Skip to content

Commit

Permalink
Add test, update logs
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Frolov <[email protected]>
  • Loading branch information
frolosofsky committed May 9, 2019
1 parent df0dd7d commit d751b58
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/esperanza/finalizationstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
32 changes: 31 additions & 1 deletion test/functional/finalization_vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit d751b58

Please sign in to comment.