Esempio n. 1
0
    def setUpClass(cls):
        super(TestHydra, cls).setUpClass()

        with open(ASSETS + 'ExternalDistort.sol', 'r') as fd:
            cls.external_distort = cls.s.contract(fd.read(),
                                                  language='solidity')

        equivalence_head1_path = ASSETS + 'EquivalenceHead1.sol'

        pyeth_deploy = PyEthereumHydraDeployment(cls.s,
                                                 cls.t.k0,
                                                 cls.t.a0,
                                                 META_CONTRACT,
                                                 [equivalence_head1_path],
                                                 instrument=False)
        deployed_contracts = pyeth_deploy.build_and_deploy()
        _, cls.naked_head = \
            [abi for (addr, abi) in deployed_contracts]

        pyeth_deploy = PyEthereumHydraDeployment(cls.s,
                                                 cls.t.k0,
                                                 cls.t.a0,
                                                 META_CONTRACT,
                                                 [equivalence_head1_path],
                                                 instrument=True)
        deployed_contracts = pyeth_deploy.build_and_deploy()
        cls.single_mc = deployed_contracts[0][
            1]  # deployed_contracts consists of (address, abi) tuples

        cls.single_head_address = deployed_contracts[1][0]

        pyeth_deploy = PyEthereumHydraDeployment(
            cls.s,
            cls.t.k0,
            cls.t.a0,
            META_CONTRACT, [equivalence_head1_path, equivalence_head1_path],
            instrument=True)
        deployed_contracts = pyeth_deploy.build_and_deploy()
        cls.multi_mc = deployed_contracts[0][
            1]  # deployed_contracts consists of (address, abi) tuples
        cls.multi_head1_address = deployed_contracts[1][0]
        cls.multi_head2_address = deployed_contracts[2][0]

        cls.ct = cls.naked_head.translator

        def print_address(name, address):
            print('Deployed {:25}: 0x{}'.format(name,
                                                utils.encode_hex(address)))

        print_address('ExternalDistort', cls.external_distort.address)
        print_address('Naked Head', cls.naked_head.address)
        print_address('Single Metacontract', cls.single_mc.address)
        print_address('Single Head', cls.single_head_address)
        print_address('Multi Metacontract', cls.multi_mc.address)
        print_address('Multi Head 1', cls.multi_head1_address)
        print_address('Multi Head 2', cls.multi_head2_address)

        cls.initial_state = cls.s.snapshot()
Esempio n. 2
0
def deploy_montyhall_mc(_tester, chain):
    mc_path = META_CONTRACT
    head_files = [
        PATH_TO_HEADS + 'MontyHall_florian.sol',
        PATH_TO_HEADS + 'MontyHall_florian.se',
        ]

    pyeth_deploy = PyEthereumHydraDeployment(chain, _tester.k0, _tester.a0,
                                             mc_path, head_files,
                                             instrument=True)
    deployed_contracts = pyeth_deploy.build_and_deploy()

    hydra = deployed_contracts[0][1]
    heads = [addr for (addr, abi) in deployed_contracts[1:]]

    print('MetaContract deployed at: 0x{}'.format(utils.encode_hex(hydra.address)))

    for i in range(len(heads)):
        print('Head {} deployed at: 0x{}'.format(i, utils.encode_hex(heads[i])))

    ct = get_contract_translator(head_files[0])

    for function_name in ct.function_data:
        hydra_kall = lambda _, *args, function_name=function_name, **kwargs: \
            kall(_tester, chain, ct, hydra.address, function_name, *args, **kwargs)
        function = hydra_kall
        method = types.MethodType(function, hydra)
        setattr(hydra, function_name, method)

    return hydra, heads, ct
Esempio n. 3
0
def deploy_erc20_mc(_tester, chain):
    mc_path = META_CONTRACT
    head_files = [
        PATH_TO_CONTRACTS + '/nonviper/ERC20_solidity_1.sol',
        PATH_TO_CONTRACTS + '/nonviper/ERC20_solidity_2.sol',
        PATH_TO_CONTRACTS + '/nonviper/ERC20_serpent.se',
        PATH_TO_CONTRACTS + '/ERC20.v.py'
        ]

    pyeth_deploy = PyEthereumHydraDeployment(chain,
                                             _tester.k0, _tester.a0,
                                             mc_path, head_files,
                                             instrument=True, instrumenter_path=INSTRUMENTER_PATH)
    deployed_contracts = pyeth_deploy.build_and_deploy(include_constructor=False, debug=False)

    hydra = deployed_contracts[0][1]
    heads = [addr for (addr, abi) in deployed_contracts[1:]]

    print('MetaContract deployed at: 0x{}'.format(utils.encode_hex(hydra.address)))

    for i in range(len(heads)):
        print('Head {} deployed at: 0x{}'.format(i, utils.encode_hex(heads[i])))

    ct = get_contract_translator(head_files[0])

    for function_name in ct.function_data:
        hydra_kall = lambda _, *args, function_name=function_name, **kwargs: \
            kall(_tester, chain, ct, hydra.address, function_name, *args, **kwargs)
        function = hydra_kall
        method = types.MethodType(function, hydra)
        setattr(hydra, function_name, method)

    return hydra, heads, ct
Esempio n. 4
0
    def setUpClass(cls):
        super(TestMetaContract, cls).setUpClass()

        heads = [ASSETS + 'Head1.sol', ASSETS + 'Head2.sol']

        pyeth_deploy = PyEthereumHydraDeployment(cls.s,
                                                 cls.t.k0,
                                                 cls.t.a0,
                                                 META_CONTRACT,
                                                 heads,
                                                 instrument=False)
        deployed_contracts = pyeth_deploy.build_and_deploy(value=4567)

        cls.hydra, cls.head1, cls.head2 = \
            [abi for (addr, abi) in deployed_contracts]

        cls.ct = cls.head1.translator

        with open(ASSETS + 'External.sol', 'r') as in_file:
            code_external = in_file.read()

        cls.external = cls.s.contract(code_external, language='solidity')

        print()
        print('Head1 deployed at: 0x' + utils.encode_hex(cls.head1.address))
        print('Head2 deployed at: 0x' + utils.encode_hex(cls.head2.address))
        print('MetaContract deployed at: 0x' +
              utils.encode_hex(cls.hydra.address))
        print('External contract deployed at: 0x' +
              utils.encode_hex(cls.external.address))
        print('Caller is: 0x' + utils.encode_hex(cls.t.a0))

        for function_name in cls.ct.function_data:
            hydra_kall = lambda _, *args, function_name=function_name, **kwargs: \
                kall(cls.t, cls.s, cls.ct, cls.hydra.address, function_name, *args, **kwargs)
            function = hydra_kall
            method = types.MethodType(function, cls.hydra)
            setattr(cls.hydra, function_name, method)

        cls.initial_state = cls.s.snapshot()