From 3b57d5ab898c28b2549063cf8b974ee65e6f7214 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Fri, 5 Jul 2024 15:48:06 +0400 Subject: [PATCH] fix some send_transaction calls --- tests/integration/test_async_http_client.py | 12 +++++------ tests/integration/test_http_client.py | 23 ++++++++------------- tests/integration/test_memo.py | 2 +- tests/integration/test_websockets.py | 2 +- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/integration/test_async_http_client.py b/tests/integration/test_async_http_client.py index 4c80634f..355e6d4b 100644 --- a/tests/integration/test_async_http_client.py +++ b/tests/integration/test_async_http_client.py @@ -78,7 +78,7 @@ async def test_send_transaction_and_get_balance( blockhash = (await test_http_client_async.get_latest_blockhash()).value.blockhash msg = Message.new_with_blockhash(ixs, async_stubbed_sender.pubkey(), blockhash) transfer_tx = Transaction([async_stubbed_sender], msg, blockhash) - resp = await test_http_client_async.send_transaction(transfer_tx, async_stubbed_sender) + resp = await test_http_client_async.send_transaction(transfer_tx) assert_valid_response(resp) # Confirm transaction await test_http_client_async.confirm_transaction(resp.value) @@ -146,7 +146,7 @@ async def test_send_bad_transaction(stubbed_receiver: Pubkey, test_http_client_a msg = Message.new_with_blockhash(ixs, poor_account.pubkey(), blockhash) transfer_tx = Transaction([poor_account], msg, blockhash) with pytest.raises(RPCException) as exc_info: - await test_http_client_async.send_transaction(transfer_tx, poor_account) + await test_http_client_async.send_transaction(transfer_tx) err = exc_info.value.args[0] assert isinstance(err, SendTransactionPreflightFailureMessage) assert err.data.logs @@ -170,7 +170,7 @@ async def test_send_transaction_prefetched_blockhash( ] msg = Message.new_with_blockhash(ixs, async_stubbed_sender_prefetched_blockhash.pubkey(), blockhash) transfer_tx = Transaction([async_stubbed_sender_prefetched_blockhash], msg, blockhash) - resp = await test_http_client_async.send_transaction(transfer_tx, async_stubbed_sender_prefetched_blockhash) + resp = await test_http_client_async.send_transaction(transfer_tx) assert_valid_response(resp) # Confirm transaction await test_http_client_async.confirm_transaction(resp.value) @@ -207,7 +207,7 @@ async def test_send_raw_transaction_and_get_balance( # Sign transaction transfer_tx.sign(async_stubbed_sender) # Send raw transaction - resp = await test_http_client_async.send_raw_transaction(transfer_tx.serialize()) + resp = await test_http_client_async.send_raw_transaction(bytes(transfer_tx)) assert_valid_response(resp) # Confirm transaction resp = await test_http_client_async.confirm_transaction(resp.value) @@ -246,7 +246,7 @@ async def test_send_raw_transaction_and_get_balance_using_latest_blockheight( transfer_tx.sign(async_stubbed_sender) # Send raw transaction resp = await test_http_client_async.send_raw_transaction( - transfer_tx.serialize(), + bytes(transfer_tx), opts=TxOpts(preflight_commitment=Processed, last_valid_block_height=last_valid_block_height), ) assert_valid_response(resp) @@ -280,7 +280,7 @@ async def test_confirm_expired_transaction(stubbed_sender, stubbed_receiver, tes transfer_tx.sign(stubbed_sender) # Send raw transaction resp = await test_http_client_async.send_raw_transaction( - transfer_tx.serialize(), opts=TxOpts(skip_confirmation=True, skip_preflight=True) + bytes(transfer_tx), opts=TxOpts(skip_confirmation=True, skip_preflight=True) ) assert_valid_response(resp) # Confirm transaction diff --git a/tests/integration/test_http_client.py b/tests/integration/test_http_client.py index b6bdf299..eabd38de 100644 --- a/tests/integration/test_http_client.py +++ b/tests/integration/test_http_client.py @@ -70,7 +70,7 @@ def test_send_transaction_and_get_balance(stubbed_sender, stubbed_receiver, test transfer_tx = Transaction([stubbed_sender], msg, blockhash) sim_resp = test_http_client.simulate_transaction(transfer_tx) assert_valid_response(sim_resp) - resp = test_http_client.send_transaction(transfer_tx, stubbed_sender) + resp = test_http_client.send_transaction(transfer_tx) assert_valid_response(resp) # Confirm transaction test_http_client.confirm_transaction(resp.value) @@ -134,7 +134,7 @@ def test_send_bad_transaction(stubbed_receiver: Pubkey, test_http_client: Client msg = Message.new_with_blockhash(ixs, poor_account.pubkey(), blockhash) transfer_tx = Transaction([poor_account], msg, blockhash) with pytest.raises(RPCException) as exc_info: - test_http_client.send_transaction(transfer_tx, poor_account) + test_http_client.send_transaction(transfer_tx) err = exc_info.value.args[0] assert isinstance(err, SendTransactionPreflightFailureMessage) assert err.data.logs @@ -146,7 +146,7 @@ def test_send_transaction_prefetched_blockhash( ): """Test sending a transaction to localnet.""" # Create transfer tx to transfer lamports from stubbed sender to stubbed_receiver - blockhash = test_http_client.get_latest_blockhash().value.blockhash + recent_blockhash = test_http_client.parse_recent_blockhash(test_http_client.get_latest_blockhash()) ixs = [ sp.transfer( sp.TransferParams( @@ -156,12 +156,9 @@ def test_send_transaction_prefetched_blockhash( ) ) ] - msg = Message.new_with_blockhash(ixs, stubbed_sender_prefetched_blockhash.pubkey(), blockhash) - transfer_tx = Transaction([stubbed_sender_prefetched_blockhash], msg, blockhash) - recent_blockhash = test_http_client.parse_recent_blockhash(test_http_client.get_latest_blockhash()) - resp = test_http_client.send_transaction( - transfer_tx, stubbed_sender_prefetched_blockhash, recent_blockhash=recent_blockhash - ) + msg = Message.new_with_blockhash(ixs, stubbed_sender_prefetched_blockhash.pubkey(), recent_blockhash) + transfer_tx = Transaction([stubbed_sender_prefetched_blockhash], msg, recent_blockhash) + resp = test_http_client.send_transaction(transfer_tx) assert_valid_response(resp) # Confirm transaction test_http_client.confirm_transaction(resp.value) @@ -192,7 +189,7 @@ def test_send_raw_transaction_and_get_balance(stubbed_sender, stubbed_receiver, # Sign transaction transfer_tx.sign(stubbed_sender) # Send raw transaction - tx_resp = test_http_client.send_raw_transaction(transfer_tx.serialize()) + tx_resp = test_http_client.send_raw_transaction(bytes(transfer_tx)) assert_valid_response(tx_resp) # Confirm transaction test_http_client.confirm_transaction(tx_resp.value) @@ -227,7 +224,7 @@ def test_send_raw_transaction_and_get_balance_using_latest_blockheight( transfer_tx.sign(stubbed_sender) # Send raw transaction resp = test_http_client.send_raw_transaction( - transfer_tx.serialize(), + bytes(transfer_tx), opts=TxOpts(preflight_commitment=Processed, last_valid_block_height=last_valid_block_height), ) assert_valid_response(resp) @@ -256,11 +253,9 @@ def test_confirm_expired_transaction(stubbed_sender, stubbed_receiver, test_http ] msg = Message.new_with_blockhash(ixs, stubbed_sender.pubkey(), recent_blockhash) transfer_tx = Transaction([stubbed_sender], msg, recent_blockhash) - # Sign transaction - transfer_tx.sign(stubbed_sender) # Send raw transaction tx_resp = test_http_client.send_raw_transaction( - transfer_tx.serialize(), opts=TxOpts(skip_confirmation=True, skip_preflight=True) + bytes(transfer_tx), opts=TxOpts(skip_confirmation=True, skip_preflight=True) ) assert_valid_response(tx_resp) # Confirm transaction diff --git a/tests/integration/test_memo.py b/tests/integration/test_memo.py index 40f8c00e..2eabbc77 100644 --- a/tests/integration/test_memo.py +++ b/tests/integration/test_memo.py @@ -32,7 +32,7 @@ def test_send_memo_in_transaction(stubbed_sender: Keypair, test_http_client: Cli ixs = [create_memo(memo_params)] msg = Message.new_with_blockhash(ixs, stubbed_sender.pubkey(), blockhash) transfer_tx = Transaction([stubbed_sender], msg, blockhash) - resp = test_http_client.send_transaction(transfer_tx, stubbed_sender) + resp = test_http_client.send_transaction(transfer_tx) assert_valid_response(resp) txn_id = resp.value # Txn needs to be finalized in order to parse the logs. diff --git a/tests/integration/test_websockets.py b/tests/integration/test_websockets.py index 4e9d076f..367e08e7 100644 --- a/tests/integration/test_websockets.py +++ b/tests/integration/test_websockets.py @@ -288,7 +288,7 @@ async def test_program_subscribe( blockhash = (test_http_client_async.get_latest_blockhash()).value.blockhash msg = Message.new_with_blockhash(ixs, owned.pubkey(), blockhash) transaction = Transaction([owned], msg, blockhash) - await test_http_client_async.send_transaction(transaction, owned) + await test_http_client_async.send_transaction(transaction) main_resp = await websocket.recv() msg = main_resp[0] assert isinstance(msg, ProgramNotification)