def compute_state_test_unit(state, txdata, indices, konfig): state.env.config = konfig s = state.snapshot() try: # Create the transaction tx = transactions.Transaction( nonce=parse_int_or_hex(txdata['nonce'] or b"0"), gasprice=parse_int_or_hex(txdata['gasPrice'] or b"0"), startgas=parse_int_or_hex(txdata['gasLimit'][indices["gas"]] or b"0"), to=decode_hex(remove_0x_head(txdata['to'])), value=parse_int_or_hex(txdata['value'][indices["value"]] or b"0"), data=decode_hex(remove_0x_head(txdata['data'][indices["data"]]))) if 'secretKey' in txdata: tx.sign(decode_hex(remove_0x_head(txdata['secretKey']))) else: tx.v = parse_int_or_hex(txdata['v']) # Run it prev = state.to_dict() success, output = apply_transaction(state, tx) print("Applied tx") except InvalidTransaction as e: print("Exception: %r" % e) success, output = False, b'' # state.set_code('0x3e180b1862f9d158abb5e519a6d8605540c23682', b'') state.commit() post = state.to_dict() # print('pozt', post) output_decl = { "hash": '0x' + encode_hex(state.trie.root_hash), "indexes": indices, "diff": mk_state_diff(prev, post) } state.revert(s) return output_decl
def apply_message(state, msg=None, **kwargs): if msg is None: msg = vm.Message(**kwargs) else: assert not kwargs ext = VMExt(state, transactions.Transaction(0, 0, 21000, b"", 0, b"")) result, gas_remained, data = apply_msg(ext, msg) return bytearray_to_bytestr(data) if result else None
def compute_state_test_unit(state, txdata, indices, konfig, is_qkc_state, qkc_env=None): state.env.config = konfig s = state.snapshot() if "transferTokenId" in txdata: transfer_token_id = parse_int_or_hex( txdata["transferTokenId"][indices["transferTokenId"]]) else: transfer_token_id = token_id_encode("QKC") try: # Create the transaction tx = transactions.Transaction( nonce=parse_int_or_hex(txdata["nonce"] or b"0"), gasprice=parse_int_or_hex(txdata["gasPrice"] or b"0"), startgas=parse_int_or_hex(txdata["gasLimit"][indices["gas"]] or b"0"), to=decode_hex(remove_0x_head(txdata["to"])), value=parse_int_or_hex(txdata["value"][indices["value"]] or b"0"), data=decode_hex(remove_0x_head(txdata["data"][indices["data"]])), gas_token_id=token_id_encode("QKC"), transfer_token_id=transfer_token_id, # Should not set testing flag if testing QuarkChain state is_testing=not is_qkc_state, ) tx.set_quark_chain_config(qkc_env.quark_chain_config) if "secretKey" in txdata: tx.sign(decode_hex(remove_0x_head(txdata["secretKey"]))) else: tx._in_mutable_context = True tx.v = parse_int_or_hex(txdata["v"]) tx._in_mutable_context = False # Run it prev = state.to_dict() success, output = apply_transaction(state, tx, tx_wrapper_hash=bytes(32)) except InvalidTransaction as e: print("Exception: %r" % e) success, output = False, b"" # touch coinbase, make behavior consistent with go-ethereum state.delta_token_balance(state.block_coinbase, token_id_encode("QKC"), 0) state.commit() post = state.to_dict() output_decl = { "hash": "0x" + encode_hex(state.trie.root_hash), "indexes": indices, "diff": mk_state_diff(prev, post), } state.revert(s) return output_decl