-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the ts-sdk testing setup (#448)
* Improve the ts-sdk testing setup * Remove unused files * Lint
- Loading branch information
Showing
9 changed files
with
659 additions
and
564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,89 @@ | ||
import { describe } from "vitest"; | ||
import { describe, it, beforeAll } from "vitest"; | ||
import { | ||
fetchConcentratedLiquidityPool, | ||
fetchSplashPool, | ||
fetchWhirlpoolsByTokenPair, | ||
} from "../src/pool"; | ||
import { rpc } from "./utils/mockRpc"; | ||
import assert from "assert"; | ||
import { | ||
SPLASH_POOL_TICK_SPACING, | ||
WHIRLPOOLS_CONFIG_ADDRESS, | ||
} from "../src/config"; | ||
import type { Address } from "@solana/web3.js"; | ||
import { setupMint } from "./utils/token"; | ||
import { setupWhirlpool } from "./utils/program"; | ||
import { getWhirlpoolAddress } from "@orca-so/whirlpools-client"; | ||
import { orderMints } from "../src/token"; | ||
|
||
describe.skip("Fetch Pool", () => { | ||
// TODO: <- | ||
describe("Fetch Pool", () => { | ||
let mintA: Address; | ||
let mintB: Address; | ||
let defaultPool: Address; | ||
let concentratedPool: Address; | ||
let splashPool: Address; | ||
|
||
beforeAll(async () => { | ||
const mint1 = await setupMint(); | ||
const mint2 = await setupMint(); | ||
[mintA, mintB] = orderMints(mint1, mint2); | ||
concentratedPool = await setupWhirlpool(mintA, mintB, 64); | ||
defaultPool = await getWhirlpoolAddress( | ||
WHIRLPOOLS_CONFIG_ADDRESS, | ||
mintA, | ||
mintB, | ||
128, | ||
).then((x) => x[0]); | ||
splashPool = await setupWhirlpool(mintA, mintB, SPLASH_POOL_TICK_SPACING); | ||
}); | ||
|
||
it("Should be able to fetch a splash pool", async () => { | ||
const pool = await fetchSplashPool(rpc, mintA, mintB); | ||
assert.strictEqual(pool.initialized, true); | ||
assert.strictEqual(pool.liquidity, 0n); | ||
assert.strictEqual(pool.tickSpacing, SPLASH_POOL_TICK_SPACING); | ||
assert.strictEqual(pool.address, splashPool); | ||
assert.strictEqual(pool.tokenMintA, mintA); | ||
assert.strictEqual(pool.tokenMintB, mintB); | ||
assert.strictEqual(pool.feeRate, 1000); | ||
assert.strictEqual(pool.protocolFeeRate, 100); | ||
assert.strictEqual(pool.whirlpoolsConfig, WHIRLPOOLS_CONFIG_ADDRESS); | ||
}); | ||
|
||
it("Should be able to fetch a concentrated liquidity pool", async () => { | ||
const pool = await fetchConcentratedLiquidityPool(rpc, mintA, mintB, 64); | ||
assert.strictEqual(pool.initialized, true); | ||
assert.strictEqual(pool.liquidity, 0n); | ||
assert.strictEqual(pool.tickSpacing, 64); | ||
assert.strictEqual(pool.address, concentratedPool); | ||
assert.strictEqual(pool.tokenMintA, mintA); | ||
assert.strictEqual(pool.tokenMintB, mintB); | ||
assert.strictEqual(pool.feeRate, 300); | ||
assert.strictEqual(pool.protocolFeeRate, 100); | ||
assert.strictEqual(pool.whirlpoolsConfig, WHIRLPOOLS_CONFIG_ADDRESS); | ||
}); | ||
|
||
it("Should be able to try fetching a non-existent pool", async () => { | ||
const pool = await fetchConcentratedLiquidityPool(rpc, mintA, mintB, 128); | ||
assert.strictEqual(pool.initialized, false); | ||
assert.strictEqual(pool.tickSpacing, 128); | ||
assert.strictEqual(pool.address, defaultPool); | ||
assert.strictEqual(pool.tokenMintA, mintA); | ||
assert.strictEqual(pool.tokenMintB, mintB); | ||
assert.strictEqual(pool.feeRate, 1000); | ||
assert.strictEqual(pool.protocolFeeRate, 100); | ||
assert.strictEqual(pool.whirlpoolsConfig, WHIRLPOOLS_CONFIG_ADDRESS); | ||
}); | ||
|
||
// TODO: Enable this test once solana-bankrun exposes getProgramAccounts | ||
it.skip("Should be able to fetch all pools for a pair", async () => { | ||
const pools = await fetchWhirlpoolsByTokenPair(rpc, mintA, mintB); | ||
assert.strictEqual(pools.length, 3); | ||
assert.strictEqual(pools[0].initialized, true); | ||
assert.strictEqual(pools[0].tickSpacing, 64); | ||
assert.strictEqual(pools[1].initialized, true); | ||
assert.strictEqual(pools[1].tickSpacing, SPLASH_POOL_TICK_SPACING); | ||
assert.strictEqual(pools[2].initialized, false); | ||
assert.strictEqual(pools[2].tickSpacing, 128); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,49 @@ | ||
import { describe } from "vitest"; | ||
import type { Address} from "@solana/web3.js"; | ||
import { generateKeyPairSigner } from "@solana/web3.js"; | ||
import { assert, beforeAll, describe, it } from "vitest"; | ||
import { setupAta, setupMint } from "./utils/token"; | ||
import { | ||
setupPosition, | ||
setupPositionBundle, | ||
setupTEPosition, | ||
setupWhirlpool, | ||
} from "./utils/program"; | ||
import { SPLASH_POOL_TICK_SPACING } from "../src/config"; | ||
import { fetchPositionsForOwner } from "../src/position"; | ||
import { rpc, signer } from "./utils/mockRpc"; | ||
import { orderMints } from "../src/token"; | ||
|
||
describe.skip("Fetch Position", () => { | ||
// TODO: <- | ||
describe("Fetch Position", () => { | ||
let mintA: Address; | ||
let mintB: Address; | ||
let pool: Address; | ||
let splashPool: Address; | ||
|
||
beforeAll(async () => { | ||
const mint1 = await setupMint(); | ||
const mint2 = await setupMint(); | ||
[mintA, mintB] = orderMints(mint1, mint2); | ||
await setupAta(mintA, { amount: 500e9 }); | ||
await setupAta(mintB, { amount: 500e9 }); | ||
pool = await setupWhirlpool(mintA, mintB, 128); | ||
splashPool = await setupWhirlpool(mintA, mintB, SPLASH_POOL_TICK_SPACING); | ||
await setupPosition(pool); | ||
await setupPosition(splashPool); | ||
await setupTEPosition(pool); | ||
await setupPositionBundle(pool); | ||
await setupPositionBundle(splashPool, [{}, {}]); | ||
}); | ||
|
||
// TODO: enable this when solana-bankrun supports gpa | ||
it.skip("Should fetch all positions for an address", async () => { | ||
const positions = await fetchPositionsForOwner(rpc, signer.address); | ||
assert.strictEqual(positions.length, 5); | ||
}); | ||
|
||
// TODO: enable this when solana-bankrun supports gpa | ||
it.skip("Should fetch no positions for a different address", async () => { | ||
const other = await generateKeyPairSigner(); | ||
const positions = await fetchPositionsForOwner(rpc, other.address); | ||
assert.strictEqual(positions.length, 0); | ||
}); | ||
}); |
Oops, something went wrong.