Esempio n. 1
0
def test_compile_and_call_id():
    # Alice should be able to compile a sophia contract with an identity
    # function into bytecode and call it.
    test_settings = settings["test_compile_and_call_id"]
    (root_dir, node, api) = setup_node(test_settings, "alice")

    # Read a contract
    currentFile = __file__
    dirPath = os.path.dirname(currentFile)
    contract_file = open(dirPath + "/identity.aes", "r")
    contract_string = contract_file.read()

    # Compile contract to bytecode
    contract = Contract(contract_string, "")
    compilation_result = api.compile_contract(contract)
    assert_regexp_matches(compilation_result.bytecode, '0x.*')

    # Call contract bytecode
    call_input = ContractCallInput("sophia", compilation_result.bytecode,
                                   "main", "42")
    call_result = api.call_contract(call_input)
    assert_regexp_matches(call_result.out, '0x.*')

    # stop node
    common.stop_node(node)
    shutil.rmtree(root_dir)
Esempio n. 2
0
def read_id_contract(api):
    # Read a contract
    currentFile = __file__
    dirPath = os.path.dirname(currentFile)
    contract_file = open(dirPath + "/identity.aes", "r")
    contract_string = contract_file.read()

    # Compile contract to bytecode
    contract = Contract(contract_string, "")
    compilation_result = api.compile_contract(contract)
    assert_regexp_matches(compilation_result.bytecode, 'cb_.*')

    return compilation_result.bytecode
Esempio n. 3
0
def test_compile_id():
    # Alice should be able to compile a ring contract with an identity
    # function into hex string encoded bytecode.
    test_settings = settings["test_compile_id"]
    (root_dir, node, api) = setup_node(test_settings, "alice")

    # Read a contract
    currentFile = __file__
    dirPath = os.path.dirname(currentFile)
    contract_file = open(dirPath + "/identity.aer", "r")
    contract_string = contract_file.read()

    # Call the compile function
    contract = Contract(contract_string, "")
    result = api.compile_contract(contract)

    bytecode = '0x36600080376200002160008080805180516004146200003057505b5060011951005b60005260206000f35b80905090565b602001517f6d61696e000000000000000000000000000000000000000000000000000000001462000061576200001a565b602001519050809150506200002a56'
    assert_equals(result['bytecode'], bytecode)

    # stop node
    common.stop_node(node)
    shutil.rmtree(root_dir)