Skip to content

Commit

Permalink
Remove public updatedAddresses parameter from Transaction.Create()
Browse files Browse the repository at this point in the history
  • Loading branch information
greymistcube committed Nov 3, 2023
1 parent 4cea4fc commit 7c248d2
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 172 deletions.
24 changes: 14 additions & 10 deletions Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,20 @@ private Transaction
var random = new System.Random(seed);
var addr = pk.ToAddress();
var bal = (int)(Chain.GetBalance(addr, TestCurrency).MajorUnit & int.MaxValue);
return Transaction.Create(
nonce,
pk,
Chain.Genesis.Hash,
random.Next() % 2 == 0
? GetRandomActions(random.Next()).ToPlainValues()
: ImmutableHashSet<SimpleAction>.Empty.ToPlainValues(),
null,
null,
GetRandomAddresses(random.Next()));
return
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: Chain.Genesis.Hash,
updatedAddresses: GetRandomAddresses(random.Next()),
timestamp: DateTimeOffset.UtcNow,
actions: new TxActionList(random.Next() % 2 == 0
? GetRandomActions(random.Next()).ToPlainValues()
: ImmutableHashSet<SimpleAction>.Empty.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(pk.PublicKey, nonce)),
pk);
}

private ImmutableArray<SimpleAction> GetRandomActions(int seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ private Transaction DummyTransaction()
new[] { new Utils.DummyAction() }.ToPlainValues(),
null,
null,
null,
DateTimeOffset.UtcNow
);
DateTimeOffset.UtcNow);
}
}
5 changes: 1 addition & 4 deletions Libplanet.Net.Tests/Consensus/ContextTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -362,9 +361,7 @@ void BroadcastMessage(ConsensusMsg message) =>
nonce: 0,
privateKey: TestUtils.PrivateKeys[1],
genesisHash: blockChain.Genesis.Hash,
actions: new[] { action }.ToPlainValues(),
updatedAddresses: ImmutableHashSet.Create(DelayAction.TrivialUpdatedAddress)
);
actions: new[] { action }.ToPlainValues());
blockChain.StageTransaction(tx);
var block = blockChain.ProposeBlock(TestUtils.PrivateKeys[1]);

Expand Down
4 changes: 1 addition & 3 deletions Libplanet.Net.Tests/SwarmTest.Preload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ public async Task PreloadWithFailedActions()
new[] { action }.ToPlainValues(),
null,
null,
ImmutableHashSet<Address>.Empty,
DateTimeOffset.UtcNow
);
DateTimeOffset.UtcNow);

Block block = minerChain.ProposeBlock(
ChainPrivateKey,
Expand Down
178 changes: 109 additions & 69 deletions Libplanet.Tests/Action/ActionEvaluatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,32 +278,50 @@ DumbAction MakeAction(Address address, char identifier, Address? transferTo = nu

Transaction[] block1Txs =
{
Transaction.Create(
nonce: 0,
privateKey: _txFx.PrivateKey1,
genesisHash: genesis.Hash,
actions: new[]
{
MakeAction(addresses[0], 'A', addresses[1]),
MakeAction(addresses[1], 'B', addresses[2]),
}.ToPlainValues(),
updatedAddresses: new[] { addresses[0], addresses[1] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(2)),
Transaction.Create(
nonce: 0,
privateKey: _txFx.PrivateKey2,
genesisHash: genesis.Hash,
actions: new[]
{
MakeAction(addresses[2], 'C', addresses[3]),
}.ToPlainValues(),
timestamp: DateTimeOffset.MinValue.AddSeconds(4)),
Transaction.Create(
nonce: 0,
privateKey: _txFx.PrivateKey3,
genesisHash: genesis.Hash,
actions: Array.Empty<DumbAction>().ToPlainValues(),
timestamp: DateTimeOffset.MinValue.AddSeconds(7)),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: genesis.Hash,
updatedAddresses: new[]
{
addresses[0],
addresses[1],
}.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(2),
actions: new TxActionList(new[]
{
MakeAction(addresses[0], 'A', addresses[1]),
MakeAction(addresses[1], 'B', addresses[2]),
}.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(_txFx.PrivateKey1.PublicKey, 0)),
_txFx.PrivateKey1),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: genesis.Hash,
updatedAddresses: ImmutableHashSet<Address>.Empty,
timestamp: DateTimeOffset.MinValue.AddSeconds(4),
actions: new TxActionList(new[]
{
MakeAction(addresses[2], 'C', addresses[3]),
}.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(_txFx.PrivateKey2.PublicKey, 0)),
_txFx.PrivateKey2),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: genesis.Hash,
updatedAddresses: ImmutableHashSet<Address>.Empty,
timestamp: DateTimeOffset.MinValue.AddSeconds(7),
actions: TxActionList.Empty,
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(_txFx.PrivateKey3.PublicKey, 0)),
_txFx.PrivateKey3),
};
foreach ((var tx, var i) in block1Txs.Zip(
Enumerable.Range(0, block1Txs.Length), (x, y) => (x, y)))
Expand Down Expand Up @@ -385,37 +403,55 @@ DumbAction MakeAction(Address address, char identifier, Address? transferTo = nu
// Note that these timestamps in themselves does not have any meanings but are
// only arbitrary. These purpose to make their evaluation order in a block
// equal to the order we (the test) intend:
Transaction.Create(
0,
_txFx.PrivateKey1,
genesis.Hash,
new[] { MakeAction(addresses[0], 'D') }.ToPlainValues(),
updatedAddresses: new[] { addresses[0] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(1)),
Transaction.Create(
0,
_txFx.PrivateKey2,
genesis.Hash,
new[] { MakeAction(addresses[3], 'E') }.ToPlainValues(),
updatedAddresses: new[] { addresses[3] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(2)),
Transaction.Create(
0,
_txFx.PrivateKey3,
genesis.Hash,
new[]
{
new DumbAction(
addresses[4],
"RecordRehearsal",
transferFrom: addresses[0],
transferTo: addresses[4],
transferAmount: 8,
recordRehearsal: true,
recordRandom: true),
}.ToPlainValues(),
updatedAddresses: new[] { addresses[4] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(4)),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: genesis.Hash,
updatedAddresses: new[] { addresses[0] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(1),
actions: new TxActionList(new[]
{
MakeAction(addresses[0], 'D'),
}.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(_txFx.PrivateKey1.PublicKey, 0)),
_txFx.PrivateKey1),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: genesis.Hash,
updatedAddresses: new[] { addresses[3] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(2),
actions: new TxActionList(new[]
{
MakeAction(addresses[3], 'E'),
}.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(_txFx.PrivateKey2.PublicKey, 0)),
_txFx.PrivateKey2),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: genesis.Hash,
updatedAddresses: new[] { addresses[4] }.ToImmutableHashSet(),
timestamp: DateTimeOffset.MinValue.AddSeconds(4),
actions: new TxActionList(new[]
{
new DumbAction(
addresses[4],
"RecordRehearsal",
transferFrom: addresses[0],
transferTo: addresses[4],
transferAmount: 8,
recordRehearsal: true,
recordRandom: true),
}.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(_txFx.PrivateKey3.PublicKey, 0)),
_txFx.PrivateKey3),
};
foreach ((var tx, var i) in block2Txs.Zip(
Enumerable.Range(0, block2Txs.Length), (x, y) => (x, y)))
Expand Down Expand Up @@ -625,7 +661,6 @@ public void EvaluateTxResultThrowingException()
new[] { action }.ToPlainValues(),
null,
null,
ImmutableHashSet<Address>.Empty,
DateTimeOffset.UtcNow);
var txs = new Transaction[] { tx };
var hash = new BlockHash(GetRandomBytes(BlockHash.Size));
Expand Down Expand Up @@ -840,17 +875,22 @@ public void OrderTxsForEvaluation(
.Select(signerNoncePair =>
{
Address targetAddress = signerNoncePair.signer.ToAddress();
return Transaction.Create(
nonce: signerNoncePair.nonce,
privateKey: signerNoncePair.signer,
genesisHash: null,
actions: new[]
{
new RandomAction(signerNoncePair.signer.ToAddress()),
}.ToPlainValues(),
updatedAddresses: ImmutableHashSet.Create(targetAddress),
timestamp: epoch
);
return new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: null,
updatedAddresses: ImmutableHashSet.Create(targetAddress),
timestamp: epoch,
actions: new TxActionList(new[]
{
new RandomAction(signerNoncePair.signer.ToAddress()),
}.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(
signerNoncePair.signer.PublicKey,
signerNoncePair.nonce)),
signerNoncePair.signer);
}).ToImmutableArray();

// Rearrange transactions so that transactions are not grouped by signers
Expand Down
8 changes: 2 additions & 6 deletions Libplanet.Tests/Blockchain/BlockChainTest.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,13 @@ public void CannotAppendBlockWithInvalidActions()
nonce: 0,
privateKey: txSigner,
genesisHash: _blockChain.Genesis.Hash,
actions: Array.Empty<DumbAction>().ToPlainValues(),
updatedAddresses: ImmutableHashSet<Address>.Empty
),
actions: Array.Empty<DumbAction>().ToPlainValues()),
invalidTx,
Transaction.Create(
nonce: 2,
privateKey: txSigner,
genesisHash: _blockChain.Genesis.Hash,
actions: Array.Empty<DumbAction>().ToPlainValues(),
updatedAddresses: ImmutableHashSet<Address>.Empty
),
actions: Array.Empty<DumbAction>().ToPlainValues()),
}.OrderBy(tx => tx.Id);

var metadata = new BlockMetadata(
Expand Down
4 changes: 1 addition & 3 deletions Libplanet.Tests/Blockchain/BlockChainTest.Internals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ Transaction MkTx(PrivateKey key, long nonce, DateTimeOffset? ts = null) =>
Array.Empty<DumbAction>().ToPlainValues(),
null,
null,
null,
ts ?? DateTimeOffset.UtcNow
);
ts ?? DateTimeOffset.UtcNow);

PrivateKey a = new PrivateKey();
PrivateKey b = new PrivateKey();
Expand Down
40 changes: 23 additions & 17 deletions Libplanet.Tests/Blockchain/BlockChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,24 @@ public void ForkShouldSkipExecuteAndRenderGenesis()
_ => _policy.BlockAction,
stateStore,
new SingleActionLoader(typeof(DumbAction)));
var privateKey = new PrivateKey();
var genesis = ProposeGenesisBlock(
actionEvaluator,
ProposeGenesis(
GenesisProposer.PublicKey,
transactions: new[]
{
Transaction.Create(
nonce: 0,
privateKey: new PrivateKey(),
genesisHash: null,
actions: new[] { action }.ToPlainValues(),
maxGasPrice: null,
gasLimit: null,
updatedAddresses: ImmutableHashSet.Create(_fx.Address1),
timestamp: DateTimeOffset.UtcNow
),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: null,
updatedAddresses: ImmutableHashSet.Create(_fx.Address1),
timestamp: DateTimeOffset.UtcNow,
actions: new TxActionList(new[] { action }.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(privateKey.PublicKey, 0)),
privateKey),
}),
privateKey: GenesisProposer);

Expand Down Expand Up @@ -1887,13 +1889,17 @@ private void CreateWithGenesisBlock()
.ToArray();
var customTxs = new[]
{
Transaction.Create(
nonce: systemTxs.Length,
privateKey: privateKey,
genesisHash: null,
actions: customActions.ToPlainValues(),
updatedAddresses: addresses.ToImmutableHashSet()
),
new Transaction(
new UnsignedTx(
new TxInvoice(
genesisHash: null,
updatedAddresses: addresses.ToImmutableHashSet(),
timestamp: DateTimeOffset.UtcNow,
actions: new TxActionList(customActions.ToPlainValues()),
maxGasPrice: null,
gasLimit: null),
new TxSigningMetadata(privateKey.PublicKey, systemTxs.Length)),
privateKey),
};
var txs = systemTxs.Concat(customTxs).ToImmutableList();
var blockChainStates = new BlockChainStates(
Expand Down
16 changes: 6 additions & 10 deletions Libplanet.Tests/Fixtures/IntegerSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ public IntegerSet(
.Select(pair => new { State = (BigInteger)pair.State, pair.Key })
.Select(pair => new { Action = Arithmetic.Add(pair.State), pair.Key })
.Select(pair =>
Transaction.Create(
0,
pair.Key,
null,
new[] { pair.Action }.ToPlainValues(),
null,
null,
ImmutableHashSet<Address>.Empty.Add(pair.Key.ToAddress())
)
)
new Transaction(
new UnsignedTx(
new TxInvoice(
actions: new TxActionList(new[] { pair.Action.PlainValue })),
new TxSigningMetadata(pair.Key.PublicKey, 0)),
pair.Key))
.OrderBy(tx => tx.Id)
.ToImmutableArray();
Miner = new PrivateKey();
Expand Down
1 change: 0 additions & 1 deletion Libplanet.Tests/Store/StoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public Transaction MakeTransaction(
actions?.ToPlainValues() ?? Array.Empty<DumbAction>().ToPlainValues(),
null,
null,
updatedAddresses,
timestamp
);
}
Expand Down
Loading

0 comments on commit 7c248d2

Please sign in to comment.