Example #1
0
def test_contract_on_chain_call_off_chain():
    test_settings = settings["test_contract_call"]
    create_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)

    ## create contract
    encoded_tx, encoded_contract_id = get_unsigned_contract_create(alice_address, create_settings["create_contract"], external_api, internal_api)
    unsigned_tx = common.api_decode(encoded_tx)

    signed = keys.sign_verify_encode_tx(unsigned_tx, private_key, public_key)
    common.ensure_transaction_posted(external_api, signed)

    call_contract = test_settings["contract_call"]
    call_input = ContractCallInput("sophia-address", encoded_contract_id,\
                                   call_contract["data"]["function"],\
                                   call_contract["data"]["argument"])
    result = internal_api.call_contract(call_input)

    assert_equals(common.hexstring_to_contract_bytearray('0x000000000000000000000000000000000000000000000000000000000000002a'),
                   result.out)

    cleanup(node, root_dir)
Example #2
0
def test_solidity_greeter():
    # Alice should be able to initialize
    # the gretee Solidity contract.

    test_settings = settings["test_id_call"]
    (root_dir, node, api, internal_api) = setup_node(test_settings, "alice")

    bytecode = greeter_code()

    call_input = ContractCallInput(
        "evm", bytecode, "", common.hexstring_to_contract_bytearray("0x00"))
    result = internal_api.call_contract(call_input)
    print(result)

    generatedcode = greeter_generated_code()

    assert_equals(result.out, generatedcode)
    # stop node
    common.stop_node(node)
    shutil.rmtree(root_dir)
Example #3
0
def test_id_call():
    # Alice should be able to call the id function in
    # an Id contract.

    test_settings = settings["test_id_call"]
    (root_dir, node, external_api,
     internal_api) = setup_node(test_settings, "alice")

    bytecode = read_id_contract(internal_api)

    call_input = ContractCallInput("sophia", bytecode, "main", "42")
    result = internal_api.call_contract(call_input)
    print(result)

    retval = common.hexstring_to_contract_bytearray(
        '0x000000000000000000000000000000000000000000000000000000000000002a')
    assert_equals(result.out, retval)
    # stop node
    common.stop_node(node)
    shutil.rmtree(root_dir)
Example #4
0
def test_call_solidity_greeter():
    # Alice should be able to call the greet function in
    # an greete Solidity contract.

    test_settings = settings["test_id_call"]
    (root_dir, node, api, internal_api) = setup_node(test_settings, "alice")

    bytecode = greeter_generated_code()

    setGreeting = "0xa4136862"
    HelloWorld = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6c6f20576f726c642100000000000000000000000000000000000000"
    call_input = ContractCallInput(
        "evm", bytecode, "",
        common.hexstring_to_contract_bytearray(setGreeting + HelloWorld))
    result = internal_api.call_contract(call_input)
    print(result)

    generatedcode = greeter_generated_code()

    # assert_equals(result.out, generatedcode)
    # stop node
    common.stop_node(node)
    shutil.rmtree(root_dir)
Example #5
0
def greeter_generated_code():
    return common.hexstring_to_contract_bytearray(
        "0x606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b51461006757806342cbb15c1461007c578063a4136862146100a5578063cfae321714610102575b600080fd5b341561007257600080fd5b61007a610190565b005b341561008757600080fd5b61008f610221565b6040518082815260200191505060405180910390f35b34156100b057600080fd5b610100600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610229565b005b341561010d57600080fd5b610115610243565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561015557808201518184015260208101905061013a565b50505050905090810190601f1680156101825780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561021f576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b565b600043905090565b806001908051906020019061023f9291906102eb565b5050565b61024b61036b565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e15780601f106102b6576101008083540402835291602001916102e1565b820191906000526020600020905b8154815290600101906020018083116102c457829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061032c57805160ff191683800117855561035a565b8280016001018555821561035a579182015b8281111561035957825182559160200191906001019061033e565b5b509050610367919061037f565b5090565b602060405190810160405280600081525090565b6103a191905b8082111561039d576000816000905550600101610385565b5090565b905600a165627a7a7230582044f3995b80d8c9db924a58848a42198252c1f6e73a6a4423329b9641955a02dc0029"
    )