def reset(self): print('Resetting blockchain') daemon = Daemon() res = daemon.get_height() daemon.pop_blocks(res.height - 1) daemon.flush_txpool()
def reset(self): print('Resetting blockchain') daemon = Daemon() daemon.pop_blocks(1000) daemon.flush_txpool()
def test_randomx(self): print("Test RandomX") daemon = Daemon() wallet = Wallet() res = daemon.get_height() daemon.pop_blocks(res.height - 1) daemon.flush_txpool() epoch = int(os.environ['SEEDHASH_EPOCH_BLOCKS']) lag = int(os.environ['SEEDHASH_EPOCH_LAG']) address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' # check we can generate blocks, and that the seed hash changes when expected res = daemon.getblocktemplate(address) first_seed_hash = res.seed_hash daemon.generateblocks(address, 1 + lag) res = daemon.mining_status() assert res.active == False assert res.pow_algorithm == 'RandomX' res = daemon.getblocktemplate(address) seed_hash = res.seed_hash t0 = time.time() daemon.generateblocks(address, epoch - 3) t0 = time.time() - t0 res = daemon.get_info() assert res.height == lag + epoch - 1 res = daemon.getblocktemplate(address) assert seed_hash == res.seed_hash t0 = time.time() daemon.generateblocks(address, 1) t0 = time.time() - t0 res = daemon.get_info() assert res.height == lag + epoch daemon.generateblocks(address, 1) res = daemon.getblocktemplate(address) assert seed_hash != res.seed_hash new_seed_hash = res.seed_hash t0 = time.time() daemon.generateblocks(address, epoch - 1) t0 = time.time() - t0 res = daemon.getblocktemplate(address) assert new_seed_hash == res.seed_hash daemon.generateblocks(address, 1) res = daemon.getblocktemplate(address) assert new_seed_hash != res.seed_hash new_seed_hash = res.seed_hash t0 = time.time() daemon.generateblocks(address, epoch - 1) t0 = time.time() - t0 res = daemon.getblocktemplate(address) assert new_seed_hash == res.seed_hash daemon.generateblocks(address, 1) res = daemon.getblocktemplate(address) assert new_seed_hash != res.seed_hash #print('First mining: ' + str(t0)) # pop all these blocks, and feed them again to monerod print('Recreating the chain') res = daemon.get_info() height = res.height assert height == lag + epoch * 3 + 1 block_hashes = [ x.hash for x in daemon.getblockheadersrange(0, height - 1).headers ] assert len(block_hashes) == height blocks = [] for i in range(len(block_hashes)): res = daemon.getblock(height=i) assert res.block_header.hash == block_hashes[i] blocks.append(res.blob) daemon.pop_blocks(height) res = daemon.get_info() assert res.height == 1 res = daemon.getblocktemplate(address) assert first_seed_hash == res.seed_hash t0 = time.time() for h in range(len(block_hashes)): res = daemon.submitblock(blocks[h]) t0 = time.time() - t0 res = daemon.get_info() assert height == res.height res = daemon.getblocktemplate(address) assert new_seed_hash != res.seed_hash res = daemon.pop_blocks(1) res = daemon.getblocktemplate(address) assert new_seed_hash == res.seed_hash #print('Submit: ' + str(t0)) # start mining from the genesis block again print('Mining from genesis block again') res = daemon.get_height() top_hash = res.hash res = daemon.getblockheaderbyheight(0) genesis_block_hash = res.block_header.hash t0 = time.time() daemon.generateblocks(address, height - 2, prev_block=genesis_block_hash) t0 = time.time() - t0 res = daemon.get_info() assert res.height == height - 1 assert res.top_block_hash == top_hash #print('Second mining: ' + str(t0)) # that one will cause a huge reorg print('Adding one to reorg') res = daemon.generateblocks(address, 1) assert len(res.blocks) == 1 new_top_hash = res.blocks[0] res = daemon.get_info() assert res.height == height assert res.top_block_hash == new_top_hash
def reset(self): print('Resetting blockchain') daemon = Daemon() daemon.pop_blocks(1000) daemon.flush_txpool()
def check_txpool(self): daemon = Daemon() wallet = Wallet() res = daemon.get_info() height = res.height txpool_size = res.tx_pool_size txes = self.create_txes( '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 5) res = daemon.get_info() assert res.tx_pool_size == txpool_size + 5 txpool_size = res.tx_pool_size res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size for txid in txes.keys(): x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == False assert x.last_failed_id_hash == '0' * 64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(txes.keys()) print('Flushing 2 transactions') txes_keys = list(txes.keys()) daemon.flush_txpool([txes_keys[1], txes_keys[3]]) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 assert len([x for x in res.transactions if x.id_hash == txes_keys[1]]) == 0 assert len([x for x in res.transactions if x.id_hash == txes_keys[3]]) == 0 new_keys = list(txes.keys()) new_keys.remove(txes_keys[1]) new_keys.remove(txes_keys[3]) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(new_keys) print('Flushing unknown transactions') unknown_txids = ['1' * 64, '2' * 64, '3' * 64] daemon.flush_txpool(unknown_txids) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 print('Mining transactions') daemon.generateblocks( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) res = daemon.get_transaction_pool() assert not 'transactions' in res or len( res.transactions) == txpool_size - 5 res = daemon.get_transaction_pool_hashes() assert not 'tx_hashes' in res or len(res.tx_hashes) == 0 print('Popping block') daemon.pop_blocks(1) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(new_keys) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 for txid in new_keys: x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == True assert x.last_failed_id_hash == '0' * 64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob
def check_txpool(self): daemon = Daemon() wallet = Wallet() res = daemon.get_info() height = res.height txpool_size = res.tx_pool_size self.check_empty_pool() txes = self.create_txes('46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 5) res = daemon.get_info() assert res.tx_pool_size == txpool_size + 5 txpool_size = res.tx_pool_size res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size total_bytes = 0 total_fee = 0 min_bytes = 99999999999999 max_bytes = 0 for txid in txes.keys(): x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == False assert x.last_failed_id_hash == '0'*64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob total_bytes += x.blob_size total_fee += x.fee min_bytes = min(min_bytes, x.blob_size) max_bytes = max(max_bytes, x.blob_size) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(txes.keys()) res = daemon.get_transaction_pool_stats() assert res.pool_stats.bytes_total == total_bytes assert res.pool_stats.bytes_min == min_bytes assert res.pool_stats.bytes_max == max_bytes assert res.pool_stats.bytes_med >= min_bytes and res.pool_stats.bytes_med <= max_bytes assert res.pool_stats.fee_total == total_fee assert res.pool_stats.txs_total == len(txes) assert res.pool_stats.num_failing == 0 assert res.pool_stats.num_10m == 0 assert res.pool_stats.num_not_relayed == 0 assert res.pool_stats.num_double_spends == 0 print('Flushing 2 transactions') txes_keys = list(txes.keys()) daemon.flush_txpool([txes_keys[1], txes_keys[3]]) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 assert len([x for x in res.transactions if x.id_hash == txes_keys[1]]) == 0 assert len([x for x in res.transactions if x.id_hash == txes_keys[3]]) == 0 new_keys = list(txes.keys()) new_keys.remove(txes_keys[1]) new_keys.remove(txes_keys[3]) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(new_keys) res = daemon.get_transaction_pool() assert len(res.transactions) == len(new_keys) total_bytes = 0 total_fee = 0 min_bytes = 99999999999999 max_bytes = 0 for txid in new_keys: x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == False assert x.last_failed_id_hash == '0'*64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob total_bytes += x.blob_size total_fee += x.fee min_bytes = min(min_bytes, x.blob_size) max_bytes = max(max_bytes, x.blob_size) res = daemon.get_transaction_pool_stats() assert res.pool_stats.bytes_total == total_bytes assert res.pool_stats.bytes_min == min_bytes assert res.pool_stats.bytes_max == max_bytes assert res.pool_stats.bytes_med >= min_bytes and res.pool_stats.bytes_med <= max_bytes assert res.pool_stats.fee_total == total_fee assert res.pool_stats.txs_total == len(new_keys) assert res.pool_stats.num_failing == 0 assert res.pool_stats.num_10m == 0 assert res.pool_stats.num_not_relayed == 0 assert res.pool_stats.num_double_spends == 0 print('Flushing unknown transactions') unknown_txids = ['1'*64, '2'*64, '3'*64] daemon.flush_txpool(unknown_txids) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 print('Mining transactions') daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) res = daemon.get_transaction_pool() assert not 'transactions' in res or len(res.transactions) == txpool_size - 5 res = daemon.get_transaction_pool_hashes() assert not 'tx_hashes' in res or len(res.tx_hashes) == 0 self.check_empty_pool() print('Popping block') daemon.pop_blocks(1) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(new_keys) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 for txid in new_keys: x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == True assert x.last_failed_id_hash == '0'*64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob print('Checking relaying txes') res = daemon.get_transaction_pool_hashes() assert len(res.tx_hashes) > 0 txid = res.tx_hashes[0] daemon.relay_tx([txid]) res = daemon.get_transactions([txid]) assert len(res.txs) == 1 assert res.txs[0].tx_hash == txid assert res.txs[0].in_pool assert res.txs[0].relayed daemon.flush_txpool() self.check_empty_pool()
def check_txpool(self): daemon = Daemon() wallet = Wallet() res = daemon.get_info() height = res.height txpool_size = res.tx_pool_size txes = self.create_txes('46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 5) res = daemon.get_info() assert res.tx_pool_size == txpool_size + 5 txpool_size = res.tx_pool_size res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size for txid in txes.keys(): x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == False assert x.last_failed_id_hash == '0'*64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(txes.keys()) print('Flushing 2 transactions') txes_keys = list(txes.keys()) daemon.flush_txpool([txes_keys[1], txes_keys[3]]) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 assert len([x for x in res.transactions if x.id_hash == txes_keys[1]]) == 0 assert len([x for x in res.transactions if x.id_hash == txes_keys[3]]) == 0 new_keys = list(txes.keys()) new_keys.remove(txes_keys[1]) new_keys.remove(txes_keys[3]) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(new_keys) print('Flushing unknown transactions') unknown_txids = ['1'*64, '2'*64, '3'*64] daemon.flush_txpool(unknown_txids) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 print('Mining transactions') daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) res = daemon.get_transaction_pool() assert not 'transactions' in res or len(res.transactions) == txpool_size - 5 res = daemon.get_transaction_pool_hashes() assert not 'tx_hashes' in res or len(res.tx_hashes) == 0 print('Popping block') daemon.pop_blocks(1) res = daemon.get_transaction_pool_hashes() assert sorted(res.tx_hashes) == sorted(new_keys) res = daemon.get_transaction_pool() assert len(res.transactions) == txpool_size - 2 for txid in new_keys: x = [x for x in res.transactions if x.id_hash == txid] assert len(x) == 1 x = x[0] assert x.kept_by_block == True assert x.last_failed_id_hash == '0'*64 assert x.double_spend_seen == False assert x.weight >= x.blob_size assert x.blob_size * 2 == len(txes[txid].tx_blob) assert x.fee == txes[txid].fee assert x.tx_blob == txes[txid].tx_blob