txid = rpc.staking.unbond(addr, int(state['bonded']), enckey=enckey, name='target') print('Wait for tx and 3 blocks') wait_for_blocks(rpc, 3) wait_for_tx(rpc, txid) rpc.wallet.sync(enckey=enckey, name='target') assert len(rpc.chain.validators()['validators']) == 2 unbonded_from = rpc.staking.state(addr)['unbonded_from'] print('Wait until unbonded_from', unbonded_from) wait_for_blocktime(rpc, unbonded_from) print('Withdraw unbonded', addr) transfer = rpc.address.list(enckey=enckey, type='transfer', name='target')[0] txid = rpc.staking.withdraw_all_unbonded( addr, transfer, enckey=enckey, name='target', # test fee calculation view_keys=[ rpc.wallet.view_key(enckey=enckey, name='target'), # view key of node1 rpc.wallet.view_key(enckey=rpc.wallet.enckey()), ])
############## unbond and re-join ################## rpc.wallet.sync(enckey=enckey, name='target') txid = rpc.staking.unbond(addr, int(state['bonded']) - 100000000 + 1, enckey=enckey, name='target') print('Wait for tx and 3 blocks') wait_for_blocks(rpc, 3) wait_for_tx(rpc, txid) rpc.wallet.sync(enckey=enckey, name='target') assert len(rpc.chain.validators()['validators']) == 2 unbonded_from = rpc.staking.state(addr, name='target')['unbonded_from'] print('Wait until unbonded_from', unbonded_from) wait_for_blocktime(rpc, unbonded_from) print('Withdraw unbonded', addr) transfer = rpc.address.list(enckey=enckey, type='transfer', name='target')[0] txid = rpc.staking.withdraw_all_unbonded( addr, transfer, enckey=enckey, name='target', # test fee calculation view_keys=[ rpc.wallet.view_key(enckey=enckey, name='target'), # view key of node1 rpc.wallet.view_key(enckey=rpc.wallet.enckey()), ] ) print('Wait for transaction', txid) wait_for_tx(rpc, txid)
supervisor.supervisor.startProcessGroup('node1') wait_for_port(BASE_PORT + 10 + 7) wait_for_blocks(rpc, 13) rpc.wallet.sync() state = rpc.staking.state(bonded_staking) assert state['node_meta']['CouncilNode']['jailed_until'] is not None, 'jailed for byzantine fault' punishment = state['last_slash'] print('punishment', punishment) assert punishment['kind'] == 'ByzantineFault' assert len(rpc.chain.validators()['validators']) == 1 stop_node(supervisor, 'node1') print('Wait until jailed_until', state['node_meta']['CouncilNode']['jailed_until']) wait_for_blocktime(rpc, state['node_meta']['CouncilNode']['jailed_until']) txid = rpc.staking.unjail(bonded_staking) print('Wait for unjail transaction', txid) wait_for_tx(rpc, txid) rpc.wallet.sync() print('re-join') txid = rpc.staking.join( 'node0', SigningKey(VALIDATOR_SEED).pub_key_base64(), bonded_staking, rpc.staking.gen_keypackage(), ) print('Wait for join node transaction', txid) wait_for_tx(rpc, txid)
wait_for_port(BASE_PORT + 10 + 7) wait_for_blocks(rpc, 13) rpc.wallet.sync() state = rpc.staking.state(bonded_staking) assert state['validator'][ 'jailed_until'] is not None, 'jailed for byzantine fault' punishment = state['last_slash'] print('punishment', punishment) assert punishment['kind'] == 'ByzantineFault' assert len(rpc.chain.validators()['validators']) == 1 stop_node(supervisor, 'node1') print('Wait until jailed_until', state['validator']['jailed_until']) wait_for_blocktime(rpc, state['validator']['jailed_until']) txid = rpc.staking.unjail(bonded_staking) print('Wait for unjail transaction', txid) wait_for_tx(rpc, txid) rpc.wallet.sync() print('re-join') txid = rpc.staking.join( 'node0', SigningKey(VALIDATOR_SEED).pub_key_base64(), bonded_staking, rpc.staking.gen_keypackage(), ) print('Wait for join node transaction', txid) wait_for_tx(rpc, txid)
block_time = latest_block_time(rpc) if last_bonded == bonded_rewarded: # wait for it to get jailed and slashed later wait_for_blocks(rpc, 6) # jailed and slashed slashed = int(last_bonded * 0.2) state = rpc.chain.staking(bonded_staking2) assert int( state['bonded'] ) == last_bonded - slashed, 'incorrect bonded: %s' % state['bonded'] last_bonded = int(state['bonded']) else: # already jailed slashed = int(init_bonded * 0.2) assert last_bonded == bonded_rewarded - slashed, 'incorrect bonded: %s' % last_bonded assert state['node_meta']['CouncilNode']['jailed_until'] is not None stop_node(supervisor, 'node1') # wait for reward period, for second reward distribution wait_for_blocktime(rpc, block_time + 10) # minted = 6182420000 minted = monetary_expansion(bonded_rewarded, int(145000000000000000 * 0.99986)) state = rpc.chain.staking(bonded_staking2) assert int(state['bonded']) == last_bonded, 'jailed node don\'t get rewarded' state = rpc.chain.staking(bonded_staking) assert int(state['bonded']) == bonded_rewarded + minted + slashed
if last_bonded == bonded_rewarded: # wait for it to get jailed and slashed later wait_for_blocks(rpc, 6) # jailed and slashed slashed = int(last_bonded * 0.2) state = rpc.chain.staking(bonded_staking2) assert int( state['bonded'] ) == last_bonded - slashed, 'incorrect bonded: %s' % state['bonded'] last_bonded = int(state['bonded']) else: # already jailed slashed = int(init_bonded * 0.2) assert last_bonded == bonded_rewarded - slashed, 'incorrect bonded: %s' % last_bonded assert state['node_meta']['CouncilNode']['jailed_until'] is not None stop_node(supervisor, 'node1') # wait for reward period, for second reward distribution height = wait_for_blocktime(rpc, block_time + 10) wait_for_block_state(rpc, height) # minted = 6182420000 minted = monetary_expansion(bonded_rewarded, int(145000000000000000 * 0.99986)) state = rpc.chain.staking(bonded_staking2, height) assert int(state['bonded']) == last_bonded, 'jailed node don\'t get rewarded' state = rpc.chain.staking(bonded_staking, height) assert int(state['bonded']) == bonded_rewarded + minted + slashed