コード例 #1
0
def test_prepare_transaction_replacement_nonce_mismatch_raises(web3):
    with pytest.raises(ValueError):
        prepare_replacement_transaction(web3, {
            'blockHash': None,
            'hash': '0x0',
            'nonce': 1,
        }, {
            'nonce': 2,
        })
コード例 #2
0
def test_prepare_transaction_replacement_not_higher_gas_price_raises(web3):
    current_transaction = SIMPLE_CURRENT_TRANSACTION
    new_transaction = {
        'value': 1,
        'gasPrice': 5,
    }
    with pytest.raises(ValueError):
        prepare_replacement_transaction(
            web3, current_transaction, new_transaction)

    # Also raises when equal to the current transaction
    new_transaction['gasPrice'] = 10
    with pytest.raises(ValueError):
        prepare_replacement_transaction(web3, current_transaction, new_transaction)
コード例 #3
0
def test_prepare_transaction_replacement_gas_price_defaulting(web3):
    current_transaction = SIMPLE_CURRENT_TRANSACTION
    new_transaction = {
        'value': 2,
    }
    replacement_transaction = prepare_replacement_transaction(
        web3, current_transaction, new_transaction)

    assert replacement_transaction['gasPrice'] == 11
コード例 #4
0
def test_prepare_transaction_replacement_without_nonce_sets_correct_nonce(web3):
    current_transaction = SIMPLE_CURRENT_TRANSACTION
    new_transaction = {
        'value': 1,
    }
    replacement_transaction = prepare_replacement_transaction(
        web3, current_transaction, new_transaction)
    assert replacement_transaction == {
        'value': 1,
        'nonce': 2,
        'gasPrice': 11,
    }
コード例 #5
0
def test_prepare_transaction_replacement(w3):
    current_transaction = SIMPLE_CURRENT_TRANSACTION
    new_transaction = {
        'value': 1,
        'nonce': 2,
    }
    replacement_transaction = prepare_replacement_transaction(
        w3, current_transaction, new_transaction)

    assert replacement_transaction == {
        'value': 1,
        'nonce': 2,
        'gasPrice': 12,
    }
コード例 #6
0
def test_prepare_transaction_replacement_gas_price_defaulting_when_strategy_higer(web3):

    def higher_gas_price_strategy(web3, txn):
        return 20

    web3.eth.setGasPriceStrategy(higher_gas_price_strategy)

    current_transaction = SIMPLE_CURRENT_TRANSACTION
    new_transaction = {
        'value': 2,
    }

    replacement_transaction = prepare_replacement_transaction(
        web3, current_transaction, new_transaction)

    assert replacement_transaction['gasPrice'] == 20
コード例 #7
0
def test_prepare_transaction_replacement_gas_price_defaulting_when_strategy_lower(
        w3):
    def lower_gas_price_strategy(w3, txn):
        return 5

    w3.eth.set_gas_price_strategy(lower_gas_price_strategy)

    current_transaction = SIMPLE_CURRENT_TRANSACTION
    new_transaction = {
        'value': 2,
    }

    replacement_transaction = prepare_replacement_transaction(
        w3, current_transaction, new_transaction)

    assert replacement_transaction['gasPrice'] == 12
コード例 #8
0
def test_prepare_transaction_replacement_already_mined_raises(web3):
    with pytest.raises(ValueError):
        prepare_replacement_transaction(
            web3, {'blockHash': '0xa1a1a1', 'hash': '0x0'}, {'value': 2})