Skip to content

Commit 63fa251

Browse files
committed
token-swap-native: Add types in tests
1 parent f4ed44c commit 63fa251

7 files changed

+156
-58
lines changed

tokens/token-swap/native/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
},
88
"devDependencies": {
99
"@solana/spl-token": "^0.4.9",
10+
"@solana/web3.js": "^1.95.8",
1011
"@types/chai": "^4.3.0",
1112
"@types/mocha": "^9.0.0",
1213
"borsh": "^0.7.0",
1314
"chai": "^4.3.4",
1415
"chai-as-promised": "^8.0.1",
1516
"mocha": "^9.0.3",
17+
"solana-bankrun": "^0.4.0",
1618
"spl-token-bankrun": "^0.2.6",
1719
"ts-mocha": "^10.0.0",
1820
"typescript": "^4.3.5"

tokens/token-swap/native/pnpm-lock.yaml

+73-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tokens/token-swap/native/tests/create_amm.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Keypair } from "@solana/web3.js";
22
import { PublicKey } from "@solana/web3.js"
33
import { it, beforeEach, describe } from "mocha";
4-
import { start } from "solana-bankrun";
4+
import { BanksClient, ProgramTestContext, start } from "solana-bankrun";
55
import { createCreateAmmInstruction } from "./ts/instructions";
66
import { Transaction } from "@solana/web3.js";
77
import { Amm } from "./ts/state";
@@ -10,7 +10,12 @@ import { expectRevert } from "./utils";
1010

1111

1212
describe('Create AMM', async () => {
13-
let programId, context, client, payer, ammPda, admin;
13+
let programId: PublicKey;
14+
let context: ProgramTestContext;
15+
let client: BanksClient;
16+
let payer: Keypair;
17+
let ammPda: PublicKey;
18+
let admin: Keypair;
1419
beforeEach(async () => {
1520
programId = PublicKey.unique();
1621
context = await start([{ name: "token_swap_native", programId }], []);
@@ -30,6 +35,9 @@ describe('Create AMM', async () => {
3035
await client.processTransaction(tx);
3136

3237
const amm = await client.getAccount(ammPda);
38+
if (!amm) {
39+
throw new Error(`AMM account not found`);
40+
}
3341
expect(amm.owner.toBase58()).to.equal(programId.toBase58())
3442
const ammData = Amm.fromBuffer(Buffer.from(amm.data));
3543
expect(ammData.admin.toBase58()).to.equal(admin.publicKey.toBase58());

tokens/token-swap/native/tests/create_pool.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
22
import { it, beforeEach, describe } from "mocha";
3-
import { start } from "solana-bankrun";
3+
import { BanksClient, ProgramTestContext, start } from "solana-bankrun";
44
import { createCreateAmmInstruction, createCreatePoolInstruction } from "./ts/instructions";
55
import { createMint } from "spl-token-bankrun";
66
import { Pool } from "./ts/state";
@@ -9,9 +9,19 @@ import { getAssociatedTokenAddressSync } from "@solana/spl-token";
99
import { expectRevert } from "./utils";
1010

1111
describe('Create Pool', async () => {
12-
let programId, context, client, payer, ammPda, admin;
13-
let mintA, mintB, poolAccountA, poolAccountB;
14-
let poolPda, poolAuthorityPda, mintLiquidityPda;
12+
let programId: PublicKey;
13+
let context: ProgramTestContext;
14+
let client: BanksClient;
15+
let payer: Keypair;
16+
let ammPda: PublicKey;
17+
let admin: Keypair;
18+
let mintA: PublicKey;
19+
let mintB: PublicKey;
20+
let poolAccountA: PublicKey;
21+
let poolAccountB: PublicKey;
22+
let poolPda: PublicKey;
23+
let poolAuthorityPda: PublicKey;
24+
let mintLiquidityPda: PublicKey;
1525
beforeEach(async () => {
1626
programId = PublicKey.unique();
1727
context = await start([{ name: "token_swap_native", programId }], []);
@@ -51,6 +61,9 @@ describe('Create Pool', async () => {
5161
await client.processTransaction(tx);
5262

5363
const pool = await client.getAccount(poolPda);
64+
if (!pool) {
65+
throw new Error(`Pool account not found`);
66+
}
5467
expect(pool.owner.toBase58()).to.equal(programId.toBase58())
5568
const poolData = Pool.fromBuffer(Buffer.from(pool.data));
5669
expect(poolData.amm.toBase58()).to.equal(ammPda.toBase58());

tokens/token-swap/native/tests/deposit_liquidity.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import { Keypair, PublicKey, Transaction } from "@solana/web3.js";
22
import { describe } from "mocha";
3-
import { start } from "solana-bankrun";
3+
import { BanksClient, ProgramTestContext, start } from "solana-bankrun";
44
import { createCreateAmmInstruction, createCreatePoolInstruction, createDepositLiquidityInstruction } from "./ts/instructions";
55
import { createMint, createAssociatedTokenAccount, mintTo } from "spl-token-bankrun";
66
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
77
import { expect } from "chai";
88
import { getTokenBalance } from "./utils";
99

10-
1110
describe('Deposit liquidity', async () => {
12-
13-
let programId, context, client, payer, ammPda, admin;
14-
let mintA, mintB, poolAccountA, poolAccountB;
15-
let poolPda, poolAuthorityPda, mintLiquidityPda;
16-
let depositorAccountLiquidity, depositorAccountA, depositorAccountB;
11+
let programId: PublicKey;
12+
let context: ProgramTestContext;
13+
let client: BanksClient;
14+
let payer: Keypair;
15+
let ammPda: PublicKey;
16+
let admin: Keypair;
17+
let mintA: PublicKey;
18+
let mintB: PublicKey;
19+
let poolAccountA: PublicKey;
20+
let poolAccountB: PublicKey;
21+
let poolPda: PublicKey;
22+
let poolAuthorityPda: PublicKey;
23+
let mintLiquidityPda: PublicKey;
24+
let depositorAccountLiquidity: PublicKey;
25+
let depositorAccountA: PublicKey;
26+
let depositorAccountB: PublicKey;
1727
const default_mint_amount = 100 * 10 ** 6;
1828
const minimum_liquidity = 100; // Matches rust constant
1929
beforeEach(async () => {

tokens/token-swap/native/tests/swap_exact_tokens_for_tokens.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import { Keypair, PublicKey, Transaction } from "@solana/web3.js";
22
import { describe } from "mocha";
3-
import { start } from "solana-bankrun";
3+
import { BanksClient, ProgramTestContext, start } from "solana-bankrun";
44
import { createCreateAmmInstruction, createCreatePoolInstruction, createDepositLiquidityInstruction, createSwapExactTokensForTokensInstruction } from "./ts/instructions";
55
import { createMint, createAssociatedTokenAccount, mintTo } from "spl-token-bankrun";
66
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
77
import { getTokenBalance } from "./utils";
88
import { expect } from "chai";
99

1010
describe('Swap', async () => {
11-
let programId, context, client, payer, ammPda, admin;
12-
let mintA, mintB, poolAccountA, poolAccountB;
13-
let poolPda, poolAuthorityPda, mintLiquidityPda;
14-
let depositorAccountLiquidity, depositorAccountA, depositorAccountB;
11+
let programId: PublicKey;
12+
let context: ProgramTestContext;
13+
let client: BanksClient;
14+
let payer: Keypair;
15+
let ammPda: PublicKey;
16+
let admin: Keypair;
17+
let mintA: PublicKey;
18+
let mintB: PublicKey;
19+
let poolAccountA: PublicKey;
20+
let poolAccountB: PublicKey;
21+
let poolPda: PublicKey;
22+
let poolAuthorityPda: PublicKey;
23+
let mintLiquidityPda: PublicKey;
24+
let depositorAccountLiquidity: PublicKey;
25+
let depositorAccountA: PublicKey;
26+
let depositorAccountB: PublicKey;
1527
const default_mint_amount = 100 * 10 ** 6;
1628
beforeEach(async () => {
1729
programId = PublicKey.unique();

0 commit comments

Comments
 (0)