Skip to content

Commit

Permalink
fix rpc_getblocksnapshot.py
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Frolov <[email protected]>
  • Loading branch information
frolosofsky committed Feb 19, 2019
1 parent b2e106b commit 7a5ed8c
Showing 1 changed file with 65 additions and 60 deletions.
125 changes: 65 additions & 60 deletions test/functional/rpc_getblocksnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
connect_nodes,
sync_blocks,
disconnect_nodes,
wait_until,
)


Expand All @@ -27,64 +28,68 @@ def set_test_params(self):
self.setup_clean_chain = True

def run_test(self):
def assert_deleted_snapshot(node, height):
block_hash = node.getblockhash(height)
res = node.getblocksnapshot(block_hash)
keys = sorted(res.keys())
assert_equal(keys, [
'block_hash',
'snapshot_deleted',
'snapshot_hash',
'valid',
])
assert_equal(res['valid'], False)
assert_equal(res['snapshot_deleted'], True)
assert_equal(res['block_hash'], block_hash)
assert_equal(len(res['snapshot_hash']), 64)
def wait_deleted_snapshot(node, height):
def check():
block_hash = node.getblockhash(height)
res = node.getblocksnapshot(block_hash)
keys = sorted(res.keys())
return (keys == [
'block_hash',
'snapshot_deleted',
'snapshot_hash',
'valid',
]
and res['valid'] == False
and res['snapshot_deleted'] == True
and res['block_hash'] == block_hash
and len(res['snapshot_hash']) == 64)
wait_until(check)

def assert_valid_finalized(node, height):
block_hash = node.getblockhash(height)
res = node.getblocksnapshot(block_hash)
keys = sorted(res.keys())
assert_equal(keys, [
'block_hash',
'block_height',
'chain_work',
'snapshot_finalized',
'snapshot_hash',
'stake_modifier',
'total_outputs',
'total_utxo_subsets',
'valid',
])
assert_equal(res['valid'], True)
assert_equal(res['block_hash'], block_hash)
assert_equal(res['block_height'], height)
assert_equal(res['snapshot_finalized'], True)
assert_equal(len(res['snapshot_hash']), 64)
assert_equal(len(res['stake_modifier']), 64)
def wait_valid_finalized(node, height):
def check():
block_hash = node.getblockhash(height)
res = node.getblocksnapshot(block_hash)
keys = sorted(res.keys())
return (keys == [
'block_hash',
'block_height',
'chain_work',
'snapshot_finalized',
'snapshot_hash',
'stake_modifier',
'total_outputs',
'total_utxo_subsets',
'valid',
]
and res['valid'] == True
and res['block_hash'] == block_hash
and res['block_height'] == height
and res['snapshot_finalized'] == True
and len(res['snapshot_hash']) == 64
and len(res['stake_modifier']) == 64)

def assert_valid_non_finalized(node, height):
block_hash = node.getblockhash(height)
res = node.getblocksnapshot(block_hash)
keys = sorted(res.keys())
assert_equal(keys, [
'block_hash',
'block_height',
'chain_work',
'snapshot_finalized',
'snapshot_hash',
'stake_modifier',
'total_outputs',
'total_utxo_subsets',
'valid',
])
assert_equal(res['valid'], True)
assert_equal(res['block_hash'], block_hash)
assert_equal(res['block_height'], height)
assert_equal(res['snapshot_finalized'], False)
assert_equal(len(res['snapshot_hash']), 64)
assert_equal(len(res['stake_modifier']), 64)
def wait_valid_non_finalized(node, height):
def check():
block_hash = node.getblockhash(height)
res = node.getblocksnapshot(block_hash)
keys = sorted(res.keys())
return (keys == [
'block_hash',
'block_height',
'chain_work',
'snapshot_finalized',
'snapshot_hash',
'stake_modifier',
'total_outputs',
'total_utxo_subsets',
'valid',
]
and res['valid'] == True
and res['block_hash'] == block_hash
and res['block_height'] == height
and res['snapshot_finalized'] == False
and len(res['snapshot_hash']) == 64
and len(res['stake_modifier']) == 64)

# generate two forks that are available for node0
# 0 ... 5 ... 10 ... 25
Expand All @@ -101,10 +106,10 @@ def assert_valid_non_finalized(node, height):
disconnect_nodes(node1, node0.index)
node0.generatetoaddress(20, node0.getnewaddress())

assert_deleted_snapshot(node0, height=3) # actually deleted
assert_deleted_snapshot(node0, height=4) # wasn't created
assert_valid_finalized(node0, height=8)
assert_valid_non_finalized(node0, height=28)
wait_deleted_snapshot(node0, height=3) # actually deleted
wait_deleted_snapshot(node0, height=4) # wasn't created
wait_valid_finalized(node0, height=8)
wait_valid_non_finalized(node0, height=28)

res = node0.getblocksnapshot(forked_block_hash)
assert_equal(res['valid'], False)
Expand Down

0 comments on commit 7a5ed8c

Please sign in to comment.