-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Synchronize wallet import and chain reindexing
Signed-off-by: Dmitry Saveliev <dima@thirdhash.com>
- Loading branch information
Showing
5 changed files
with
166 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2019 The Unit-e developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
""" | ||
Test running united with -reindex options and with finalization transactions | ||
- Start a pair of nodes - validator and proposer | ||
- Run a validator for some time | ||
- Restart both nodes and check if finalization can continue with restarted state | ||
""" | ||
|
||
from test_framework.test_framework import UnitETestFramework | ||
from test_framework.util import ( | ||
assert_equal, | ||
connect_nodes, | ||
connect_nodes_bi, | ||
disconnect_nodes, | ||
json, | ||
sync_blocks, | ||
wait_until, | ||
) | ||
|
||
MIN_DEPOSIT = 1500 | ||
EPOCH_LENGTH = 10 | ||
|
||
|
||
class FeatureReindexCommits(UnitETestFramework): | ||
|
||
def get_extra_args(self, reindex): | ||
finalization_params = json.dumps({ | ||
'epochLength': EPOCH_LENGTH, | ||
'minDepositSize': MIN_DEPOSIT, | ||
'dynastyLogoutDelay': 2, | ||
'withdrawalEpochDelay': 2 | ||
}) | ||
proposer_args = ['-proposing=1', '-debug=all', '-whitelist=127.0.0.1', | ||
'-esperanzaconfig=' + finalization_params] | ||
|
||
validator_args = [ | ||
'-validating=1', | ||
'-debug=all', | ||
'-whitelist=127.0.0.1', | ||
'-esperanzaconfig=' + | ||
finalization_params] | ||
|
||
if reindex: | ||
proposer_args.append('-reindex') | ||
validator_args.append('-reindex') | ||
|
||
return [proposer_args, validator_args] | ||
|
||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.extra_args = self.get_extra_args(False) | ||
self.num_nodes = len(self.extra_args) | ||
|
||
def run_test(self): | ||
proposer = self.nodes[0] | ||
finalizer = self.nodes[1] | ||
|
||
self.setup_stake_coins(proposer, finalizer) | ||
self.generate_sync(proposer) | ||
wait_until(lambda: finalizer.getvalidatorinfo()[ | ||
'validator_status'] == 'NOT_VALIDATING', timeout=5) | ||
|
||
self.generate_deposit() | ||
wait_until(lambda: finalizer.getvalidatorinfo()[ | ||
'validator_status'] == 'IS_VALIDATING', timeout=5) | ||
|
||
self.assert_votes(count=10) | ||
|
||
self.restart_nodes(True) | ||
wait_until(lambda: finalizer.getvalidatorinfo()[ | ||
'validator_status'] == 'IS_VALIDATING', timeout=5) | ||
|
||
self.generate_sync(proposer, EPOCH_LENGTH) | ||
|
||
self.restart_nodes(False) | ||
wait_until(lambda: finalizer.getvalidatorinfo()[ | ||
'validator_status'] == 'IS_VALIDATING', timeout=5) | ||
|
||
last_fin_epoch = finalizer.getfinalizationstate()['lastFinalizedEpoch'] | ||
self.assert_votes(count=10) | ||
assert_equal( | ||
last_fin_epoch + 10, | ||
finalizer.getfinalizationstate()['lastFinalizedEpoch']) | ||
|
||
def generate_deposit(self): | ||
proposer = self.nodes[0] | ||
finalizer = self.nodes[1] | ||
|
||
deposit_tx = finalizer.deposit( | ||
finalizer.getnewaddress( | ||
"", "legacy"), MIN_DEPOSIT) | ||
self.wait_for_transaction(deposit_tx) | ||
|
||
proposer.generatetoaddress(51, proposer.getnewaddress('', 'bech32')) | ||
assert_equal(proposer.getblockcount(), 52) | ||
|
||
def assert_votes(self, count): | ||
proposer = self.nodes[0] | ||
finalizer = self.nodes[1] | ||
|
||
disconnect_nodes(proposer, finalizer.index) | ||
votes = self.generate_epoch( | ||
EPOCH_LENGTH, | ||
proposer=proposer, | ||
finalizer=finalizer, | ||
count=count) | ||
assert_equal(len(votes), count) | ||
connect_nodes(finalizer, proposer.index) | ||
sync_blocks(self.nodes) | ||
|
||
def restart_nodes(self, reindex): | ||
node0 = self.nodes[0] | ||
block_count_before = node0.getblockcount() | ||
|
||
self.stop_nodes() | ||
self.start_nodes(self.get_extra_args(reindex)) | ||
|
||
for i in range(self.num_nodes - 1): | ||
connect_nodes_bi(self.nodes, i, i + 1) | ||
|
||
wait_until(lambda: node0.getblockcount() == block_count_before) | ||
sync_blocks(self.nodes) | ||
|
||
|
||
if __name__ == '__main__': | ||
FeatureReindexCommits().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters