def test_platon_replaceTransaction_gas_price_too_low(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['gasPrice'] = 9 with pytest.raises(ValueError): platon.replaceTransaction(txn_hash, txn_params)
def test_platon_replaceTransaction_non_existing_transaction(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, } with pytest.raises(ValueError): platon.replaceTransaction( '0x98e8cc09b311583c5079fa600f6c2a3bea8611af168c52e4b60b5b243a441997', txn_params )
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)
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
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)
def test_platon_replaceTransaction_already_mined(self, unlocked_account): platon = Eth(unlocked_account['node'].web3) address = unlocked_account['address'] txn_params = { 'from': address, 'to': address, 'value': 76, 'gas': 21000, 'gasPrice': platon.gasPrice * 4, } txn_hash = platon.sendTransaction(txn_params) txn_params['gasPrice'] = platon.gasPrice * 5 platon.waitForTransactionReceipt(txn_hash) with pytest.raises(ValueError): platon.replaceTransaction(txn_hash, txn_params)
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
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']