From d751b5817323b504ab05e2c7f8cc6c4a4ff36e8c Mon Sep 17 00:00:00 2001 From: Stanislav Frolov Date: Thu, 9 May 2019 12:47:13 +0200 Subject: [PATCH] Add test, update logs Signed-off-by: Stanislav Frolov --- src/esperanza/finalizationstate.cpp | 6 +++--- test/functional/finalization_vote.py | 32 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/esperanza/finalizationstate.cpp b/src/esperanza/finalizationstate.cpp index da0c1da9e9..effae06883 100644 --- a/src/esperanza/finalizationstate.cpp +++ b/src/esperanza/finalizationstate.cpp @@ -327,8 +327,8 @@ Result FinalizationState::IsVotable(const Validator &validator, if (it == m_checkpoints.end()) { return fail(Result::VOTE_MALFORMED, log_errors, - "%s: target_epoch=%d is in the future.\n", __func__, - targetEpoch); + "%s: target_epoch=%d not found. current_epoch=%d.\n", __func__, + targetEpoch, m_current_epoch); } auto &targetCheckpoint = it->second; @@ -363,7 +363,7 @@ Result FinalizationState::IsVotable(const Validator &validator, if (it == m_checkpoints.end()) { return fail(Result::VOTE_MALFORMED, log_errors, - "%s: source_epoch=%d is in the future. current_epoch=%d\n", __func__, + "%s: source_epoch=%d not found. current_epoch=%d\n", __func__, sourceEpoch, m_current_epoch); } diff --git a/test/functional/finalization_vote.py b/test/functional/finalization_vote.py index 313e5cfbbb..c42dc38ca1 100755 --- a/test/functional/finalization_vote.py +++ b/test/functional/finalization_vote.py @@ -10,9 +10,11 @@ from test_framework.util import ( assert_equal, assert_finalizationstate, + assert_raises_rpc_error, connect_nodes, disconnect_nodes, generate_block, + make_vote_tx, sync_blocks, ) from test_framework.test_framework import UnitETestFramework @@ -135,7 +137,7 @@ def run_test(self): # test that finalizers can vote after configured epoch block number generate_block(node0, count=4) assert_equal(node0.getblockcount(), 39) - self.wait_for_vote_and_disconnect(finalizer=finalizer1, node=node0) + prev_tx = self.wait_for_vote_and_disconnect(finalizer=finalizer1, node=node0) self.wait_for_vote_and_disconnect(finalizer=finalizer2, node=node0) self.wait_for_vote_and_disconnect(finalizer=finalizer3, node=node0) generate_block(node0) @@ -147,6 +149,34 @@ def run_test(self): 'validators': 3}) self.log.info('Finalizers voted after configured block number') + generate_block(node0, count=4) + prev_tx = finalizer1.decoderawtransaction(prev_tx)['txid'] + + # test that node recognizes old and invalid votes. + tx = make_vote_tx(finalizer1, address1, node0.getblockhash(40), 5, 8, prev_tx) + assert_raises_rpc_error(-26, 'bad-vote-invalid', node0.sendrawtransaction, tx) + tx = make_vote_tx(finalizer1, address1, node0.getblockhash(40), 7, 9, prev_tx) + assert_raises_rpc_error(-26, 'bad-vote-invalid', node0.sendrawtransaction, tx) + tx = make_vote_tx(finalizer1, address1, node0.getblockhash(40), 5, 6, prev_tx) + assert_raises_rpc_error(-26, 'bad-vote-invalid', node0.sendrawtransaction, tx) + tx = make_vote_tx(finalizer1, address1, node0.getblockhash(40), 7, 6, prev_tx) + assert_raises_rpc_error(-26, 'bad-vote-invalid', node0.sendrawtransaction, tx) + self.log.info('Bad configured votes cannot screw up things') + + # check that make_vote_tx works as expected (we really rely on this guy on tests above) + tx = make_vote_tx(finalizer1, address1, node0.getblockhash(40), 7, 8, prev_tx) + node0.sendrawtransaction(tx) + self.wait_for_vote_and_disconnect(finalizer=finalizer2, node=node0) + self.wait_for_vote_and_disconnect(finalizer=finalizer3, node=node0) + generate_block(node0) + assert_equal(node0.getblockcount(), 45) + assert_finalizationstate(node0, {'currentDynasty': 6, + 'currentEpoch': 9, + 'lastJustifiedEpoch': 8, + 'lastFinalizedEpoch': 7, + 'validators': 3}) + self.log.info('make_vote_tx works together with real finalizers') + # UNIT-E TODO: there is a know issue https://github.com/dtr-org/unit-e/issues/643 # that finalizer doesn't vote after processing the checkpoint. # Once it's resolved, the bellow test must be uncommented