Ejemplo n.º 1
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
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_platon_replaceTransaction_incorrect_nonce(self, unlocked_account):
        platon = Eth(unlocked_account['node'].web3)
        address = unlocked_account['address']
        txn_params = {
            'from': address,
            'to': address,
            'value': 1,
            'gas': 21000,
            'gasPrice': platon.gasPrice,
        }
        txn_hash = platon.sendTransaction(txn_params)
        txn = platon.getTransaction(txn_hash)

        txn_params['gasPrice'] = platon.gasPrice * 2
        txn_params['nonce'] = int(txn['nonce'], 16) + 1
        with pytest.raises(ValueError):
            platon.replaceTransaction(txn_hash, txn_params)
Ejemplo n.º 4
0
    def test_platon_replaceTransaction_gas_price_defaulting_minimum(self, unlocked_account):
        platon = Eth(unlocked_account['node'].web3)
        address = unlocked_account['address']
        txn_params = {
            'from': address,
            'to': address,
            'value': 1,
            'gas': 21000,
            'gasPrice': platon.gasPrice,
        }
        txn_hash = platon.sendTransaction(txn_params)

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

        # todo minimum gas price is what
        assert replace_txn['gasPrice'] == 110000000
Ejemplo n.º 5
0
    def test_platon_sendTransaction(self, unlocked_account):

        platon = Eth(unlocked_account['node'].web3)

        txn_params = {
            'from': unlocked_account['address'],
            'to': unlocked_account['address'],
            'value': 1,
            'gas': 21000,
            'gasPrice': platon.gasPrice,
        }
        txn_hash = platon.sendTransaction(txn_params)
        txn = platon.getTransaction(txn_hash)

        assert is_same_address(txn['from'], txn_params['from'])
        assert is_same_address(txn['to'], txn_params['to'])
        assert txn['value'] == 1
        assert txn['gas'] == 21000
        assert txn['gasPrice'] == txn_params['gasPrice']
Ejemplo n.º 6
0
    def test_platon_replaceTransaction(self, unlocked_account):
        platon = Eth(unlocked_account['node'].web3)
        txn_params = {
            'from': unlocked_account['address'],
            'to': unlocked_account['address'],
            'value': 3,
            'gas': 21000,
            'gasPrice': platon.gasPrice,
            'nonce': 1000,
        }
        txn_hash = platon.sendTransaction(txn_params)
        txn_params['gasPrice'] = platon.gasPrice * 2
        replace_txn_hash = platon.replaceTransaction(txn_hash, txn_params)
        replace_txn = platon.getTransaction(replace_txn_hash)

        assert is_same_address(replace_txn['from'], txn_params['from'])
        assert is_same_address(replace_txn['to'], txn_params['to'])
        assert replace_txn['value'] == 3
        assert replace_txn['gas'] == 21000
        assert replace_txn['gasPrice'] == txn_params['gasPrice']
Ejemplo n.º 7
0
    def test_platon_sendTransaction_with_nonce(self, unlocked_account):

        platon = Eth(unlocked_account['node'].web3)
        txn_params = {
            'from': unlocked_account['address'],
            'to': unlocked_account['address'],
            'value': 1,
            'gas': 21000,
            # Increased gas price to ensure transaction hash different from other tests
            'gasPrice': platon.gasPrice * 2,
            'nonce': platon.getTransactionCount(unlocked_account['address']),
        }
        txn_hash = platon.sendTransaction(txn_params)
        txn = platon.getTransaction(txn_hash)

        assert is_same_address(txn['from'], txn_params['from'])
        assert is_same_address(txn['to'], txn_params['to'])
        assert txn['value'] == 1
        assert txn['gas'] == 21000
        assert txn['gasPrice'] == txn_params['gasPrice']