def prepare_env(pre): global g_counter g_counter += 1 r = eosapi.push_action('helloworld11', 'clearenv', int.to_bytes(g_counter, 4, 'little'), {'helloworld11': 'active'}) for addr in pre: info = pre[addr] balance = evm.hex2int(info['balance']) balance = int.to_bytes(balance, 32, 'little') balance = balance.hex() code = info['code'][2:] nonce = evm.hex2int(info['nonce']) storage = [] for key in info['storage']: value = info['storage'][key] value = hex2int(value) key = hex2int(key) key = int.to_bytes(key, 32, 'big').hex() value = int.to_bytes(value, 32, 'big').hex() storage.append(key) storage.append(value) args = dict(address=addr[2:], nonce=nonce, balance=balance, code=code, storage=storage, counter=g_counter) # logger.info(args) ret = eosapi.push_action('helloworld11', 'setaddrinfo', args, {'helloworld11': 'active'}) output = ret['processed']['action_traces'][0]['console']
def convert_storage(s): out = {} for _s in s: key = hex2int(_s['key']) value = hex2int(_s['value']) out[key] = value return out
def convert_post_storage(s): _s = {} for key in s: value = s[key] value = hex2int(value) key = hex2int(key) _s[key] = value return _s
def run_test(test): global g_counter global g_failed_gas_check g_counter += 1 trx = test['transaction'] transaction_index = 0 for data in trx['data']: for gas_limit in trx['gasLimit']: for value in trx['value']: prepare_env(test['pre']) value = hex2int(value) gas_price = hex2int(trx['gasPrice']) nonce = hex2int(trx['nonce']) to = trx['to'] secret_key = trx['secretKey'] a = Account.from_key('0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8') _from = a.address[2:] transaction = dict(nonce=nonce, gasPrice=gas_price, gas=gas_limit, # to=to, value=value, data=data) logger.info((_from, nonce)) transaction = evm.pack_transaction(transaction) args = {'trx': transaction, 'sender': _from} ret = eosapi.push_action('helloworld11', 'raw2', args, {'helloworld11':'active'}) output = ret['processed']['action_traces'][0]['console'] logger.info(("++++logs:", output)) output = bytes.fromhex(output) output = rlp.decode(output) logs = output[2] # logger.info(logs) logs = rlp.encode(logs) h = keccak(logs) assert h.hex() == test['post']['Istanbul'][transaction_index]['logs'][2:] transaction_index += 1
def run_test(test): global g_counter global g_failed_gas_check g_counter += 1 r = eosapi.push_action('helloworld11', 'clearenv', int.to_bytes(g_counter, 4, 'little'), {'helloworld11': 'active'}) trx = test['exec'] caller = trx['caller'][2:] to = trx['address'][2:] caller_created = False for addr in test['pre']: # logger.info(addr) if caller == addr[2:]: caller_created = True info = test['pre'][addr] balance = evm.hex2int(info['balance']) balance = int.to_bytes(balance, 32, 'little') balance = balance.hex() code = info['code'][2:] nonce = evm.hex2int(info['nonce']) storage = [] for key in info['storage']: value = info['storage'][key] value = hex2int(value) key = hex2int(key) key = int.to_bytes(key, 32, 'big').hex() value = int.to_bytes(value, 32, 'big').hex() storage.append(key) storage.append(value) args = dict(address=addr[2:], nonce=nonce, balance=balance, code=code, storage=storage, counter=g_counter) # logger.info(args) ret = eosapi.push_action('helloworld11', 'setaddrinfo', args, {'helloworld11': 'active'}) output = ret['processed']['action_traces'][0]['console'] # logger.info(('++++output:', output)) # logger.info(eth.get_all_address_info()) # {'balance': '0x152d02c7e14af6800000', 'code': '0x6000600020600055', 'nonce': '0x00', 'storage': {} if not caller_created: try: #1000000000000000000 args = dict(address=caller, nonce=1, balance='00', code='', storage=[], counter=g_counter) r = eosapi.push_action('helloworld11', 'setaddrinfo', args, {'helloworld11': 'active'}) except Exception as e: logger.info(e) # "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", # "currentDifficulty" : "0x0100", # "currentGasLimit" : "0x0f4240", # "currentNumber" : "0x01", # "currentTimestamp" : "0x01" env = test['env'] value = hex2int(trx['value']) value = int.to_bytes(value, 32, 'little') value = value.hex() args = [ hex2bytes(trx['address']), hex2bytes(trx['caller']), hex2bytes(trx['origin']), hex2bytes(trx['code']), hex2bytes(trx['data']), hex2int(trx['gas']), hex2int(trx['gasPrice']), hex2int(trx['value']), hex2bytes(env['currentCoinbase']), hex2int(env['currentDifficulty']), hex2int(env['currentGasLimit']), hex2int(env['currentNumber']), hex2int(env['currentTimestamp']), config.evm_version ] data = rlp.encode(args) sender = int.to_bytes(g_counter, 4, 'little').hex() + "fffffefdfcfbfaf9f7f6f5f4f3f2f1f0" args = dict(trx=data.hex(), sender=sender) # logger.info(args) ret = eosapi.push_action('helloworld11', 'raw', args, {'helloworld11': 'active'}) output = ret['processed']['action_traces'][0]['console'] # logger.info(("++++++++console:", output)) # start = output.rfind(':') # output = output[start+1:] # logger.info(('++++elapsed:', ret['processed']['elapsed'])) try: output = bytes.fromhex(output) output = rlp.decode(output) # logger.info(output) except Exception as e: logger.error(output) raise e if 'out' in test: assert output[1].hex() == test['out'][2:], (output[1].hex(), test['out'][2:]) if 'logs' in test: if len(output) == 2: logs = [] else: logs = output[2] # logger.info(logs) logs = rlp.encode(logs) logs = keccak(logs) assert logs.hex() == test['logs'][2:], (logs, test['logs']) if 'post' in test: for addr in test['post']: post_info = test['post'][addr] post_balance = evm.hex2int(post_info['balance']) code = post_info['code'][2:] nonce = evm.hex2int(post_info['nonce']) post_storage = post_info['storage'] post_storage = convert_post_storage(post_storage) balance = eth.get_balance(addr) assert balance == post_balance, (post_balance, balance) assert code == eth.get_code(addr), (code, eth.get_code(addr)) storage = eth.get_all_values(addr) storage = convert_storage(storage) # logger.info(storage) for key in post_storage: assert key in storage, (key, storage) assert storage[key] == post_storage[key], (storage[key], post_storage[key]) #too many failture on gas checking on BYZANTIUM fork, VMTests gas depend on FRONTIER if 'gas' in test: expected_gas = hex2int(test['gas']) gas = output[3] gas = int.from_bytes(gas, 'big') if gas != expected_gas: raise GasCheckingException(dict(gas=gas, expected_gas=expected_gas))