From 80863e25085226135eb86f7ec7116e9ea2a23ff7 Mon Sep 17 00:00:00 2001 From: Roy Ben Abraham Date: Wed, 17 Nov 2021 14:23:52 +0700 Subject: [PATCH 1/4] Wait for withdrawal era instead of waiting 500 seconds --- test/functional/feature_staking_unlock_and_withdraw.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/functional/feature_staking_unlock_and_withdraw.py b/test/functional/feature_staking_unlock_and_withdraw.py index c467002..79a8f51 100755 --- a/test/functional/feature_staking_unlock_and_withdraw.py +++ b/test/functional/feature_staking_unlock_and_withdraw.py @@ -65,6 +65,7 @@ def run_test(self): assert_equal(len(ledger[0][1]['unlocking']),0) alice_stash = Keypair.create_from_uri('//Alice//stash') + alice = Keypair.create_from_uri('//Alice') # fetch the genesis utxo from storage utxos = list(client.utxos_for(alice_stash)) @@ -87,9 +88,11 @@ def run_test(self): assert_equal(events[2].value['event_id'], 'StakeUnlocked') ledger = list(client.get_staking_ledger()) + assert_equal(len(ledger),2) - time.sleep(500) + while client.current_era() < client.withdrawal_era(alice): + time.sleep(1) (_, _, w_events) = client.withdraw_stake(alice_stash) From dbcb7abd2f024c415f25e93e3c8469af38de8582 Mon Sep 17 00:00:00 2001 From: Roy Ben Abraham Date: Wed, 17 Nov 2021 14:24:19 +0700 Subject: [PATCH 2/4] Enable feature_staking_unlock_and_withdraw test --- test/functional/test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index ad07c29..635b752 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -66,7 +66,7 @@ 'feature_staking_withdraw_no_unlock.py', 'feature_staking_withdraw_not_validator.py', 'feature_smart_contract_test.py', -# 'feature_staking_unlock_and_withdraw.py' ## should be ran on 20 secs + 'feature_staking_unlock_and_withdraw.py' ## should be ran on 20 secs # Don't append tests at the end to avoid merge conflicts # Put them in a random line within the section that fits their approximate run-time ] From ed8f677fa479d1d476b8f5b7b337d26c0d959a82 Mon Sep 17 00:00:00 2001 From: Roy Ben Abraham Date: Wed, 17 Nov 2021 17:33:25 +0700 Subject: [PATCH 3/4] Change current_era to return an int rather than scalecodec.types.U32 --- test/functional/test_framework/mintlayer/staking.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/functional/test_framework/mintlayer/staking.py b/test/functional/test_framework/mintlayer/staking.py index 722e9ac..cdfec7a 100644 --- a/test/functional/test_framework/mintlayer/staking.py +++ b/test/functional/test_framework/mintlayer/staking.py @@ -20,7 +20,10 @@ def current_era(self): module='Staking', storage_function='CurrentEra' ) - return query + # this query returns an object of type scalecodec.types.U32 + # so we convert it to an integer + # TODO find a more elegant way to do conversion + return int("{}".format(query)) """ gets the staking ledger of the given key """ def get_ledger(self, keypair): From f5c1ac2f105e7083c3f7969cdce160b50911bff3 Mon Sep 17 00:00:00 2001 From: Roy Ben Abraham Date: Wed, 17 Nov 2021 17:32:46 +0700 Subject: [PATCH 4/4] Added hard timeout for awaiting withdrawal_era --- test/functional/feature_staking_unlock_and_withdraw.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/functional/feature_staking_unlock_and_withdraw.py b/test/functional/feature_staking_unlock_and_withdraw.py index 79a8f51..7edff73 100755 --- a/test/functional/feature_staking_unlock_and_withdraw.py +++ b/test/functional/feature_staking_unlock_and_withdraw.py @@ -91,8 +91,14 @@ def run_test(self): assert_equal(len(ledger),2) + time_elapsed = 0 + max_wait = 1200 + time_step = 1 while client.current_era() < client.withdrawal_era(alice): - time.sleep(1) + if time_elapsed > max_wait: + raise Exception('Timeout: waited too long for withdrawal_era') + time.sleep(time_step) + time_elapsed +=time_step (_, _, w_events) = client.withdraw_stake(alice_stash)