Exemplo n.º 1
0
def deploy_solidity_contract(contract_path,
                             contract_name,
                             chain,
                             sender=k0,
                             value=0,
                             startgas=STARTGAS,
                             gasprice=GASPRICE,
                             *args):
    output = subprocess.check_output(
        ["solc", "--combined-json", "bin,abi", contract_path])
    result = solc_parse_output(output)
    data = solidity_get_contract_data(result, contract_path, contract_name)

    interface = data['abi']
    ct = ContractTranslator(interface)

    code = data['bin'] \
           + (ct.encode_constructor_arguments(args) if args else b'')
    addr = chain.tx(sender=sender,
                    to=b'',
                    value=value,
                    data=code,
                    startgas=startgas,
                    gasprice=gasprice)
    return ABIContract(chain, ct, addr)
Exemplo n.º 2
0
 def compile_to_data(self, name, path):
     """Compile a solidity file and return the result data."""
     compiled = solidity.compile_file(
         path,
         combined='bin,abi,userdoc,devdoc,hashes',
         extra_args='common={} lib={} permission_management={} system={}'.
         format(self.contracts_common_dir, self.contracts_lib_dir,
                self.contracts_perm_dir, self.contracts_sys_dir))
     data = solidity.solidity_get_contract_data(compiled, path, name)
     if not data['bin']:
         sys.exit(1)
     return data
Exemplo n.º 3
0
    def compile_to_data(self, name, path):
        """Compile a solidity file and return the result data."""

        import logging

        compiled = solidity.compile_file(
            path,
            combined='bin,abi,userdoc,devdoc,hashes',
            extra_args='common={} lib={} interaction={}'.format(
                self.contracts_common_dir, self.contracts_lib_dir,
                self.contracts_interaction_dir))
        data = solidity.solidity_get_contract_data(compiled, path, name)
        if not data['bin']:
            logging.critical(
                'The bin of contract %r is empty. Please check it!', name)
            sys.exit(1)
        return data
Exemplo n.º 4
0
def init_contracts(nodes):
    result = dict()
    tester_state = Chain()
    for address, contract in CONTRACTS.iteritems():
        contract_path = path.join(CONTRACTS_DIR, contract['file'])
        simple_compiled = compile_file(contract_path)
        simple_data = solidity_get_contract_data(
            simple_compiled,
            contract_path,
            contract['name'],
        )

        ct = ContractTranslator(simple_data['abi'])
        if (address == '0x00000000000000000000000000000000013241a3'):
            extra = (ct.encode_constructor_arguments([nodes[address]]) if nodes[address] else b'')
        else:
            extra = (ct.encode_constructor_arguments([nodes[address][0], nodes[address][1]]) if nodes[address] else b'')
        print(binascii.hexlify(simple_data['bin'] + extra))
        abi_address = tester_state.contract(simple_data['bin'] + extra)
        tester_state.mine()
        account = tester_state.chain.state.account_to_dict(abi_address)
        result[address] = {'code': account['code'], 'storage': account['storage'], 'nonce': account['nonce']}
    return result
Exemplo n.º 5
0
def test_abicontract_interface():
    """ Test for issue #370. """
    tester_state = Chain()

    contract_path = path.join(CONTRACTS_DIR, 'simple_contract.sol')
    contract_name = 'Simple'
    simple_compiled = compile_file(contract_path)
    simple_data = solidity_get_contract_data(
        simple_compiled,
        contract_path,
        contract_name,
    )
    simple_address = tester_state.contract(simple_data['bin'])

    # ABIContract class must accept json_abi
    abi_json = json.dumps(simple_data['abi']).encode('utf-8')

    abi = ABIContract(
        _chain=tester_state,
        _abi=abi_json,
        address=simple_address,
    )

    assert abi.test() == 1  # pylint: disable=no-member
Exemplo n.º 6
0
#slogging.configure(':DEBUG')

# Create the simulated blockchain
tester.Chain().chain.config['BLOCK_GAS_LIMIT'] = 3141592000
tester.Chain().chain.config['START_GAS_LIMIT'] = 3141592000

s = tester.Chain()
s.mine()

contract_path = './contractNipopow.sol'
contract_name = 'Crosschain'
contract_compiled = compile_file(contract_path)

contract_data = solidity_get_contract_data(
    contract_compiled,
    contract_path,
    contract_name,
)

contract_address = s.contract(contract_data['bin'], language='evm')

contract_abi = tester.ABIContract(s, contract_data['abi'], contract_address)

import cPickle as pickle
proof = pickle.load(open('proof.pkl'))
proof_f = pickle.load(open('proof-fork50k.pkl'))
proof2 = pickle.load(open('proof-2.pkl'))
proof3 = pickle.load(open('proof-3.pkl'))
proof4 = pickle.load(open('proof-4.pkl'))

# Take a snapshot before trying out test cases
Exemplo n.º 7
0
def test_logfilters_topics(test_app):
    sample_compiled = _solidity.compile_code(
        sample_sol_code,
        combined='bin,abi',
    )

    filepath = None
    contract_data = _solidity.solidity_get_contract_data(
        sample_compiled, filepath, 'SampleContract')
    theabi = contract_data['abi']
    theevm = contract_data['bin_hex']

    sender_address = test_app.services.accounts.unlocked_accounts[0].address
    sender = address_encoder(sender_address)

    event1 = get_event(theabi, 'Event1')
    event2 = get_event(theabi, 'Event2')
    event3 = get_event(theabi, 'Event3')
    event1_id = event_id(*get_eventname_types(event1))
    event2_id = event_id(*get_eventname_types(event2))
    event3_id = event_id(*get_eventname_types(event3))

    test_app.mine_next_block()  # start with a fresh block

    n0 = test_app.services.chain.chain.head.number
    assert n0 == 1

    contract_creation = {
        'from': sender,
        'data': '0x' + theevm,
        'gas': quantity_encoder(1000000)
    }

    tx_hash = test_app.client.call('eth_sendTransaction', contract_creation)
    test_app.mine_next_block()
    receipt = test_app.client.call('eth_getTransactionReceipt', tx_hash)
    contract_address = receipt['contractAddress']

    sample_contract = ContractProxy(sender_address, theabi, contract_address,
                                    test_app.client.call,
                                    test_app.client.send_transaction)

    topic1 = hex(event1_id).rstrip("L")
    topic2 = hex(event2_id).rstrip("L")
    topic3 = hex(event3_id).rstrip("L")
    topica, topicb, topicc = \
        '0x0000000000000000000000000000000000000000000000000000000000000001',\
        '0x0000000000000000000000000000000000000000000000000000000000000064',\
        '0x00000000000000000000000000000000000000000000000000000000000003e8'
    topic_filter_1 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic1]
    })
    topic_filter_2 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic2]
    })
    topic_filter_3 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic3]
    })
    topic_filter_4 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic1, topica]
    })

    topic_filter_5 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic2, topica, topicb]
    })
    topic_filter_6 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [topic3, topica, topicb, topicc]
        })
    topic_filter_7 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topica, topicb, topicc]
    })
    topic_filter_8 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic3, topica, topicb]
    })
    topic_filter_9 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [topicc, topicb, topica, topic3]
        })
    topic_filter_10 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [topicb, topicc, topica, topic3]
        })
    topic_filter_11 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic2, topica]
    })
    topic_filter_12 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic3, topica]
    })
    topic_filter_13 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topica, topicb]
    })
    topic_filter_14 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic2, [topica, topicb]]
    })
    topic_filter_15 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [[topic1, topic2], topica]
    })
    topic_filter_16 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [[topic1, topic2, topic3]]
    })
    topic_filter_17 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [[topic1, topic2, topic3, topica, topicb, topicc]]
        })
    topic_filter_18 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [topic2, topica, topicb, [topic2, topica, topicb]]
        })
    topic_filter_19 = test_app.client.call('eth_newFilter', {
        'fromBlock': 0,
        'toBlock': 'pending',
        'topics': [topic1, topica, topicb]
    })
    topic_filter_20 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [[topic1, topic2], [topica, topicb], [topica, topicb]]
        })
    topic_filter_21 = test_app.client.call(
        'eth_newFilter', {
            'fromBlock': 0,
            'toBlock': 'pending',
            'topics': [[topic2, topic3], [topica, topicb], [topica, topicb]]
        })

    thecode = test_app.client.call('eth_getCode',
                                   address_encoder(sample_contract.address))
    assert len(thecode) > 2

    sample_contract.trigger1(1)
    test_app.mine_next_block()
    sample_contract.trigger2(100)
    test_app.mine_next_block()
    sample_contract.trigger3(1000)
    test_app.mine_next_block()

    tl1 = test_app.client.call('eth_getFilterChanges', topic_filter_1)
    assert len(tl1) == 1
    tl2 = test_app.client.call('eth_getFilterChanges', topic_filter_2)
    assert len(tl2) == 1
    tl3 = test_app.client.call('eth_getFilterChanges', topic_filter_3)
    assert len(tl3) == 1
    tl4 = test_app.client.call('eth_getFilterChanges', topic_filter_4)
    assert len(tl4) == 1
    tl5 = test_app.client.call('eth_getFilterChanges', topic_filter_5)
    assert len(tl5) == 1
    tl6 = test_app.client.call('eth_getFilterChanges', topic_filter_6)
    assert len(tl6) == 1
    tl7 = test_app.client.call('eth_getFilterChanges', topic_filter_7)
    assert len(tl7) == 0
    tl8 = test_app.client.call('eth_getFilterChanges', topic_filter_8)
    assert len(tl8) == 1
    tl9 = test_app.client.call('eth_getFilterChanges', topic_filter_9)
    assert len(tl9) == 0
    tl10 = test_app.client.call('eth_getFilterChanges', topic_filter_10)
    assert len(tl10) == 0
    tl11 = test_app.client.call('eth_getFilterChanges', topic_filter_11)
    assert len(tl11) == 1
    tl12 = test_app.client.call('eth_getFilterChanges', topic_filter_12)
    assert len(tl12) == 1
    tl13 = test_app.client.call('eth_getFilterChanges', topic_filter_13)
    assert len(tl13) == 0
    tl14 = test_app.client.call('eth_getFilterChanges', topic_filter_14)
    assert len(tl14) == 1
    tl15 = test_app.client.call('eth_getFilterChanges', topic_filter_15)
    assert len(tl15) == 2
    tl16 = test_app.client.call('eth_getFilterChanges', topic_filter_16)
    assert len(tl16) == 3
    tl17 = test_app.client.call('eth_getFilterChanges', topic_filter_17)
    assert len(tl17) == 3
    tl18 = test_app.client.call('eth_getFilterChanges', topic_filter_18)
    assert len(tl18) == 0
    tl19 = test_app.client.call('eth_getFilterChanges', topic_filter_19)
    assert len(tl19) == 0
    tl20 = test_app.client.call('eth_getFilterChanges', topic_filter_20)
    assert len(tl20) == 1
    tl21 = test_app.client.call('eth_getFilterChanges', topic_filter_21)
    assert len(tl21) == 2
Exemplo n.º 8
0
#slogging.configure(':INFO,eth.vm:INFO')
#slogging.configure(':DEBUG')

# Create the simulated blockchain
tester.Chain().chain.config['BLOCK_GAS_LIMIT'] = 31415920000
tester.Chain().chain.config['START_GAS_LIMIT'] = 31415920000

s = tester.Chain()
s.mine()

benchmark_path = './benchmark.sol'
benchmark_name = 'Benchmark'
benchmark_compiled = compile_file(benchmark_path)

benchmark_data = solidity_get_contract_data(
        benchmark_compiled,
        benchmark_path,
        benchmark_name,)

benchmark_address = s.contract(benchmark_data['bin'], language='evm')

benchmark_abi = tester.ABIContract(
    s,
    benchmark_data['abi'],
    benchmark_address)

# Take a snapshot before trying out test cases
s.mine()
base = s.snapshot()

def initialize_test():
    try: