Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add functional test coverage for rounds system - Closes #1303 #1747

Merged
merged 137 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
4abe6b2
Add query for testing accounts balanses consistency
4miners Jan 31, 2018
29c4f4d
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Feb 1, 2018
564a3f3
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Feb 5, 2018
84a177d
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Feb 12, 2018
c86b305
Simplify validate_accounts_balances query, as we have rounds_rewards …
4miners Feb 12, 2018
d9bc31c
Add fixtures for rounds
4miners Feb 13, 2018
193d8d0
Add environment tests to functional system rounds
4miners Feb 13, 2018
d83fd84
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Feb 14, 2018
e7ab29c
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Feb 26, 2018
7c32f07
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 11, 2018
3b6cedf
Add getBlocks query
4miners Mar 12, 2018
0c85c78
Add getRoundRewards query
4miners Mar 12, 2018
0ffaacb
Add getVotes query
4miners Mar 12, 2018
0b52919
Use camelcase for producedBlocks and missedBlocks
4miners Mar 12, 2018
7d4bee0
Check unconfirmed states, as 0.9.12 is backported
4miners Mar 12, 2018
303ff10
Use chai-as-promised
4miners Mar 12, 2018
56c94ce
Rename getVotes query to getVoters
4miners Mar 12, 2018
9bebe05
Start blocks rewards at 150-th block
4miners Mar 12, 2018
99a0892
Add required dependencies
4miners Mar 12, 2018
14615db
Rename bignum to Bignum
4miners Mar 12, 2018
b71c762
Drop cast to Number when preparing getRoundRewards results
4miners Mar 12, 2018
170ec5d
Require path dependency first
4miners Mar 12, 2018
f775cd2
Change var to let/const
4miners Mar 12, 2018
f3d1a84
Fix mocha/no-synchronous-tests
4miners Mar 12, 2018
6b9cd38
Add skeleton for round 1 tests
4miners Mar 12, 2018
658f389
Convert deleteLastBlock and generateDelegateList to promises
4miners Mar 13, 2018
c106800
Copy initial table states at the beginning or round 1
4miners Mar 13, 2018
91ba1c4
Add getMemAccounts helper function
4miners Mar 13, 2018
36afd3c
Add getDelegates helper function
4miners Mar 13, 2018
d6e6c46
Add exptectedMemStates helper function
4miners Mar 13, 2018
54f8afe
Add applyRoundRewards helper function
4miners Mar 13, 2018
7832026
Add recalculateVoteWeights helper function
4miners Mar 13, 2018
efe1a35
Add applyOutsiders helper function
4miners Mar 13, 2018
1c328fa
Add getExpectedRoundRewards helper function
4miners Mar 13, 2018
4c31bf4
Add functions for dealing with forging
4miners Mar 13, 2018
957776d
Add tickAndValidate helper function + test skeleton
4miners Mar 13, 2018
731f5b8
Perform forging and save all states for tickAndValidate
4miners Mar 13, 2018
3feded7
Fill expectations for tickAndValidate tests
4miners Mar 13, 2018
5915f52
Test forge block with 1 transfer tx to random account
4miners Mar 13, 2018
1c5e095
Test forge block with 25 txs to random accounts
4miners Mar 13, 2018
377fc64
Test forge 97 blocks with 1 tx each to random account
4miners Mar 13, 2018
06f4f19
Test forge last block of round, save mem_accounts states before
4miners Mar 13, 2018
bd74092
Test block height after round 1 is finished
4miners Mar 13, 2018
57afa7a
Test round reward calculation after round 1 is finished
4miners Mar 13, 2018
423ae2d
Test generation of delegates list when round 1 is finished
4miners Mar 13, 2018
dcabf83
Execute block deletion for delete last block of round 1 case
4miners Mar 13, 2018
ebbd452
Fill expectations for delete last block of round 1 case
4miners Mar 13, 2018
e86787b
Temporarily skip test case for states comparison after delete last bl…
4miners Mar 13, 2018
530e2a9
Remove excess brackets
4miners Mar 13, 2018
aff1964
Temporarily disable eslint rules for skipped and skeleton test
4miners Mar 13, 2018
29a827d
Fix call of generateDelegateList in getDelegateForSlot function
4miners Mar 13, 2018
911b230
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 13, 2018
36f2814
Temporarily disable eslint rules for skipped and skeleton tests
4miners Mar 13, 2018
91cc27c
Add getFullBlock query
4miners Mar 13, 2018
9a85a28
Pass block through readDbRows for getFullBlock
4miners Mar 13, 2018
1310bd9
Move generateDelegateListPromise to global scope, fix consistency
4miners Mar 13, 2018
20aa5fa
Fix standards
4miners Mar 13, 2018
e1a51b9
Remove duplicated getFullBlock query
4miners Mar 13, 2018
0fc7db4
Add comment to getFullBlock
4miners Mar 13, 2018
fefb72d
Drop normalisation for genesis block, as already normalised
4miners Mar 13, 2018
68f3879
Add test for adding back transactions from deleted block
4miners Mar 13, 2018
d50dfb1
Apply prettier
4miners Mar 13, 2018
96bbee9
Add tests skeleton for round rollback when forger of last block is un…
4miners Mar 13, 2018
15392b3
Create unvote transaction, execute delete block
4miners Mar 13, 2018
5a4c9b7
Fill expectations for round rollback scenario
4miners Mar 13, 2018
642df95
Reset vote for all accounts in recalculateVoteWeights
4miners Mar 13, 2018
a79ad90
Fix end of round detection in tickAndValidate
4miners Mar 13, 2018
bf13cde
Fill expectations for round rollback case
4miners Mar 13, 2018
4455ca2
Apply prettier
4miners Mar 13, 2018
93fd1ca
Improve tests for added back transactions from deleted block, skip fa…
4miners Mar 13, 2018
d150c8f
Apply prettier
4miners Mar 13, 2018
a946742
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 13, 2018
960f8d0
Add test scenario for comparing u_balance with balance after every block
4miners Mar 13, 2018
7a3ede1
Add missing brackets
4miners Mar 13, 2018
031cb8c
Improve expectedMemState function
4miners Mar 15, 2018
1f00a01
Support delegate registration in expectedMemState
4miners Mar 15, 2018
5713ad1
Improve consistency when dealing with Bignumber
4miners Mar 15, 2018
ec14303
Apply outsiders from data before tick instead of after
4miners Mar 15, 2018
7b5caec
Improve comment
4miners Mar 15, 2018
ae77611
Apply prettier
4miners Mar 15, 2018
507ecc2
Add skeleton for round rollback when last block forget is replaced
4miners Mar 15, 2018
41eb4f6
Add initial behavior for round rollback when last block forger is rep…
4miners Mar 15, 2018
cc6c4f1
Fill expectations for round rollback when last block forger is replaced
4miners Mar 15, 2018
5a3d463
Temporarily skip failing test
4miners Mar 15, 2018
2f8c281
Remove empty line
4miners Mar 15, 2018
2b60928
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 15, 2018
af24124
Move helper functions declarations one level above
4miners Mar 15, 2018
0211a87
Apply prettier
4miners Mar 15, 2018
ec3d8da
Add nasty hack until issue https://github.com/LiskHQ/lisk/issues/716 …
4miners Mar 15, 2018
c7714e4
Add/improve comments for expectedMemState function
4miners Mar 15, 2018
38fc7eb
Fix spelling
4miners Mar 15, 2018
f8cc9d6
Add getDelegatesForList SQL query
4miners Mar 15, 2018
d3f2c40
Fix missing space in log message
4miners Mar 15, 2018
49bd947
Copy delegatesForList states before and after forging a block
4miners Mar 15, 2018
2c40f2a
Add test for delegates weight order, improve check for delegates list
4miners Mar 15, 2018
c4ca6c5
Apply prettier
4miners Mar 15, 2018
d7c1ee7
Add test skeleton for round 2
4miners Mar 15, 2018
baa0384
Fill expectations for round rewards consistency - before reward start
4miners Mar 15, 2018
a4b6399
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 15, 2018
83b187a
Fix redundant brackets
4miners Mar 16, 2018
0b43dbe
Remove redundant .then from queries
4miners Mar 16, 2018
d43ee53
Remove redundant .then from queries
4miners Mar 16, 2018
4a0fe7b
Remove test case as not needed/redundant
4miners Mar 16, 2018
549f53b
use expectedRewardsPerBlock for comparisons
4miners Mar 16, 2018
4ea6c08
Before rewards start we should expect rewards 0
4miners Mar 16, 2018
d05bfed
Add remaining cases and logic for round 2 tests
4miners Mar 16, 2018
cda466b
Use camelCase variable names instead of snake_case
4miners Mar 16, 2018
9c93c32
:nail_care: Apply prettier
4miners Mar 16, 2018
8137853
Update rounds system tests to reuse existing forging logic
nazarhussain Mar 19, 2018
a72feb4
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 23, 2018
094fb46
Adjust usage of Lisk Elements to new version
4miners Mar 26, 2018
a027a99
Temporarily disable test failing due to changes in Lisk Elements
4miners Mar 26, 2018
b6834da
Add reference to issue https://github.com/LiskHQ/lisk/issues/1781
4miners Mar 26, 2018
3c85e35
Add reference to issue https://github.com/LiskHQ/lisk/issues/1782
4miners Mar 26, 2018
51c32b3
Add reference for issue https://github.com/LiskHQ/lisk/issues/1783
4miners Mar 26, 2018
0184ddc
Add reference for issue https://github.com/LiskHQ/lisk-js/issues/625
4miners Mar 26, 2018
52cb8ae
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 26, 2018
4bc7155
Move map functions inside getMemAccounts and getDelegates respectively
4miners Mar 26, 2018
84310d5
Refactor applyOutsiders function
4miners Mar 26, 2018
007ae2d
Remove redundant toString() calls
4miners Mar 26, 2018
104f778
Remove expectation from recalculateVoteWeights function
4miners Mar 26, 2018
7e52719
Rename property expectedDelegatesOrder to delegatesOrderAfterGenesisB…
4miners Mar 27, 2018
0b891e6
Add comments to validate_accounts_balances SQL query
4miners Mar 27, 2018
64e2aa1
Simplify expectations using map
4miners Mar 27, 2018
e323a36
Improve test description
4miners Mar 27, 2018
5ddf89c
Simplify extraction of unique accounts from genesis block
4miners Mar 27, 2018
b6841f5
Improve comments (native -> calculated)
4miners Mar 27, 2018
d15eb26
Use getForgersKeyPairs instead of rewire
4miners Mar 27, 2018
a32559e
Move mem_accountsFields to accounts fixtures
4miners Mar 27, 2018
648b19f
Create and use database account fixture
4miners Mar 27, 2018
1ea98ec
Rename *d/DelegatesForList to *d/DelegatesOrderedByVote
4miners Mar 27, 2018
b5dc523
Simplify expectations for comparison delegates list
4miners Mar 27, 2018
a98ab99
Merge remote-tracking branch 'origin/1.0.0' into 1303_rounds-function…
4miners Mar 27, 2018
a63ea75
Use getForgersKeyPairs function instead of rewire
4miners Mar 27, 2018
a0c11bc
Move queries to separate helper file
4miners Mar 27, 2018
541a709
Move genesis block and delegates test to application functional syste…
4miners Mar 27, 2018
9755781
Merge branch '1.0.0' into 1303_rounds-functional-tests
MaciejBaj Mar 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions test/fixtures/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ accounts.genesis = {
key: 'elephant tree paris dragon chair galaxy',
};

accounts.mem_accountsFields = [
'username',
'isDelegate',
'u_isDelegate',
'secondSignature',
'u_secondSignature',
'u_username',
'address',
'publicKey',
'secondPublicKey',
'balance',
'u_balance',
'vote',
'rate',
'delegates',
'u_delegates',
'multisignatures',
'u_multisignatures',
'multimin',
'u_multimin',
'multilifetime',
'u_multilifetime',
'blockId',
'nameexist',
'u_nameexist',
'producedBlocks',
'missedBlocks',
'fees',
'rewards',
'virgin',
];

const Account = stampit({
props: {
username: '',
Expand Down Expand Up @@ -108,6 +140,46 @@ const Account = stampit({
},
});

const dbAccount = stampit({
props: {
address: null,
balance: 0,
blockId: 0,
delegates: null,
fees: '0',
isDelegate: 0,
missedBlocks: 0,
multilifetime: 0,
multimin: 0,
multisignatures: null,
nameexist: 0,
producedBlocks: 0,
publicKey: null,
rate: '0',
rewards: '0',
secondPublicKey: null,
secondSignature: 0,
u_balance: 0,
u_delegates: null,
u_isDelegate: 0,
u_multilifetime: 0,
u_multimin: 0,
u_multisignatures: null,
u_nameexist: 0,
u_secondSignature: 0,
u_username: null,
username: null,
virgin: 1,
vote: '0',
},
init({ address, balance, u_balance, blockId }) {
this.address = address || this.address;
this.balance = balance || this.balance;
this.u_balance = u_balance || this.u_balance || this.balance;
this.blockId = blockId || this.blockId;
},
});

const Delegate = stampit(Account, {
props: {
isDelegate: true,
Expand All @@ -126,6 +198,7 @@ const Dependent = stampit({
});

accounts.Account = Account;
accounts.dbAccount = dbAccount;
accounts.Delegate = Delegate;
accounts.Dependent = Dependent;

Expand Down
108 changes: 108 additions & 0 deletions test/fixtures/rounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const randomstring = require('randomstring');
const stampit = require('stampit');
const faker = require('faker');

const rounds = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't understand the use of empty const object as fixture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an empty object, we add properties to it later.


const Round = stampit({
props: {
address: '',
Expand Down Expand Up @@ -45,6 +47,112 @@ const Round = stampit({
},
});

// Results from Lisk-Core 0.9.3 (after genesis block insertion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it logical to match delegate list for version 0.9.3. Should not we look for the order in 0.9.12

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Desn't matter, as order is the same (because 0.9.12 is still able to sync blockchain from scratch).

rounds.delegatesOrderAfterGenesisBlock = [
'948b8b509579306694c00833ec1c0f81e964487db2206ddb1517bfeca2b0dc1b',
'f25af3c59ac7f5155c7a9f36762bd941b9dc9c5c051a1bc2d4e34ed773dd04a3',
'74583aba9c0b92e4f08c8c75e6df341c255ca007971195ff64d6f909dc4b7177',
'27f43391cca75cbc82d1750307649508d1d318cd015f1f172b97318f17ab954e',
'6fb2e0882cd9d895e1e441b9f9be7f98e877aa0a16ae230ee5caceb7a1b896ae',
'b5341e839b25c4cc2aaf421704c0fb6ba987d537678e23e45d3ca32454a2908c',
'6d462852d410e84ca199a34d7ccad443784471f22cf3de37c531ce3b87ebbc41',
'c4dfedeb4f639f749e498a2307f1545ddd6bda62e5503ac1832b122c4a5aedf9',
'a50a55d4476bb118ba5121a07b51c185a8fe0a92b65840143b006b9820124df4',
'1e82c7db09da2010e7f5fef24d83bc46238a20ef7ecdf12d9f32e4318a818777',
'd8daea40fd098d4d546aa76b8e006ce4368c052ffe2c26b6eb843e925d54a408',
'64db2bce729e302f6021047dfd39b6c53caf83b42da4b5b881cb153a3fb31613',
'4bde949c19a0803631768148019473929b5f8661e9e48efb8d895efa9dd24aef',
'5f6cc5a8aac752d37c676b0d46a798f7625e37dfa1e96091983274e04ab7ffe2',
'03e811dda4f51323ac712cd12299410830d655ddffb104f2c9974d90bf8c583a',
'9986cedd4b5a28e4c81d9b4bff0461dddaa25099df00b8632fe99e88df28ce73',
'3ff32442bb6da7d60c1b7752b24e6467813c9b698e0f278d48c43580da972135',
'3ea481498521e9fb1201b2295d0e9afa826ac6a3ef51de2f00365f915ac7ac06',
'f9f6ff873c10c24eba834be28a56415a49c9c67b7c0ee9f106da827847168986',
'0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1',
'f62062b7590d46f382fb8c37a26ab0a1bd512951777aedcaa96822230727d3a1',
'f827f60366fae9f9ed65384979de780f4a18c6dbfbefb1c7d100957dde51a06d',
'07935c642c7409c365258c8488760e96a851cee618aec72eeeb135c9c827f0f9',
'640dfec4541daed209a455577d7ba519ad92b18692edd9ae71d1a02958f47b1b',
'e818ac2e8e9ffacd2d49f0f2f6739e16711644194d10bb1a8e9e434603125fa1',
'bf9f5cfc548d29983cc0dfa5c4ec47c66c31df0f87aa669869678996902ab47f',
'01389197bbaf1afb0acd47bbfeabb34aca80fb372a8f694a1c0716b3398db746',
'904c294899819cce0283d8d351cb10febfa0e9f0acd90a820ec8eb90a7084c37',
'a10f963752b3a44702dfa48b429ac742bea94d97849b1180a36750df3a783621',
'8a0bcba8e909036b7a0fdb244f049d847b117d871d203ef7cc4c3917c94fd5fd',
'fc8672466cc16688b5e239a784cd0e4c0acf214af039d9b2bf7a006da4043883',
'6e904b2f678eb3b6c3042acb188a607d903d441d61508d047fe36b3c982995c8',
'910da2a8e20f25ccbcb029fdcafd369b43d75e5bc4dc6d92352c29404acc350f',
'ba7acc3bcbd47dbf13d744e57f696341c260ce2ea8f332919f18cb543b1f3fc7',
'31402977c7eaf9e38d18d0689a45d719d615de941f7e80f6db388453b46f4df5',
'9d3058175acab969f41ad9b86f7a2926c74258670fe56b37c429c01fca9f2f0f',
'19ffdf99dee16e4be2db4b0e000b56ab3a4e10bee9f457d8988f75ff7a79fc00',
'6f04988de7e63537c8f14e84b0eb51e0ea9c5da8b4b9256243b3e40b1aeccb76',
'da673805f349faf9ca1db167cb941b27f4517a36d23b3c21da4159cff0045fbe',
'68680ca0bcd4676489976837edeac305c34f652e970386013ef26e67589a2516',
'e13a0267444e026fe755ec128858bf3c519864631e0e4c474ba33f2470a18b83',
'96c16a6251e1b9a8c918d5821a5aa8dfb9385607258338297221c5a226eca5c6',
'f7b9751d59dd6be6029aa36a81a3f6436e2970cf4348845ab6254678fb946c18',
'2f9b9a43b915bb8dcea45ea3b8552ebec202eb196a7889c2495d948e15f4a724',
'73fec19d4bfe361c0680a7cfd24b3f744a1c1b29d932c4d89ce6157679f8af7d',
'85b07e51ffe528f272b7eb734d0496158f2b0f890155ebe59ba2989a8ccc9a49',
'526931663cbee883ff22369172cba091a5dd5fa1200284fa790d7aeca53d37af',
'b137de324fcc79dd1a21ae39a2ee8eed05e76b86d8e89d378f8bb766afb8719f',
'c3d1bc76dea367512df3832c437c7b2c95508e140f655425a733090da86fb82d',
'86499879448d1b0215d59cbf078836e3d7d9d2782d56a2274a568761bff36f19',
'55405aed8c3a1eabe678be3ad4d36043d6ef8e637d213b84ee703d87f6b250ed',
'9a7452495138cf7cf5a1564c3ef16b186dd8ab4f96423f160e22a3aec6eb614f',
'e42bfabc4a61f02131760af5f2fa0311007932a819a508da25f2ce6af2468156',
'141b16ac8d5bd150f16b1caa08f689057ca4c4434445e56661831f4e671b7c0a',
'9f2fcc688518324273da230afff9756312bf23592174896fab669c2d78b1533c',
'47c8b3d6a9e418f0920ef58383260bcd04799db150612d4ff6eb399bcd07f216',
'5c4af5cb0c1c92df2ed4feeb9751e54e951f9d3f77196511f13e636cf6064e74',
'd3e3c8348bca51461eabfc382f8a01e8e284db54104ad37ec0695d48ae5531ac',
'cf8a3bf23d1936a34facc4ff63d86d21cc2e1ac17e0010035dc3ef7ae85010dc',
'9a0f19e60581003b70291cf4a874e8217b04871e676b2c53c85a18ab95c2683b',
'aa33af13b440746b4f24312cba5fa910eb077ce6b16b84ebb482cb7720b5c686',
'0779ca873bbda77f2850965c8a3a3d40a6ee4ec56af55f0a3f16c7c34c0f298b',
'9c16751dbe57f4dff7b3fb8911a62c0cb2bdee6240e3f3fefe76832788cb14c6',
'94b163c5a5ad346db1c84edaff51604164476cf78b8834b6b610dd03bd6b65d9',
'a10ed9c59dac2c4b8264dc34f2d318719fb5f20ecdd8d6be2d7abfe32294f20d',
'f33f93aa1f3ddcfd4e42d3206ddaab966f7f1b6672e5096d6da6adefd38edc67',
'1cc68fa0b12521158e09779fd5978ccc0ac26bf99320e00a9549b542dd9ada16',
'e6d075e3e396673c853210f74f8fe6db5e814c304bb9cd7f362018881a21f76c',
'eabfe7093ef2394deb1b84287f2ceb1b55fe638edc3358a28fc74f64b3498094',
'addb0e15a44b0fdc6ff291be28d8c98f5551d0cd9218d749e30ddb87c6e31ca9',
'76c9494237e608d43fd6fb0114106a7517f5503cf79d7482db58a02304339b6c',
'399a7d14610c4da8800ed929fc6a05133deb8fbac8403dec93226e96fa7590ee',
'9503d36c0810f9ac1a9d7d45bf778387a2baab151a45d77ac1289fbe29abb18f',
'031e27beab583e2c94cb3167d128fc1a356c1ae88adfcfaa2334abffa3ae0b4c',
'ba2ea5e324eeb42fa6f4d1132a1d79911721e8507033bb0abd49715f531877b4',
'cdd68a321ea737e82bce23d2208040f79471d36f2e6f84c74ea36ab26245e522',
'95ea7eb026e250741be85e3593166ef0c4cb3a6eb9114dba8f0974987f10403f',
'd1c3a2cb254554971db289b917a665b5c547617d6fd20c2d6051bc5dfc805b34',
'b6ac700bf890b887e218dbd55b8f6b091dfc5a684d0fd7a6f69db7dc0313b51b',
'c61d0822bbdbfe2a0b5503daff0ce8441c623115c94c0cfcf047a51f8b7160d3',
'4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5',
'edbb9828fbe62da2a59afbc8623e8ebc5ed2f9b7f77a0cd1cdcf55edea30521c',
'2b6f49383af36fd9f1a72d5d2708c8c354add89aaea7edc702c420e2d5fdf22e',
'db821a4f828db977c6a8d186cc4a44280a6ef6f54ac18ec9eb32f78735f38683',
'1b5a93c7622c666b0228236a70ee1a31407828b71bfb6daaa29a1509e87d4d3c',
'b00269bd169f0f89bd2f278788616521dd1539868ced5a63b652208a04ee1556',
'1af35b29ca515ff5b805a5e3a0ab8c518915b780d5988e76b0672a71b5a3be02',
'3476bba16437ee0e04a29daa34d753139fbcfc14152372d7be5b7c75d51bac6c',
'82174ee408161186e650427032f4cfb2496f429b4157da78888cbcea39c387fc',
'a796e9c0516a40ccd0eee7a32fdc2dc297fee40a9c76fef9c1bb0cf41ae69750',
'47b9b07df72d38c19867c6a8c12429e6b8e4d2be48b27cd407da590c7a2af0dc',
'386217d98eee87268a54d2d76ce9e801ac86271284d793154989e37cb31bcd0e',
'62bbb3c41e43df73de2c3f87e6577d095b84cf6deb1b2d6e87612a9156b980f8',
'6164b0cc68f8de44cde90c78e838b9ee1d6041fa61cf0cfbd834d76bb369a10e',
'1e6ce18addd973ad432f05f16a4c86372eaca054cbdbcaf1169ad6df033f6b85',
'644a971f2c0d0d4b657d050fca27e5f9265e3dfa02a71f7fbf834cc2f2a6a4c8',
'5d28e992b80172f38d3a2f9592cad740fd18d3c2e187745cd5f7badf285ed819',
'67651d29dc8d94bcb1174d5bd602762850a89850503b01a5ffde3b726b43d3d2',
'3be2eb47134d5158e5f7d52076b624b76744b3fba8aa50791b46ba21408524c9',
'fab7b58be4c1e9542c342023b52e9d359ea89a3af34440bdb97318273e8555f0',
'19d55c023d85d6061d1e196fa440a50907878e2d425bcd893366fa04bc23b4de',
];

module.exports = {
Round,
rounds,
};
31 changes: 31 additions & 0 deletions test/functional/common/sql/rounds/validate_accounts_balances.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © 2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

WITH balances AS (
-- Subtract amount and fee from sender accounts
(SELECT UPPER("senderId") AS address, -SUM(amount+fee) AS amount FROM trs GROUP BY UPPER("senderId"))
UNION ALL
-- Credit amount to recipient accounts
(SELECT UPPER("recipientId") AS address, SUM(amount) AS amount FROM trs WHERE "recipientId" IS NOT NULL GROUP BY UPPER("recipientId"))
UNION ALL
-- Sum total rewards (fee split + block reward) from all rounds, for all delegates accounts
(SELECT a.address, r.amount FROM
(SELECT r."publicKey", SUM(r.fees) + SUM(r.reward) AS amount FROM rounds_rewards r GROUP BY r."publicKey") r LEFT JOIN mem_accounts a ON r."publicKey" = a."publicKey"
)
),
-- Sum all calculated accounts balances
accounts AS (SELECT b.address, SUM(b.amount) AS balance FROM balances b GROUP BY b.address)
-- Compare calculated (based on blockchain) balances with current accounts balances (mem_accounbts)
SELECT m.address, ENCODE(m."publicKey", 'hex') AS "publicKey", m.username, a.balance::BIGINT AS blockchain, m.balance::BIGINT AS memory, (m.balance-a.balance)::BIGINT AS diff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not it look odd a.balance::BIGINT AS blockchain and m.balance::BIGINT AS memory, it should be something relevant. e.g. a.balance::BIGINT AS calculatedBalance and m.balance::BIGINT AS accountBalance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments for clarification.

FROM accounts a LEFT JOIN mem_accounts m ON a.address = m.address WHERE a.balance <> m.balance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to explain to explain this SQL in comments above.

What I understood.

  1. Summing up all amount+fee that one paid and considering these negative
  2. Summing up all amount that one received and considering these positive
  3. Summing up fee+rewards for all delegates in a round.

Can you explain the third point? Why we sump up fees with rewards, while fee already covered in the first point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works a little different:

  • subtract amount+fee from sender accounts
  • credit amount to recipient accounts
  • sum total rewards (fee split + block reward) from all rounds, for all delegates accounts

I'll add some comments to that query.

39 changes: 26 additions & 13 deletions test/functional/system/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function createBlock(library, transactions, timestamp, keypair, previousBlock) {
function createValidBlock(library, transactions, cb) {
var lastBlock = library.modules.blocks.lastBlock.get();
var slot = slots.getSlotNumber();
var keypairs = library.rewiredModules.delegates.__get__('__private.keypairs');
var keypairs = library.modules.delegates.getForgersKeyPairs();
getDelegateForSlot(library, slot, (err, delegateKey) => {
var block = createBlock(
library,
Expand Down Expand Up @@ -79,15 +79,15 @@ function getBlocks(library, cb) {
});
}

function forge(library, cb) {
function getNextForger(offset, cb) {
offset = !offset ? 1 : offset;
function getNextForger(library, offset, cb) {
offset = !offset ? 1 : offset;

var lastBlock = library.modules.blocks.lastBlock.get();
var slot = slots.getSlotNumber(lastBlock.timestamp);
getDelegateForSlot(library, slot + offset, cb);
}
var lastBlock = library.modules.blocks.lastBlock.get();
var slot = slots.getSlotNumber(lastBlock.timestamp);
getDelegateForSlot(library, slot + offset, cb);
}

function forge(library, cb) {
var keypairs = library.rewiredModules.delegates.__get__('__private.keypairs');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe modules.delegates.getForgersKeyPairs() instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


async.waterfall(
Expand All @@ -96,7 +96,7 @@ function forge(library, cb) {
fillPool(library, seriesCb);
},
function(seriesCb) {
getNextForger(null, seriesCb);
getNextForger(library, null, seriesCb);
},
function(delegate, seriesCb) {
var last_block = library.modules.blocks.lastBlock.get();
Expand Down Expand Up @@ -145,6 +145,9 @@ function fillPool(library, cb) {
function addTransaction(library, transaction, cb) {
// Add transaction to transactions pool - we use shortcut here to bypass transport module, but logic is the same
// See: modules.transport.__private.receiveTransaction
__testContext.debug(` Add transaction ID: ${transaction.id}`);

transaction = library.logic.transaction.objectNormalize(transaction);
library.balancesSequence.add(sequenceCb => {
library.modules.transactions.processUnconfirmedTransaction(
transaction,
Expand Down Expand Up @@ -177,7 +180,12 @@ function addTransactionToUnconfirmedQueue(library, transaction, cb) {
);
}

function addTransactionsAndForge(library, transactions, cb) {
function addTransactionsAndForge(library, transactions, forgeDelay, cb) {
if (typeof forgeDelay === 'function') {
cb = forgeDelay;
forgeDelay = 800;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to support that delay here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4miners As per @SargeKhan it was added because of transaction pool. He can explain further on it.

}

async.waterfall(
[
function addTransactions(waterCb) {
Expand All @@ -190,9 +198,13 @@ function addTransactionsAndForge(library, transactions, cb) {
);
},
function(waterCb) {
setTimeout(() => {
forge(library, waterCb);
}, 800);
if (forgeDelay > 0) {
setTimeout(() => {
forge(library, waterCb);
}, forgeDelay);
} else {
setImmediate(forge, library, waterCb);
}
},
],
err => {
Expand Down Expand Up @@ -334,6 +346,7 @@ function loadTransactionType(key, account, dapp, secondPassword, cb) {
}

module.exports = {
getNextForger,
forge,
fillPool,
addTransaction,
Expand Down
Loading