def test_platon_sendTransaction_withWrongAddress(self, unlocked_account): platon = Eth(unlocked_account['node'].web3) txn_params = { 'from': UNKNOWN_ADDRESS, 'to': unlocked_account['address'], 'value': 1, 'gas': 21000, 'gasPrice': platon.gasPrice, } with pytest.raises(ValueError): platon.sendTransaction(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_sendTransaction_addr_checksum_required(self, unlocked_account): platon = Eth(unlocked_account['node'].web3) address = unlocked_account['address'].lower() txn_params = { 'from': address, 'to': address, 'value': 1, 'gas': 21000, 'gasPrice': platon.gasPrice, } with pytest.raises(InvalidAddress): invalid_params = dict(txn_params, **{'from': UNKNOWN_ADDRESS}) platon.sendTransaction(invalid_params) with pytest.raises(InvalidAddress): invalid_params = dict(txn_params, **{'to': UNKNOWN_ADDRESS}) platon.sendTransaction(invalid_params)
def test_platon_getTransactionReceipt_unmined(self, unlocked_account): platon = Eth(unlocked_account['node'].web3) txn_hash = platon.sendTransaction({ 'from': unlocked_account['address'], 'to': unlocked_account['address'], 'value': 1, 'gas': 21000, 'gasPrice': platon.gasPrice, }) receipt = platon.getTransactionReceipt(txn_hash) assert receipt is None
def test_platon_estimateGas_low(self, unlocked_account): node = unlocked_account['node'] platon = Eth(node.web3) gas_estimate = platon.estimateGas({ 'from': unlocked_account['address'], 'to': unlocked_account['address'], 'value': 1, }) assert is_integer(gas_estimate) assert gas_estimate > 0 status = True try: platon.sendTransaction({ 'from': unlocked_account['address'], 'to': unlocked_account['address'], 'value': 1, 'gas': gas_estimate - 2000, }) status = False except BaseException: ... assert status
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_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_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']
def test_platon_estimateGas_high(self, unlocked_account): node = unlocked_account['node'] platon = Eth(node.web3) gas_estimate = platon.estimateGas({ 'from': unlocked_account['address'], 'to': unlocked_account['address'], 'value': 1, }) assert is_integer(gas_estimate) assert gas_estimate > 0 hash = platon.sendTransaction({ 'from': unlocked_account['address'], 'to': unlocked_account['address'], 'value': 1, 'gas': gas_estimate + 2000, }) res = platon.waitForTransactionReceipt(hash) assert res['blockNumber'] != 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']
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']