Skip to content

Commit

Permalink
fix some send_transaction calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Jul 5, 2024
1 parent 5742d5a commit 3b57d5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
12 changes: 6 additions & 6 deletions tests/integration/test_async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
23 changes: 9 additions & 14 deletions tests/integration/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_memo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3b57d5a

Please sign in to comment.