Example #1
0
    def test_platon_replaceTransaction_gas_price_defaulting_strategy_lower(self, unlocked_account):

        node = unlocked_account['node']
        platon = Eth(node.web3)
        price = platon.gasPrice
        txn_params = {
            'from': unlocked_account['address'],
            'to': unlocked_account['address'],
            'value': 3,
            'gas': 21000,
            'gasPrice': price * 2,
            'nonce': 3000,
        }

        txn_hash = platon.sendTransaction(txn_params)

        def lower_gas_price_strategy(web3, txn):
            return price

        platon.setGasPriceStrategy(lower_gas_price_strategy)

        node.web3.eth = platon

        txn_params.pop('gasPrice')
        replace_txn_hash = platon.replaceTransaction(txn_hash, txn_params)

        replace_txn = platon.getTransaction(replace_txn_hash)

        # Strategy provices lower gas price - minimum preferred
        assert replace_txn['gasPrice'] == int(price * 2 * 1.1)
Example #2
0
    def test_platon_replaceTransaction_gas_price_defaulting_strategy_higher(self, unlocked_account):
        node = unlocked_account['node']
        platon = Eth(node.web3)
        price = platon.gasPrice

        txn_params = {
            'from': unlocked_account['address'],
            'to': UNKNOWN_ADDRESS,
            'value': 1,
            'gas': 21000,
            'gasPrice': price * 10,
            'nonce': 1000,
        }

        txn_hash = platon.sendTransaction(txn_params)

        def higher_gas_price_strategy(web3, txn):
            return price * 20

        platon.setGasPriceStrategy(higher_gas_price_strategy)
        node.web3.eth = platon

        txn_params.pop('gasPrice')

        replace_txn_hash = platon.replaceTransaction(txn_hash, txn_params)
        replace_txn = platon.getTransaction(replace_txn_hash)
        log.info(replace_txn)
        assert replace_txn['gasPrice'] == price * 20  # Strategy provides higher gas price