Skip to content

Commit 4799c1a

Browse files
authored
Merge pull request #161 from kevinheavey/remove-old-transaction
2 parents 35d275d + 0a346dc commit 4799c1a

File tree

11 files changed

+31
-141
lines changed

11 files changed

+31
-141
lines changed

docs/clientgen/index.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ This will generate code to `./my_client`:
7777
### Instructions
7878

7979
```python
80-
from solana.transaction import Transaction
80+
from solders.hash import Hash
8181
from solders.keypair import Keypair
82+
from solders.message import Message
8283
from solders.pubkey import Pubkey
84+
from solders.transaction import Transaction
8385
from anchorpy import Provider
8486
from my_client.instructions import some_instruction
8587

8688
# call an instruction
8789
foo_account = Keypair()
90+
# in real use, fetch this from an RPC
91+
recent_blockhash = Hash.default()
8892

8993
ix = some_instruction({
9094
"foo_param": "...",
@@ -95,11 +99,12 @@ ix = some_instruction({
9599
"bar_account": Pubkey("..."),
96100
...
97101
})
98-
tx = Transaction().add(ix)
102+
msg = Message(instructions=[instruction], payer=payer.pubkey())
103+
tx = Transaction([payer], msg, recent_blockhash)
99104

100105
provider = Provider.local()
101106

102-
await provider.send(tx, [payer, foo_account])
107+
await provider.send(tx)
103108
```
104109

105110
### Accounts

docs/dynamic_client/api_reference.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
:::anchorpy.Context
77
:::anchorpy.create_workspace
88
:::anchorpy.close_workspace
9-
:::anchorpy.bankrun_fixture
109
:::anchorpy.workspace_fixture
1110
:::anchorpy.localnet_fixture
1211
:::anchorpy.Wallet

docs/testing/index.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,3 @@ Then run `anchor test` and voila!.
185185

186186
!!! note
187187
You must have `pytest-asyncio` installed for `test_basic_1.py` to work.
188-
189-
## Bankrun Integration
190-
191-
AnchorPy comes with a `bankrun_fixture` to help use
192-
[`solders.bankrun`](https://kevinheavey.github.io/solders/examples/bankrun.html) in tests.
193-
194-
If you haven't heard, `bankrun` is a much faster and more convenient alternative to
195-
`solana-test-validator`. Long test suites are about 40 times faster with `bankrun`,
196-
and for short test suites the difference is even bigger because `bankrun` has neglible
197-
startup time.
198-
199-
`bankrun_fixture` calls `bankrun.start()` and deploys all the programs in the current
200-
Anchor workspace to the test envioronment.
201-
Check out [this example](https://github.com/kevinheavey/anchorpy/blob/main/tests/test_basic_3_bankrun.py).
202-

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires-python = "~=3.9"
77
readme = "README.md"
88
dependencies = [
99
"construct-typing>=0.5.1,<0.6",
10-
"solana>=0.33.0,<1.0",
10+
"solana>=0.36.1,<1.0",
1111
"solders>=0.21.0,<1.0",
1212
"borsh-construct>=0.1.0,<0.2",
1313
"toolz>=0.11.2,<0.12",

src/anchorpy/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
__has_pytest = False
2424
with __suppress(ImportError):
2525
from anchorpy.pytest_plugin import (
26-
bankrun_fixture,
2726
localnet_fixture,
2827
workspace_fixture,
2928
)
@@ -59,7 +58,6 @@
5958
__all__ = (
6059
[
6160
*__all_core,
62-
"bankrun_fixture",
6361
"localnet_fixture",
6462
"workspace_fixture",
6563
]

src/anchorpy/program/namespace/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from construct import Container
88
from solana.rpc.commitment import Commitment
99
from solana.rpc.types import MemcmpOpts
10-
from solana.transaction import Instruction
10+
from solders.instruction import Instruction
1111
from solders.keypair import Keypair
1212
from solders.pubkey import Pubkey
1313
from solders.system_program import CreateAccountParams, create_account

src/anchorpy/provider.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
from solana.rpc import types
1111
from solana.rpc.async_api import AsyncClient
1212
from solana.rpc.commitment import Confirmed, Finalized, Processed
13-
from solana.transaction import Transaction
1413
from solders.keypair import Keypair
1514
from solders.pubkey import Pubkey
1615
from solders.rpc.responses import SimulateTransactionResp
1716
from solders.signature import Signature
18-
from solders.transaction import VersionedTransaction
17+
from solders.transaction import Transaction, VersionedTransaction
1918

2019
DEFAULT_OPTIONS = types.TxOpts(skip_confirmation=False, preflight_commitment=Processed)
2120
COMMITMENT_RANKS = MappingProxyType({Processed: 0, Confirmed: 1, Finalized: 2})
@@ -118,7 +117,7 @@ async def send(
118117
"""
119118
if opts is None:
120119
opts = self.opts
121-
raw = tx.serialize() if isinstance(tx, Transaction) else bytes(tx)
120+
raw = bytes(tx)
122121
resp = await self.connection.send_raw_transaction(raw, opts=opts)
123122
return resp.value
124123

@@ -140,7 +139,7 @@ async def send_all(
140139
opts = self.opts
141140
sigs = []
142141
for tx in txs:
143-
raw = tx.serialize() if isinstance(tx, Transaction) else bytes(tx)
142+
raw = bytes(tx)
144143
resp = await self.connection.send_raw_transaction(raw, opts=opts)
145144
sigs.append(resp.value)
146145
return sigs
@@ -184,7 +183,7 @@ def sign_transaction(self, tx: Transaction) -> Transaction:
184183
Returns:
185184
The signed transaction.
186185
"""
187-
tx.sign(self.payer)
186+
tx.sign([self.payer], tx.message.recent_blockhash)
188187
return tx
189188

190189
def sign_all_transactions(self, txs: list[Transaction]) -> list[Transaction]:
@@ -197,7 +196,7 @@ def sign_all_transactions(self, txs: list[Transaction]) -> list[Transaction]:
197196
The signed transactions.
198197
"""
199198
for tx in txs:
200-
tx.sign_partial(self.payer)
199+
tx.partial_sign([self.payer], tx.message.recent_blockhash)
201200
return txs
202201

203202
@classmethod

src/anchorpy/pytest_plugin.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
import os
33
import signal
44
import subprocess
5-
from contextlib import suppress
65
from pathlib import Path
7-
from typing import AsyncGenerator, Callable, Literal, Optional, Sequence, Tuple, Union
6+
from typing import AsyncGenerator, Callable, Literal, Optional, Union
87

98
from pytest import fixture
109
from pytest_asyncio import fixture as async_fixture
1110
from pytest_xprocess import getrootdir
12-
from solders.account import Account
13-
from solders.pubkey import Pubkey
1411
from xprocess import ProcessStarter, XProcess, XProcessInfo
1512

1613
from anchorpy.program.core import Program
1714
from anchorpy.workspace import close_workspace, create_workspace
1815

19-
with suppress(ImportError):
20-
from solders import bankrun
21-
2216
_Scope = Literal["session", "package", "module", "class", "function"]
2317

2418

@@ -240,57 +234,3 @@ class Starter(ProcessStarter):
240234
_fixed_xprocess.getinfo("localnet").terminate()
241235

242236
return _workspace_fixture
243-
244-
245-
async def _bankrun_helper(
246-
path: Union[Path, str],
247-
build_cmd: Optional[str] = None,
248-
accounts: Optional[Sequence[Tuple[Pubkey, Account]]] = None,
249-
compute_max_units: Optional[int] = None,
250-
transaction_account_lock_limit: Optional[int] = None,
251-
) -> "bankrun.ProgramTestContext":
252-
actual_build_cmd = "anchor build" if build_cmd is None else build_cmd
253-
subprocess.run(actual_build_cmd, cwd=path, check=True, shell=True)
254-
path_to_use = Path(path)
255-
return await bankrun.start_anchor(
256-
path_to_use,
257-
accounts=accounts,
258-
compute_max_units=compute_max_units,
259-
transaction_account_lock_limit=transaction_account_lock_limit,
260-
)
261-
262-
263-
def bankrun_fixture(
264-
path: Union[Path, str],
265-
scope: _Scope = "module",
266-
build_cmd: Optional[str] = None,
267-
accounts: Optional[Sequence[Tuple[Pubkey, Account]]] = None,
268-
compute_max_units: Optional[int] = None,
269-
transaction_account_lock_limit: Optional[int] = None,
270-
) -> "bankrun.ProgramTestContext":
271-
"""Create a fixture that builds the project and starts a bankrun with all the programs in the workspace deployed.
272-
273-
Args:
274-
path: Path to root of the Anchor project.
275-
scope: Pytest fixture scope.
276-
build_cmd: Command to build the project. Defaults to `anchor build`.
277-
accounts: A sequence of (address, account_object) tuples, indicating
278-
what data to write to the given addresses.
279-
compute_max_units: Override the default compute unit limit for a transaction.
280-
transaction_account_lock_limit: Override the default transaction account lock limit.
281-
282-
Returns:
283-
A bankrun fixture for use with pytest.
284-
""" # noqa: E501,D202
285-
286-
@async_fixture(scope=scope)
287-
async def _bankrun_fixture() -> bankrun.ProgramTestContext:
288-
return await _bankrun_helper(
289-
path,
290-
build_cmd,
291-
accounts,
292-
compute_max_units,
293-
transaction_account_lock_limit,
294-
)
295-
296-
return _bankrun_fixture

src/anchorpy/utils/rpc.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
from solana.rpc.async_api import AsyncClient
77
from solana.rpc.commitment import Commitment, Confirmed, Finalized, Processed
88
from solana.rpc.core import RPCException
9-
from solana.transaction import Transaction
109
from solders.account import Account
1110
from solders.account_decoder import UiAccountEncoding
1211
from solders.commitment_config import CommitmentLevel
13-
from solders.instruction import AccountMeta, Instruction
1412
from solders.pubkey import Pubkey
1513
from solders.rpc.config import RpcAccountInfoConfig
1614
from solders.rpc.requests import GetMultipleAccounts, batch_to_json
1715
from solders.rpc.responses import GetMultipleAccountsResp, RPCError, batch_from_json
18-
from solders.signature import Signature
1916
from toolz import concat, partition_all
2017

21-
from anchorpy.program.common import AddressType, translate_address
22-
from anchorpy.provider import Provider
23-
2418
_GET_MULTIPLE_ACCOUNTS_LIMIT = 100
2519
_MAX_ACCOUNT_SIZE = 10 * 1048576
2620

@@ -48,36 +42,6 @@ class AccountInfo(NamedTuple):
4842
data: bytes
4943
rent_epoch: Optional[int]
5044

51-
52-
async def invoke(
53-
program_id: AddressType,
54-
provider: Provider,
55-
accounts: Optional[list[AccountMeta]] = None,
56-
data: Optional[bytes] = None,
57-
) -> Signature:
58-
"""Send a transaction to a program with the given accounts and instruction data.
59-
60-
Args:
61-
program_id: The program ID
62-
provider: the `Provider` instance.
63-
accounts: `AccountMeta` objects.
64-
data: The transaction data.
65-
66-
Returns:
67-
The transaction signature.
68-
"""
69-
translated_program_id = translate_address(program_id)
70-
tx = Transaction()
71-
tx.add(
72-
Instruction(
73-
program_id=translated_program_id,
74-
accounts=[] if accounts is None else accounts,
75-
data=bytes(0) if data is None else data,
76-
),
77-
)
78-
return await provider.send(tx)
79-
80-
8145
@dataclass
8246
class _MultipleAccountsItem:
8347
pubkey: Pubkey

tests/unit/test_accounts_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from anchorpy import Idl
44
from anchorpy.program.namespace.instruction import _accounts_array
55
from pytest import mark
6-
from solana.transaction import AccountMeta
6+
from solders.instruction import AccountMeta
77
from solders.keypair import Keypair
88

99

0 commit comments

Comments
 (0)