mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
functional_tests: add alt chains tests
This commit is contained in:
parent
f8be31d269
commit
7c657bb2dd
2 changed files with 49 additions and 1 deletions
|
@ -224,7 +224,10 @@ class BlockchainTest():
|
||||||
def _test_alt_chains(self):
|
def _test_alt_chains(self):
|
||||||
print('Testing alt chains')
|
print('Testing alt chains')
|
||||||
daemon = Daemon()
|
daemon = Daemon()
|
||||||
|
res = daemon.get_alt_blocks_hashes()
|
||||||
|
starting_alt_blocks = res.blks_hashes if 'blks_hashes' in res else []
|
||||||
res = daemon.get_info()
|
res = daemon.get_info()
|
||||||
|
root_block_hash = res.top_block_hash
|
||||||
height = res.height
|
height = res.height
|
||||||
prev_hash = res.top_block_hash
|
prev_hash = res.top_block_hash
|
||||||
res_template = daemon.getblocktemplate('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm')
|
res_template = daemon.getblocktemplate('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm')
|
||||||
|
@ -247,15 +250,23 @@ class BlockchainTest():
|
||||||
|
|
||||||
print 'mining 3 on 1'
|
print 'mining 3 on 1'
|
||||||
# three more on [1]
|
# three more on [1]
|
||||||
|
chain1 = []
|
||||||
res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3, prev_block = alt_blocks[1], starting_nonce = nonce)
|
res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3, prev_block = alt_blocks[1], starting_nonce = nonce)
|
||||||
assert res.height == height + 3
|
assert res.height == height + 3
|
||||||
assert len(res.blocks) == 3
|
assert len(res.blocks) == 3
|
||||||
blk_hash = res.blocks[2]
|
blk_hash = res.blocks[2]
|
||||||
res = daemon.getblockheaderbyhash(blk_hash)
|
res = daemon.getblockheaderbyhash(blk_hash)
|
||||||
nonce = res.block_header.nonce
|
nonce = res.block_header.nonce
|
||||||
print('mined 3 blocks to height ' + str(height + 3))
|
|
||||||
assert not res.block_header.orphan_status
|
assert not res.block_header.orphan_status
|
||||||
nonce += 1
|
nonce += 1
|
||||||
|
chain1.append(blk_hash)
|
||||||
|
chain1.append(res.block_header.prev_hash)
|
||||||
|
|
||||||
|
print('Checking alt blocks match')
|
||||||
|
res = daemon.get_alt_blocks_hashes()
|
||||||
|
assert len(res.blks_hashes) == len(starting_alt_blocks) + 4
|
||||||
|
for txid in alt_blocks:
|
||||||
|
assert txid in res.blks_hashes or txid == alt_blocks[1]
|
||||||
|
|
||||||
print 'mining 4 on 3'
|
print 'mining 4 on 3'
|
||||||
# 4 more on [3], the chain will reorg when we mine the 4th
|
# 4 more on [3], the chain will reorg when we mine the 4th
|
||||||
|
@ -277,6 +288,28 @@ class BlockchainTest():
|
||||||
assert res.height == height + 5
|
assert res.height == height + 5
|
||||||
assert res.top_block_hash == prev_block
|
assert res.top_block_hash == prev_block
|
||||||
|
|
||||||
|
print('Checking alt blocks match')
|
||||||
|
res = daemon.get_alt_blocks_hashes()
|
||||||
|
blks_hashes = res.blks_hashes
|
||||||
|
assert len(blks_hashes) == len(starting_alt_blocks) + 7
|
||||||
|
for txid in alt_blocks:
|
||||||
|
assert txid in blks_hashes or txid == alt_blocks[3]
|
||||||
|
for txid in chain1:
|
||||||
|
assert txid in blks_hashes
|
||||||
|
|
||||||
|
res = daemon.get_alternate_chains()
|
||||||
|
assert len(res.chains) == 4
|
||||||
|
tips = [chain.block_hash for chain in res.chains]
|
||||||
|
for txid in tips:
|
||||||
|
assert txid in blks_hashes
|
||||||
|
for chain in res.chains:
|
||||||
|
assert chain.length in [1, 4]
|
||||||
|
assert chain.length == len(chain.block_hashes)
|
||||||
|
assert chain.height == height + chain.length - 1 # all happen start at the same height
|
||||||
|
assert chain.main_chain_parent_block == root_block_hash
|
||||||
|
for txid in [alt_blocks[0], alt_blocks[2], alt_blocks[4]]:
|
||||||
|
assert len([chain for chain in res.chains if chain.block_hash == txid]) == 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
BlockchainTest().run_test()
|
BlockchainTest().run_test()
|
||||||
|
|
|
@ -312,3 +312,18 @@ class Daemon(object):
|
||||||
'categories': categories,
|
'categories': categories,
|
||||||
}
|
}
|
||||||
return self.rpc.send_request('/set_log_categories', set_log_categories)
|
return self.rpc.send_request('/set_log_categories', set_log_categories)
|
||||||
|
|
||||||
|
def get_alt_blocks_hashes(self):
|
||||||
|
get_alt_blocks_hashes = {
|
||||||
|
}
|
||||||
|
return self.rpc.send_request('/get_alt_blocks_hashes', get_alt_blocks_hashes)
|
||||||
|
|
||||||
|
def get_alternate_chains(self):
|
||||||
|
get_alternate_chains = {
|
||||||
|
'method': 'get_alternate_chains',
|
||||||
|
'params': {
|
||||||
|
},
|
||||||
|
'jsonrpc': '2.0',
|
||||||
|
'id': '0'
|
||||||
|
}
|
||||||
|
return self.rpc.send_json_rpc_request(get_alternate_chains)
|
||||||
|
|
Loading…
Reference in a new issue