Skip to content

Commit b36f680

Browse files
committed
swap out bankrun for litesvm in ts-sdk whirlpool tests
1 parent e6f4dad commit b36f680

File tree

8 files changed

+611
-183
lines changed

8 files changed

+611
-183
lines changed

ts-sdk/whirlpool/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"devDependencies": {
4545
"@solana/kit": "^5.0.0",
46-
"solana-bankrun": "^0.4.0",
46+
"litesvm": "^0.3.3",
4747
"tsup": "^8.4.0",
4848
"typescript": "^5.9.3",
4949
"vitest": "^3.2.4"

ts-sdk/whirlpool/src/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export async function prepareTokenAccountsInstructions(
151151
: 0n;
152152
if (ENFORCE_TOKEN_BALANCE_CHECK) {
153153
assert(
154-
BigInt(spec[mint.address]) <= existingBalance,
154+
BigInt(spec[mint.address]) < existingBalance,
155155
`Token account for ${mint.address} does not have the required balance`,
156156
);
157157
}

ts-sdk/whirlpool/tests/increaseLiquidity.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { describe, it, beforeAll } from "vitest";
2-
import { increaseLiquidityInstructions } from "../src/increaseLiquidity";
3-
import { rpc, signer, sendTransaction } from "./utils/mockRpc";
4-
import { setupMint, setupAta } from "./utils/token";
51
import { fetchPosition, getPositionAddress } from "@orca-so/whirlpools-client";
62
import { fetchToken } from "@solana-program/token-2022";
73
import type { Address } from "@solana/kit";
84
import assert from "assert";
5+
import { beforeAll, describe, it } from "vitest";
6+
import {
7+
DEFAULT_FUNDER,
8+
setDefaultFunder,
9+
setEnforceTokenBalanceCheck,
10+
} from "../src/config";
11+
import { increaseLiquidityInstructions } from "../src/increaseLiquidity";
12+
import { rpc, sendTransaction, signer } from "./utils/mockRpc";
913
import {
1014
setupPosition,
1115
setupTEPosition,
1216
setupWhirlpool,
1317
} from "./utils/program";
14-
import { DEFAULT_FUNDER, setDefaultFunder } from "../src/config";
18+
import { setupAta, setupMint } from "./utils/token";
1519
import {
1620
setupAtaTE,
1721
setupMintTE,
@@ -132,7 +136,7 @@ describe("Increase Liquidity Instructions", () => {
132136
const liquidity = 100_000n;
133137
setDefaultFunder(DEFAULT_FUNDER);
134138
await assert.rejects(
135-
increaseLiquidityInstructions(rpc, positions.entries().next().value, {
139+
increaseLiquidityInstructions(rpc, positions.entries().next().value![1], {
136140
liquidity,
137141
}),
138142
);
@@ -141,10 +145,12 @@ describe("Increase Liquidity Instructions", () => {
141145

142146
it("Should throw error increase liquidity amount by token is equal or greater than the token balance", async () => {
143147
const tokenAAmount = 1_000_000n;
148+
setEnforceTokenBalanceCheck(true);
144149
await assert.rejects(
145-
increaseLiquidityInstructions(rpc, positions.entries().next().value, {
150+
increaseLiquidityInstructions(rpc, positions.entries().next().value![1], {
146151
tokenA: tokenAAmount,
147152
}),
148153
);
154+
setEnforceTokenBalanceCheck(false);
149155
});
150156
});

ts-sdk/whirlpool/tests/pool.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,21 @@ describe("Fetch Pool", () => {
7373
assert.strictEqual(pool.whirlpoolsConfig, WHIRLPOOLS_CONFIG_ADDRESS);
7474
});
7575

76-
// TODO: Enable this test once solana-bankrun exposes getProgramAccounts
77-
it.skip("Should be able to fetch all pools for a pair", async () => {
76+
it("Should be able to fetch all pools for a pair", async () => {
7877
const pools = await fetchWhirlpoolsByTokenPair(rpc, mintA, mintB);
7978
assert.strictEqual(pools.length, 3);
80-
assert.strictEqual(pools[0].initialized, true);
81-
assert.strictEqual(pools[0].tickSpacing, 64);
82-
assert.strictEqual(pools[1].initialized, true);
83-
assert.strictEqual(pools[1].tickSpacing, SPLASH_POOL_TICK_SPACING);
84-
assert.strictEqual(pools[2].initialized, false);
85-
assert.strictEqual(pools[2].tickSpacing, 128);
79+
80+
// Check that we have all expected tick spacings
81+
const tickSpacings = pools.map((p) => p.tickSpacing);
82+
assert.ok(tickSpacings.includes(64));
83+
assert.ok(tickSpacings.includes(SPLASH_POOL_TICK_SPACING));
84+
assert.ok(tickSpacings.includes(128));
85+
86+
// Check initialized states
87+
const initializedPools = pools.filter((p) => p.initialized);
88+
const uninitializedPools = pools.filter((p) => !p.initialized);
89+
assert.strictEqual(initializedPools.length, 2);
90+
assert.strictEqual(uninitializedPools.length, 1);
91+
assert.strictEqual(uninitializedPools[0].tickSpacing, 128);
8692
});
8793
});

ts-sdk/whirlpool/tests/position.test.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
fetchPositionsInWhirlpool,
1515
} from "../src/position";
1616
import { rpc, signer } from "./utils/mockRpc";
17+
import { getFullRangeTickIndexes } from "@orca-so/whirlpools-core";
1718

1819
describe("Fetch Position", () => {
1920
let mintA: Address;
@@ -29,28 +30,48 @@ describe("Fetch Position", () => {
2930
pool = await setupWhirlpool(mintA, mintB, 128);
3031
splashPool = await setupWhirlpool(mintA, mintB, SPLASH_POOL_TICK_SPACING);
3132
await setupPosition(pool);
32-
await setupPosition(splashPool);
33+
const splashFullRange = getFullRangeTickIndexes(SPLASH_POOL_TICK_SPACING);
34+
await setupPosition(splashPool, {
35+
tickLower: splashFullRange.tickLowerIndex,
36+
tickUpper: splashFullRange.tickUpperIndex,
37+
});
3338
await setupTEPosition(pool);
34-
await setupPositionBundle(pool);
35-
await setupPositionBundle(splashPool, [{}, {}]);
39+
40+
// bundle with 1 position, 2 positions
41+
await setupPositionBundle(pool, [{ tickLower: -100, tickUpper: 100 }]);
42+
await setupPositionBundle(splashPool, [
43+
{
44+
tickLower: splashFullRange.tickLowerIndex,
45+
tickUpper: splashFullRange.tickUpperIndex,
46+
},
47+
{
48+
tickLower: splashFullRange.tickLowerIndex,
49+
tickUpper: splashFullRange.tickUpperIndex,
50+
},
51+
]);
3652
});
3753

38-
// TODO: enable this when solana-bankrun supports gpa
39-
it.skip("Should fetch all positions for an address", async () => {
54+
it("Should fetch all positions for an address", async () => {
4055
const positions = await fetchPositionsForOwner(rpc, signer.address);
41-
assert.strictEqual(positions.length, 5);
56+
57+
// 3 positions: 1 regular on pool, 1 full-range on splashPool, 1 TE on pool
58+
const standalone = positions.filter((p) => !p.isPositionBundle);
59+
assert.strictEqual(standalone.length, 3);
60+
61+
const bundles = positions.filter((p) => p.isPositionBundle);
62+
assert.strictEqual(bundles.length, 2);
63+
assert.deepEqual(bundles.map((b) => b.positions.length).sort(), [1, 2]);
4264
});
4365

44-
// TODO: enable this when solana-bankrun supports gpa
45-
it.skip("Should fetch no positions for a different address", async () => {
66+
it("Should fetch no positions for a different address", async () => {
4667
const other = await generateKeyPairSigner();
4768
const positions = await fetchPositionsForOwner(rpc, other.address);
4869
assert.strictEqual(positions.length, 0);
4970
});
5071

51-
// TODO: enable this when solana-bankrun supports gpa
52-
it.skip("Should fetch positions for a whirlpool", async () => {
72+
it("Should fetch positions for a whirlpool", async () => {
5373
const positions = await fetchPositionsInWhirlpool(rpc, pool);
74+
// 3 positions in pool: 1 regular + 1 TE + 1 bundled
5475
assert.strictEqual(positions.length, 3);
5576
});
5677
});

0 commit comments

Comments
 (0)