def test_contract_create(): test_settings = settings["test_contract_create"] (node, (root_dir, external_api, top)) = setup_node_with_tokens(test_settings, "node") internal_api = common.internal_api(node) private_key = keys.new_private() public_key = keys.public_key(private_key) alice_address = keys.address(public_key) test_settings["alice"]["pubkey"] = alice_address send_tokens_to_user("alice", test_settings, external_api, internal_api) encoded_tx, contract_address = get_unsigned_contract_create( alice_address, test_settings["create_contract"], external_api) print("Unsigned encoded transaction: " + encoded_tx) print("Contract address: " + contract_address) unsigned_tx = common.base58_decode(encoded_tx) tx = common.decode_unsigned_tx(unsigned_tx) print("Unsigned decoded transaction: " + str(tx)) # make sure same tx assert_equals(tx['type'], 'contract_create_tx') assert_equals(tx['owner'], common.base58_decode(test_settings["alice"]["pubkey"])) assert_equals(tx['vm_version'], test_settings["create_contract"]["vm_version"]) assert_equals(tx['deposit'], test_settings["create_contract"]["deposit"]) assert_equals(tx['amount'], test_settings["create_contract"]["amount"]) assert_equals(tx['gas'], test_settings["create_contract"]["gas"]) assert_equals(tx['gas_price'], test_settings["create_contract"]["gas_price"]) assert_equals(tx['fee'], test_settings["create_contract"]["fee"]) signed = keys.sign_verify_encode_tx(unsigned_tx, private_key, public_key) print("Signed transaction " + signed) alice_balance0 = common.get_account_balance(external_api, internal_api, pub_key=alice_address).balance tx_object = Tx(tx=signed) external_api.post_tx(tx_object) top = external_api.get_top_block() common.wait_until_height(external_api, top.height + 3) alice_balance = common.get_account_balance(external_api, internal_api, pub_key=alice_address).balance assert_equals( alice_balance0, alice_balance + test_settings["create_contract"]["fee"] + test_settings["create_contract"]["gas_used"] + test_settings["create_contract"]["deposit"] + test_settings["create_contract"]["amount"]) print("Fee was consumed, transaction is part of the chain") cleanup(node, root_dir)
def test_contract_create(): test_settings = settings["test_contract_create"] beneficiary = common.setup_beneficiary() (node, (root_dir, external_api, internal_api, top)) = setup_node_with_tokens(test_settings, beneficiary, "node") private_key = keys.new_private() public_key = keys.public_key(private_key) alice_address = keys.address(public_key) test_settings["alice"]["pubkey"] = alice_address send_tokens_to_user(beneficiary, "alice", test_settings, external_api, internal_api) encoded_tx, contract_id = get_unsigned_contract_create( alice_address, test_settings["create_contract"], external_api, internal_api) print("Unsigned encoded transaction: " + encoded_tx) print("Contract id: " + contract_id) unsigned_tx = common.api_decode(encoded_tx) tx = common.decode_unsigned_tx(unsigned_tx) print("Unsigned decoded transaction: " + str(tx)) # make sure same tx assert_equals(tx['type'], 'contract_create_tx') assert_equals(tx['owner_id'], common.api_decode(test_settings["alice"]["pubkey"])) assert_equals(tx['vm_version'], test_settings["create_contract"]["vm_version"]) assert_equals(tx['abi_version'], test_settings["create_contract"]["abi_version"]) assert_equals(tx['deposit'], test_settings["create_contract"]["deposit"]) assert_equals(tx['amount'], test_settings["create_contract"]["amount"]) assert_equals(tx['gas'], test_settings["create_contract"]["gas"]) assert_equals(tx['gas_price'], test_settings["create_contract"]["gas_price"]) assert_equals(tx['fee'], test_settings["create_contract"]["fee"]) signed = keys.sign_verify_encode_tx(unsigned_tx, private_key, public_key) print("Signed transaction " + signed) alice_balance0 = common.get_account_balance(external_api, alice_address) common.ensure_transaction_posted(external_api, signed) alice_balance = common.get_account_balance(external_api, alice_address) assert_equals( alice_balance0, alice_balance + test_settings["create_contract"]["fee"] + test_settings["create_contract"]["gas_used"] * test_settings["create_contract"]["gas_price"] + test_settings["create_contract"]["deposit"] + test_settings["create_contract"]["amount"]) print("Fee was consumed, transaction is part of the chain") cleanup(node, root_dir)