diff --git a/src/internal/helpers.ts b/src/internal/helpers.ts index 647c55c..0b0f1fe 100644 --- a/src/internal/helpers.ts +++ b/src/internal/helpers.ts @@ -1,7 +1,7 @@ import * as path from "node:path"; import type { Sablier } from "@src/types"; import * as fs from "fs-extra"; -import { isBroadcastsUnified } from "../../tests/helpers/broadcasts"; +import { isBroadcastsUnified } from "../../tests/evm/helpers/broadcasts"; import { log } from "./logger"; const ROOT_DIR = path.join(__dirname, "..", ".."); diff --git a/tests/chains.test.ts b/tests/evm/chains.test.ts similarity index 100% rename from tests/chains.test.ts rename to tests/evm/chains.test.ts diff --git a/tests/comptroller.test.ts b/tests/evm/comptroller.test.ts similarity index 100% rename from tests/comptroller.test.ts rename to tests/evm/comptroller.test.ts diff --git a/tests/contracts/abi-const.test.ts b/tests/evm/contracts/abi-const.test.ts similarity index 92% rename from tests/contracts/abi-const.test.ts rename to tests/evm/contracts/abi-const.test.ts index d66922f..1832152 100644 --- a/tests/contracts/abi-const.test.ts +++ b/tests/evm/contracts/abi-const.test.ts @@ -106,9 +106,9 @@ describe("Type-level const validation", () => { test("Sample ABI files have correct const assertions", () => { // These imports will fail at compile time if ABIs don't have proper 'as const' type TestAirdropsV14 = - typeof import("../../src/evm/releases/airdrops/v1.3/abi/SablierMerkleInstant").sablierMerkleInstantAbi; - type TestLockupV10 = typeof import("../../src/evm/releases/lockup/v2.0/abi/SablierLockup").sablierLockupAbi; - type TestFlowV10 = typeof import("../../src/evm/releases/flow/v1.1/abi/SablierFlow").sablierFlowAbi; + typeof import("../../../src/evm/releases/airdrops/v1.3/abi/SablierMerkleInstant").sablierMerkleInstantAbi; + type TestLockupV10 = typeof import("../../../src/evm/releases/lockup/v2.0/abi/SablierLockup").sablierLockupAbi; + type TestFlowV10 = typeof import("../../../src/evm/releases/flow/v1.1/abi/SablierFlow").sablierFlowAbi; // These type assertions will fail if the ABIs aren't const type _AssertAirdrops = AssertAsConst; diff --git a/tests/contracts/catalog.test.ts b/tests/evm/contracts/catalog.test.ts similarity index 100% rename from tests/contracts/catalog.test.ts rename to tests/evm/contracts/catalog.test.ts diff --git a/tests/contracts/checksums.test.ts b/tests/evm/contracts/checksums.test.ts similarity index 100% rename from tests/contracts/checksums.test.ts rename to tests/evm/contracts/checksums.test.ts diff --git a/tests/contracts/indexed.test.ts b/tests/evm/contracts/indexed.test.ts similarity index 100% rename from tests/contracts/indexed.test.ts rename to tests/evm/contracts/indexed.test.ts diff --git a/tests/contracts/queries.test.ts b/tests/evm/contracts/queries.test.ts similarity index 100% rename from tests/contracts/queries.test.ts rename to tests/evm/contracts/queries.test.ts diff --git a/tests/cron/blocks.test.ts b/tests/evm/cron/blocks.test.ts similarity index 100% rename from tests/cron/blocks.test.ts rename to tests/evm/cron/blocks.test.ts diff --git a/tests/cron/chains-rpc.test.ts b/tests/evm/cron/chains-rpc.test.ts similarity index 100% rename from tests/cron/chains-rpc.test.ts rename to tests/evm/cron/chains-rpc.test.ts diff --git a/tests/cron/coingecko.test.ts b/tests/evm/cron/coingecko.test.ts similarity index 100% rename from tests/cron/coingecko.test.ts rename to tests/evm/cron/coingecko.test.ts diff --git a/tests/deployments/airdrops.test.ts b/tests/evm/deployments/airdrops.test.ts similarity index 100% rename from tests/deployments/airdrops.test.ts rename to tests/evm/deployments/airdrops.test.ts diff --git a/tests/deployments/flow.test.ts b/tests/evm/deployments/flow.test.ts similarity index 100% rename from tests/deployments/flow.test.ts rename to tests/evm/deployments/flow.test.ts diff --git a/tests/deployments/lockup.test.ts b/tests/evm/deployments/lockup.test.ts similarity index 100% rename from tests/deployments/lockup.test.ts rename to tests/evm/deployments/lockup.test.ts diff --git a/tests/deployments/utils/finders.ts b/tests/evm/deployments/utils/finders.ts similarity index 100% rename from tests/deployments/utils/finders.ts rename to tests/evm/deployments/utils/finders.ts diff --git a/tests/deployments/utils/generators.ts b/tests/evm/deployments/utils/generators.ts similarity index 100% rename from tests/deployments/utils/generators.ts rename to tests/evm/deployments/utils/generators.ts diff --git a/tests/deployments/utils/loaders.ts b/tests/evm/deployments/utils/loaders.ts similarity index 100% rename from tests/deployments/utils/loaders.ts rename to tests/evm/deployments/utils/loaders.ts diff --git a/tests/helpers/broadcasts.ts b/tests/evm/helpers/broadcasts.ts similarity index 100% rename from tests/helpers/broadcasts.ts rename to tests/evm/helpers/broadcasts.ts diff --git a/tests/helpers/etherscan.ts b/tests/evm/helpers/etherscan.ts similarity index 100% rename from tests/helpers/etherscan.ts rename to tests/evm/helpers/etherscan.ts diff --git a/tests/helpers/missing.ts b/tests/evm/helpers/missing.ts similarity index 100% rename from tests/helpers/missing.ts rename to tests/evm/helpers/missing.ts diff --git a/tests/types.ts b/tests/evm/types.ts similarity index 100% rename from tests/types.ts rename to tests/evm/types.ts diff --git a/tests/helpers/setup.ts b/tests/setup.ts similarity index 100% rename from tests/helpers/setup.ts rename to tests/setup.ts diff --git a/tests/solana/contracts/catalog.test.ts b/tests/solana/contracts/catalog.test.ts new file mode 100644 index 0000000..571ecdc --- /dev/null +++ b/tests/solana/contracts/catalog.test.ts @@ -0,0 +1,20 @@ +import { sablier } from "@src/sablier"; +import { releases } from "@src/solana/releases"; +import { describe, expect, it } from "vitest"; + +describe("Contract catalog", () => { + const releasesToTest = [releases.airdrops["v1.0"], releases.lockup["v1.0"]]; + + for (const release of releasesToTest) { + it(`should have a valid catalog for ${release.protocol} ${release.version}`, () => { + const deployment = release.deployments[0]; + const contract = deployment.contracts[0]; + const entry = sablier.solana.contracts.get({ + chainId: deployment.chainId, + contractName: contract.name, + release: release, + }); + expect(entry).toStrictEqual(contract); + }); + } +}); diff --git a/tests/solana/contracts/indexed.test.ts b/tests/solana/contracts/indexed.test.ts new file mode 100644 index 0000000..cb615e3 --- /dev/null +++ b/tests/solana/contracts/indexed.test.ts @@ -0,0 +1,35 @@ +import { sablier } from "@src/sablier"; +import { contracts } from "@src/solana/contracts"; +import { Protocol } from "@src/solana/enums"; +import type { Sablier } from "@src/types"; +import { describe, expect, it } from "vitest"; + +/** + * These contracts are indexed by the Sablier Indexers, so they require a deployment block number. + * @see https://github.com/sablier-labs/indexers + */ +const INDEXED: Record> = { + [Protocol.Airdrops]: new Set([contracts.names.SABLIER_MERKLE_INSTANT]), + [Protocol.Lockup]: new Set([contracts.names.SABLIER_LOCKUP_LINEAR]), +}; + +describe("Indexed contracts have a deployment block number", () => { + for (const release of sablier.solana.releases.getAll()) { + describe(`${release.protocol} ${release.version}`, () => { + const contracts = sablier.solana.contracts.getAll({ release })!; + + for (const contract of contracts) { + if (!INDEXED[release.protocol].has(contract.name)) { + it.skip(`Skipped ${contract.name} because it's not an indexed contract.`, () => {}); + continue; + } + + const chain = sablier.solana.chains.getOrThrow(contract.chainId); + it(`Contract ${contract.name} should have a deployment block number set on ${chain.name}`, () => { + const errorMsg = `No block number found for ${contract.name}`; + expect(contract.block, errorMsg).toBeDefined(); + }); + } + }); + } +}); diff --git a/tests/solana/contracts/queries.test.ts b/tests/solana/contracts/queries.test.ts new file mode 100644 index 0000000..a250bae --- /dev/null +++ b/tests/solana/contracts/queries.test.ts @@ -0,0 +1,73 @@ +import { sablier } from "@src/sablier"; +import { releases } from "@src/solana/releases"; +import { describe, expect, it } from "vitest"; + +const allReleasesToTest = [releases.airdrops["v1.0"], releases.lockup["v1.0"]]; + +describe("contractsQueries.get", () => { + describe("{ chainId, contractName, release }", () => { + for (const release of allReleasesToTest) { + it("should return contract when found", () => { + const deployment = release.deployments[0]; + const contract = deployment.contracts[0]; + + const result = sablier.solana.contracts.get({ + chainId: deployment.chainId, + contractName: contract.name, + release, + }); + + expect(result).toStrictEqual(contract); + }); + } + }); + + describe("{ chainId, contractAddress, protocol }", () => { + it("should return contract when found in single release", () => { + const release = allReleasesToTest[0]; + const deployment = release.deployments[0]; + const contract = deployment.contracts[0]; + + const result = sablier.solana.contracts.get({ + chainId: deployment.chainId, + contractAddress: contract.address, + protocol: release.protocol, + }); + + expect(result).toStrictEqual(contract); + }); + }); + + describe("{ chainId, contractAddress, protocol, release }", () => { + it("should return contract when found", () => { + const release = allReleasesToTest[0]; + const deployment = release.deployments[0]; + const contract = deployment.contracts[0]; + + const result = sablier.solana.contracts.get({ + chainId: deployment.chainId, + contractAddress: contract.address, + protocol: release.protocol, + release, + }); + + expect(result).toStrictEqual(contract); + }); + }); + + describe("{ chainId, contractAddress, release }", () => { + it("should return contract when found", () => { + const release = allReleasesToTest[0]; + const deployment = release.deployments[0]; + const contract = deployment.contracts[0]; + + const result = sablier.solana.contracts.get({ + chainId: deployment.chainId, + contractAddress: contract.address, + release, + }); + + expect(result).toStrictEqual(contract); + }); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts index b6eaa1f..0b5d747 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,10 +6,10 @@ const VITE_CRON_TESTS = Boolean(process.env.VITE_CRON_TESTS); function getInclude() { if (CI && VITE_CRON_TESTS) { - return ["tests/cron/**/*.test.ts"]; + return ["tests/**/cron/**/*.test.ts"]; } - return ["tests/**/*.test.ts", "!tests/cron/**/*.ts"]; + return ["tests/**/*.test.ts", "!tests/**/cron/**/*.ts"]; } /** @@ -34,7 +34,7 @@ export default defineConfig({ plugins: [tsconfigPaths()], test: { environment: "node", - globalSetup: "./tests/helpers/setup.ts", + globalSetup: "./tests/setup.ts", globals: true, include: getInclude(), outputFile: CI ? "./test-results.json" : undefined,