def test_build_transaction_with_contract_fallback_function(
        web3, fallback_function_contract):
    txn = fallback_function_contract.fallback.buildTransaction()
    assert dissoc(txn, 'gas') == {
        'to': fallback_function_contract.address,
        'data': '0x',
        'value': 0,
        'gasPrice': 1,
        'chainId': None,
    }
def test_build_transaction_not_paying_to_nonpayable_function(
        web3, payable_tester_contract, buildTransaction):
    txn = buildTransaction(contract=payable_tester_contract,
                           contract_function='doNoValueCall')
    assert dissoc(txn, 'gas') == {
        'to': payable_tester_contract.address,
        'data': '0xe4cb8f5c',
        'value': 0,
        'gasPrice': 1,
        'chainId': None,
    }
def test_build_transaction_with_contract_no_arguments(web3, math_contract,
                                                      buildTransaction):
    txn = buildTransaction(contract=math_contract,
                           contract_function='increment')
    assert dissoc(txn, 'gas') == {
        'to': math_contract.address,
        'data': '0xd09de08a',
        'value': 0,
        'gasPrice': 1,
        'chainId': None,
    }
def test_build_transaction_with_contract_class_method(web3, MathContract,
                                                      math_contract,
                                                      buildTransaction):
    txn = buildTransaction(
        contract=MathContract,
        contract_function='increment',
        tx_params={'to': math_contract.address},
    )
    assert dissoc(txn, 'gas') == {
        'to': math_contract.address,
        'data': '0xd09de08a',
        'value': 0,
        'gasPrice': 1,
        'chainId': None,
    }
def test_build_transaction_with_gas_price_strategy_set(web3, math_contract,
                                                       buildTransaction):
    def my_gas_price_strategy(web3, transaction_params):
        return 5

    web3.eth.setGasPriceStrategy(my_gas_price_strategy)
    txn = buildTransaction(contract=math_contract,
                           contract_function='increment')
    assert dissoc(txn, 'gas') == {
        'to': math_contract.address,
        'data': '0xd09de08a',
        'value': 0,
        'gasPrice': 5,
        'chainId': None,
    }
def test_eth_account_sign_transaction_from_eth_test(acct, transaction_info):
    expected_raw_txn = transaction_info['signed']
    key = transaction_info['key']

    transaction = dissoc(transaction_info, 'signed', 'key', 'unsigned')

    # validate r, in order to validate the transaction hash
    # There is some ambiguity about whether `r` will always be deterministically
    # generated from the transaction hash and private key, mostly due to code
    # author's ignorance. The example test fixtures and implementations seem to agree, so far.
    # See ecdsa_raw_sign() in /eth_keys/backends/native/ecdsa.py
    signed = acct.signTransaction(transaction, key)
    assert signed.r == Web3.toInt(hexstr=expected_raw_txn[-130:-66])

    # confirm that signed transaction can be recovered to the sender
    expected_sender = acct.privateKeyToAccount(key).address
    assert acct.recoverTransaction(signed.rawTransaction) == expected_sender
def test_build_transaction_with_contract_with_arguments(
        web3, skip_if_testrpc, math_contract, transaction_args, method_args,
        method_kwargs, expected, skip_testrpc, buildTransaction):
    if skip_testrpc:
        skip_if_testrpc(web3)

    txn = buildTransaction(contract=math_contract,
                           contract_function='increment',
                           func_args=method_args,
                           func_kwargs=method_kwargs,
                           tx_params=transaction_args)
    expected['to'] = math_contract.address
    assert txn is not None
    if 'gas' in transaction_args:
        assert txn['gas'] == transaction_args['gas']
    else:
        assert 'gas' in txn
    assert dissoc(txn, 'gas') == expected
Beispiel #8
0
    def middleware(method, params):
        result = make_request(method, params)

        # As of v1.8, Geth returns errors when you request a
        # receipt for a transaction that is not in the chain.
        # It used to return a result of None, so we simulate the old behavior.

        if method == 'eth_getTransactionReceipt' and 'error' in result:
            is_geth = web3.version.node.startswith('Geth')
            if is_geth and result['error']['code'] == -32000:
                return assoc(
                    dissoc(result, 'error'),
                    'result',
                    None,
                )
            else:
                return result
        else:
            return result
Beispiel #9
0
def transaction_normalizer(transaction):
    return dissoc(transaction, 'chainId')
def remove_key_if(key, remove_if, input_dict):
    if key in input_dict and remove_if(input_dict):
        return dissoc(input_dict, key)
    else:
        return input_dict