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

adding bankrun context wrapper #41

Closed
Closed
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
23 changes: 18 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,32 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: metadaoproject/setup-[email protected]
- uses: heyayushh/setup-[email protected]
with:
# Install Solana CLI (beta, required to fix 'ahash' issue)
solana-cli-version: "1.18.5"
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
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
run: echo $PATH; which solana-keygen
- 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 test
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
src/temp
tests/temp
dist
node_modules
test-ledger
.env*
.env*
coverage
13 changes: 13 additions & 0 deletions 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,17 @@ 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();
```

## Secret key format

Secret keys can be read in either the more compact base58 format (`base58.encode(randomKeypair.secretKey);`), like:
Expand Down
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
export default {
testEnvironment: "node",
preset: 'ts-jest',
testMatch: ['**/tests/**/*.test.ts'],
testPathIgnorePatterns: ['/node_modules/', '/tests/bankrun_test/'],
transform: {
'^.+\\.(ts|tsx)?$': ["ts-jest",{
tsconfig: 'tsconfig.test.json',
diagnostics: {
exclude: ['tests/bankrun_test/**'],
}
}],
},
testTimeout: 1200000
};
Loading