Skip to content

Commit

Permalink
Test: Add frozen funds for 6 more validators
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Dec 10, 2021
1 parent a88b550 commit 88d8a91
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 76 deletions.
8 changes: 4 additions & 4 deletions source/agora/consensus/Ledger.d
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ unittest
scope ledger = new TestLedger(genesis_validator_keys[0], blocks);

assert(ledger.utxo_set.length
== /* Genesis, Frozen */ 6 + 8 /* Block #1 Payments*/);
== /* Genesis, Frozen */ 12 + 8 /* Block #1 Payments*/);

// Ensure that all previously-generated outputs are in the UTXO set
{
Expand Down Expand Up @@ -2070,8 +2070,8 @@ unittest
{
assert(ex.message ==
"Genesis block loaded from disk " ~
"(0x6db06ab1cae5c4b05e806401e2c42d526ebf4ac81411d0fcd82344561b5" ~
"a25ae0d29728f5c1c9bec6cf254f621c183be71858a6ed5339c06fc5b34d7881b9b23) "~
"(0x498d14496a0ea3159bae273719496a1a43158b67a9666ff5266126bde05" ~
"5d84bdfa39079d8fb6104b5b629a179836c8f33fbc25e1f0a290ddbdb553377d679ca) "~
"is different from the one in the config file " ~
"(0x47f30089ca49c3eacb09f2d96e4a27e1049697bbfe1002862344fd0b33b" ~
"72d1b3b69467148905626e0a0f4845f5cdca69c25d2ec2663622acd45c38c974d0d91)");
Expand Down Expand Up @@ -2467,7 +2467,7 @@ unittest
scope ledger = new TestLedger(genesis_validator_keys[0], blocks, params);
ledger.simulatePreimages(Height(params.ValidatorCycle));

auto freeze_tx = GenesisBlock.txs.find!(tx => tx.isFreeze).front();
auto freeze_tx = GenesisBlock.txs.find!(tx => tx.isFreeze).array.back();
auto melting_tx = TxBuilder(freeze_tx, 0).sign();

// enrolled stake can't be spent
Expand Down
35 changes: 24 additions & 11 deletions source/agora/consensus/data/genesis/Test.d
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,23 @@ public immutable Block GenesisBlock = {
txs: [
Transaction(
[
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(61_000_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(2_000_000L * 10_000_000L), WK.Keys.NODE8.address, OutputType.Freeze),
Output(Amount(2_000_000L * 10_000_000L), WK.Keys.NODE9.address, OutputType.Freeze),
Output(Amount(2_000_000L * 10_000_000L), WK.Keys.NODE10.address, OutputType.Freeze),
Output(Amount(2_000_000L * 10_000_000L), WK.Keys.NODE11.address, OutputType.Freeze),
Output(Amount(2_000_000L * 10_000_000L), WK.Keys.NODE12.address, OutputType.Freeze),
Output(Amount(2_000_000L * 10_000_000L), WK.Keys.NODE13.address, OutputType.Freeze),
]),
Transaction(
[
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
Output(Amount(59_500_000L * 10_000_000L), GenesisOutputAddress),
]),
Transaction(
[
Expand Down Expand Up @@ -127,7 +136,7 @@ unittest
assert(GenesisBlock.header.prev_block == Hash.init);
assert(GenesisBlock.header.height == 0);
assert(GenesisBlock.txs.isSorted(), "Block transaction must be sorted!");
assert(GenesisBlock.merkle_tree.length == 3);
assert(GenesisBlock.merkle_tree.length == 7);
Hash[] merkle_tree;
GenesisBlock.buildMerkleTree(GenesisBlock.txs, merkle_tree);
assert(merkle_tree == GenesisMerkleTree, merkle_tree.to!string);
Expand All @@ -146,9 +155,13 @@ unittest
}

private immutable Hash[] GenesisMerkleTree = [
Hash(`0x26866bb263593d024a92103646c48cf35a2b1bfcc49b087915b85db14a432b373569d56f576242354328a31bf0102a0a78cb806cf6e25d88d7981367833631b7`),
Hash(`0x5289192825c751ac16649f59f4d4ee7b115af7918c625e944bbf9301a20f77c447d2c54f712fdf224c8d3564d9afcee6a85d70910ec892adb758471f3c55c7c5`),
Hash(`0x56c1aa99fb4c9795274b8b2ffa6fe555885b9bbf07ecf20c8556bf1c6f7949d9e356b72dcc6d9e2c0ff0afcfbe522b2a5a01f2309ae610c0a457d66d9a0b0165`),
Hash(`0xeb5e0004d046422c84ddb7b9d54a0eba484a41b5179beda0b3dd7c54c3fca609437a9c8ef16b5bfc2335d9b258eb68908757e0f1a4c725752598aaa962924551`),
Hash(`0xeb5e0004d046422c84ddb7b9d54a0eba484a41b5179beda0b3dd7c54c3fca609437a9c8ef16b5bfc2335d9b258eb68908757e0f1a4c725752598aaa962924551`),
Hash(`0xaf402f71c175bc6f53ededdd9cfa1f4c074efcd2fe7090c9d0ca3b95c5d1e7513cd4b4f922c4f7ebf120958f449a2d3e23a397c7219e297b8ff1cfbc00ebc93d`)
Hash(`0xa8becf607ad1721aa25b9378d8b64ec906ea9e383ef079aa6e6e94f09c85979d300e9bdf8513cbdb311123ec0bc1ad6c83cc5ceabd3f58db98a4e75aaeb92244`),
Hash(`0x932c18001c1787ebd6440c69a4db00bc6bb98527bd0d41e7437df3d26b29b1603fc476c2b00870d304b04b3af4d886f67f12a0052a058919e86947f53af82cad`),
Hash(`0xc5d27cf200b9da791f976ddaaee3d6f96cc33da9012f862f49f5af676910a70fb3d21b197ee2a53b3bda2e51ef2d870bf5148e8a602cf33d89df5bf3bee1103e`),
];

/// GDGENES4KXH7RQJELTONR7HSVISVSQ5POSVBEWLR6EEIIL72H24IEDT4
Expand Down
2 changes: 1 addition & 1 deletion source/agora/consensus/data/genesis/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ version (unittest) public NodeEnrollment[] checkGenesisEnrollments (
import std.conv;
import std.algorithm;

auto freeze_tx = genesisBlock.txs.filter!(tx => tx.isFreeze).front;
auto freeze_tx = genesisBlock.txs.filter!(tx => tx.isFreeze).array.back;
Output[] sorted_freeze_outputs = freeze_tx.outputs.dup.sort.array;
assert(sorted_freeze_outputs == freeze_tx.outputs);
Hash txhash = hashFull(freeze_tx);
Expand Down
8 changes: 4 additions & 4 deletions source/agora/consensus/validation/Block.d
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,14 @@ unittest
assert(!block.isGenesisBlockValid());

// at least 1 tx needed (todo: relax this?)
block.txs ~= txs.filter!(tx => tx.isFreeze).front;
block.txs ~= txs.filter!(tx => tx.isFreeze).array;
buildMerkleTree(block);
checkValidity(block);

block = GenesisBlock.serializeFull.deserializeFull!Block;
foreach (_; 0 .. 6)
block.txs ~= makeNewTx();
assert(block.txs.length == 8);
assert(block.txs.length == GenesisBlock.txs.length + 6);
buildMerkleTree(block);
checkValidity(block);

Expand All @@ -378,7 +378,7 @@ unittest
// there may be any number of txs, does not need to be power of 2
block.txs ~= makeNewTx();
buildMerkleTree(block);
assert(block.txs.length == 3);
assert(block.txs.length == GenesisBlock.txs.length + 1);
checkValidity(block);

block = GenesisBlock.serializeFull.deserializeFull!Block;
Expand Down Expand Up @@ -695,7 +695,7 @@ unittest
findNonSpent, Enrollment.MinValidatorCount, checker, findGenesisEnrollments, toDelegate(utGetPenaltyDeposit));

// All `payment` utxos have been consumed
assert(used_set.length + GenesisBlock.frozens.front.outputs.length == utxo_set_len);
assert(used_set.length + GenesisBlock.frozens.map!(frozen => frozen.outputs.length).sum() == utxo_set_len);

// reset state
used_set.clear();
Expand Down
4 changes: 4 additions & 0 deletions source/agora/test/ManyValidators.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void manyValidators (size_t validators)
// generate 18 blocks, 2 short of the enrollments expiring.
network.generateBlocks(Height(GenesisValidatorCycle - 2));

// make sure outsiders are up to date
network.expectHeight(iota(GenesisValidators, validators),
Height(GenesisValidatorCycle - 2));

// prepare frozen outputs for the outsider validator to enroll
network.postAndEnsureTxInPool(network.freezeUTXO(iota(GenesisValidators, GenesisValidators + conf.outsider_validators)));

Expand Down
4 changes: 4 additions & 0 deletions source/agora/test/Quorum.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ unittest
// generate 18 blocks, 1 short of the enrollments expiring.
network.generateBlocks(Height(GenesisValidatorCycle - 2));

// make sure outsiders are up to date
network.expectHeight(iota(GenesisValidators, validators),
Height(GenesisValidatorCycle - 2));

// prepare frozen outputs for the outsider validator to enroll
network.postAndEnsureTxInPool(network.freezeUTXO(iota(GenesisValidators, validators)));

Expand Down
36 changes: 20 additions & 16 deletions source/agora/test/QuorumPreimage.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ unittest
// generate 18 blocks, 2 short of the enrollments expiring.
network.generateBlocks(Height(GenesisValidatorCycle - 2));

// make sure outsiders are up to date
network.expectHeight(iota(GenesisValidators, validators),
Height(GenesisValidatorCycle - 2));

void printQuorums (uint line = __LINE__)
{
foreach (idx, node; nodes.enumerate)
Expand Down Expand Up @@ -117,28 +121,28 @@ unittest

enum quorums_2 = [
// 0
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 1
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 4, 5, 6, 7]),

// 2
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 3
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 4
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 4, 5, 6, 7]),

// 5
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 6
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 4, 5, 6, 7]),

// 7
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),
];

static assert(quorums_1 != quorums_2);
Expand Down Expand Up @@ -166,28 +170,28 @@ unittest
// which use a different preimage
enum quorums_3 = [
// 0
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 1
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 2
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 3
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 4
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),

// 5
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 4, 5, 6, 7]),

// 6
QuorumConfig(6, [1, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 4, 5, 6, 7]),

// 7
QuorumConfig(6, [0, 2, 3, 4, 5, 6, 7]),
QuorumConfig(6, [0, 1, 2, 3, 4, 5, 7]),
];

static assert(quorums_2 != quorums_3);
Expand Down
6 changes: 3 additions & 3 deletions source/agora/test/RestoreSlashingInfo.d
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ unittest
network.postAndEnsureTxInPool(iota(GenesisValidators),
network.freezeUTXO(iota(GenesisValidators, GenesisValidators + 3)));

network.generateBlocks(Height(GenesisValidatorCycle - 1));
network.generateBlocks(Height(GenesisValidatorCycle - 1), true);

// wait for other nodes to get to same block height
set_b.enumerate.each!((idx, node) =>
Expand All @@ -65,7 +65,7 @@ unittest
.each!(i => network.enroll(i));

// Block 20, After this the Genesis block enrolled validators will be expired.
network.generateBlocks(iota(GenesisValidators), Height(GenesisValidatorCycle));
network.generateBlocks(iota(GenesisValidators), Height(GenesisValidatorCycle), true);
// Set B validators should catch up
network.expectHeight(iota(GenesisValidators, GenesisValidators + conf.outsider_validators),
Height(GenesisValidatorCycle));
Expand All @@ -80,7 +80,7 @@ unittest
network.waitForDiscovery();
// Block 21
network.generateBlocks(iota(GenesisValidators - 1, GenesisValidators + conf.outsider_validators),
Height(GenesisValidatorCycle + 1));
Height(GenesisValidatorCycle + 1), true);

// Now restarting the validators in the set B, all the data of those
// validators has been wiped out.
Expand Down
Loading

0 comments on commit 88d8a91

Please sign in to comment.