Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor bankrun connection helper #51

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,35 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: metadaoproject/setup-solana@v1.0
- uses: heyayushh/setup-anchor@v4.3
with:
# Install Solana CLI (beta, required to fix 'ahash' issue)
solana-cli-version: "1.18.5"

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: 21.x
node-version: "21.x"
solana-cli-version: "1.18.22"
anchor-version: "0.30.1"
use-avm: "false"

- name: Run Solana validator (and background it)
run: solana-test-validator &

- name: Install everything
run: npm ci

- name: Check Solana keygen is installed
run: echo $PATH; which solana-keygen
run: |
npm ci
# Install deps for bankrun test
cd tests/bankrun_test && npm ci
cd - > /dev/null
shell: bash

- name: Check Solana keygen is installed and Create a keypair
run: |
echo $PATH; which solana-keygen;
solana config set --url localhost
solana-keygen new --no-bip39-passphrase
solana airdrop 3
shell: bash

- name: Run tests
run: npm run test:ci
run: |
cd tests && npm run test:ci
killall solana-test-validator
npm run test:bankrun
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ The `helpers` package contains Solana helper functions, for use in the browser a

[Load or create a keypair and airdrop to it if needed](#load-or-create-a-keypair-and-airdrop-to-it-if-needed)

[Get connection object for anchor-bankrun](#get-connection-object-for-anchor-bankrun)

## Installation

```bash
Expand Down Expand Up @@ -441,6 +443,23 @@ const DEFAULT_MINIMUM_BALANCE = 0.5 * LAMPORTS_PER_SOL;
const DEFAULT_ENV_KEYPAIR_VARIABLE_NAME = "PRIVATE_KEY";
```

### Get Connection object for anchor-bankrun

[Anchor bankrun](https://github.com/kevinheavey/anchor-bankrun) when used with `provider.connection` doesn't have functions like `sendTransaction` and `getSignatureStatus` that are available in the `@solana/web3.js` connection object.
This helper function allows you to get the connection object for anchor-bankrun.

connection object can be created using this way.
```
const bankrunContextWrapper = new BankrunContextWrapper(context);
const connection = bankrunContextWrapper.connection.toConnection();
const program = new anchor.Program<BankrunTest>(IDL, {
...provider,
connection: connection,
});
```

now you can pass connection object as args or directly use program.methods.

## Secret key format

Secret keys can be read in either the more compact base58 format (`base58.encode(randomKeypair.secretKey);`), like:
Expand Down Expand Up @@ -478,7 +497,7 @@ The tests use the [node native test runner](https://blog.logrocket.com/exploring
If you'd like to run a single test, use:

```bash
esrun --node-test-name-pattern="getCustomErrorMessage" src/index.test.ts
node --require esbuild-register --test --test-name-pattern="getCustomErrorMessage" src/logs.test.ts
```

To just run tests matching the name `getCustomErrorMessage`.
Loading