diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index cbce2a8e..11cc2300 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -10,9 +10,9 @@ runs: - name: Npm audit shell: bash run: npm audit --audit-level=moderate - # - name: Test - # shell: bash - # run: npm run test:ci + - name: Test + shell: bash + run: npm run test:ci - name: Build shell: bash run: | diff --git a/package.json b/package.json index 84ab738d..aa1ecd76 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "sideEffects": false, "description": "Typescript library to interact with the Nil blockchain. Can be used in the browser or in Node.js.", "scripts": { - "test": "vitest -c ./test/vitest.config.ts", + "test:unit": "vitest -c ./test/vitest.config.ts", "test:ci": "CI=true vitest -c ./test/vitest.config.ts", - "integration-test": "CI=true vitest -c ./test/vitest.integration.config.ts --isolate false", + "test:integration": "CI=true vitest -c ./test/vitest.integration.config.ts --isolate false", "test:coverage": "npm run test:ci -- --coverage", "build": "rimraf dist && rollup -c ./rollup/rollup.config.js --bundleConfigAsCjs", "prepare": "npx simple-git-hooks", diff --git a/src/clients/PublicClient.test.ts b/src/clients/PublicClient.test.ts index b646bf96..3eda5cca 100644 --- a/src/clients/PublicClient.test.ts +++ b/src/clients/PublicClient.test.ts @@ -170,7 +170,10 @@ test("getMessageByHash", async ({ expect }) => { test("getMessageReceiptByHash", async ({ expect }) => { const fn = vi.fn(); - fn.mockReturnValue({}); + fn.mockReturnValue({ + gasPrice: "0x100", + gasUsed: "0x100", + }); const client = new PublicClient({ transport: new MockTransport(fn), shardId: 1, diff --git a/src/clients/PublicClient.ts b/src/clients/PublicClient.ts index 69b406e9..ac7e378e 100644 --- a/src/clients/PublicClient.ts +++ b/src/clients/PublicClient.ts @@ -300,6 +300,7 @@ class PublicClient extends BaseClient { shardId = this.shardId, ): Promise { assertIsValidShardId(shardId); + const mapReceipt = (receipt: IReceipt): ProcessedReceipt => { return { ...receipt, diff --git a/src/contracts/Faucet/Faucet.test.ts b/src/contracts/Faucet/Faucet.test.ts index 128641eb..0d683809 100644 --- a/src/contracts/Faucet/Faucet.test.ts +++ b/src/contracts/Faucet/Faucet.test.ts @@ -1,5 +1,5 @@ import { PublicClient } from "../../clients/index.js"; -import { bytesToHex } from "../../index.js"; +import { bytesToHex } from "../../encoding/fromBytes.js"; import { LocalECDSAKeySigner, generateRandomPrivateKey, diff --git a/src/contracts/WalletV1/WalletV1.test.ts b/src/contracts/WalletV1/WalletV1.test.ts index 3eed5784..8816d5bd 100644 --- a/src/contracts/WalletV1/WalletV1.test.ts +++ b/src/contracts/WalletV1/WalletV1.test.ts @@ -2,17 +2,18 @@ import { PublicClient } from "../../clients/index.js"; import { generateRandomPrivateKey } from "../../index.js"; import { LocalECDSAKeySigner } from "../../signers/LocalECDSAKeySigner.js"; import { MockTransport } from "../../transport/MockTransport.js"; -import { HttpTransport } from "../../transport/index.js"; import { WalletV1 } from "./WalletV1.js"; const signer = new LocalECDSAKeySigner({ privateKey: generateRandomPrivateKey(), }); const pubkey = await signer.getPublicKey(); + +const fn = vi.fn(); +fn.mockReturnValue({}); + const client = new PublicClient({ - transport: new HttpTransport({ - endpoint: "http://127.0.0.1:8529", - }), + transport: new MockTransport(fn), shardId: 1, }); @@ -121,7 +122,7 @@ test("Deploy through wallet", async ({ expect }) => { salt: 100n, shardId: 1, value: 100n, - gas: 100_000n * 10n, + feeCredit: 100_000n, }); expect(fn.mock.calls).toHaveLength(1); expect(fn.mock.calls[0][0].method).toBe("eth_sendRawTransaction"); diff --git a/src/contracts/WalletV1/WalletV1.ts b/src/contracts/WalletV1/WalletV1.ts index 26be1e19..5e453b95 100644 --- a/src/contracts/WalletV1/WalletV1.ts +++ b/src/contracts/WalletV1/WalletV1.ts @@ -4,7 +4,8 @@ import { bytesToHex, encodeFunctionData } from "viem"; import type { PublicClient } from "../../clients/PublicClient.js"; import { prepareDeployPart } from "../../encoding/deployPart.js"; import { externalMessageEncode } from "../../encoding/externalMessage.js"; -import { hexToBytes, toHex } from "../../index.js"; +import { hexToBytes } from "../../encoding/fromHex.js"; +import { toHex } from "../../encoding/toHex.js"; import type { ISigner } from "../../signers/index.js"; import type { IDeployData } from "../../types/IDeployData.js"; import { getShardIdFromAddress, refineAddress } from "../../utils/address.js"; diff --git a/src/encoding/fromBytes.ts b/src/encoding/fromBytes.ts index ac2e5be9..382ab68e 100644 --- a/src/encoding/fromBytes.ts +++ b/src/encoding/fromBytes.ts @@ -1,4 +1,5 @@ -import { type Hex, toHex } from "../index.js"; +import type { Hex } from "../index.js"; +import { toHex } from "./toHex.js"; const decoder = new TextDecoder("utf8"); diff --git a/src/integrations/bounce.test.ts b/test/integration/bounce.test.ts similarity index 96% rename from src/integrations/bounce.test.ts rename to test/integration/bounce.test.ts index 4094f700..c94e9732 100644 --- a/src/integrations/bounce.test.ts +++ b/test/integration/bounce.test.ts @@ -1,5 +1,4 @@ import { bytesToHex, encodeFunctionData } from "viem"; -import { testEnv } from "../../test/testEnv.js"; import { Faucet, HttpTransport, @@ -9,7 +8,8 @@ import { convertEthToWei, generateRandomPrivateKey, waitTillCompleted, -} from "../index.js"; +} from "../../src/index.js"; +import { testEnv } from "../testEnv.js"; const client = new PublicClient({ transport: new HttpTransport({ endpoint: testEnv.endpoint, diff --git a/src/integrations/calling.test.ts b/test/integration/calling.test.ts similarity index 97% rename from src/integrations/calling.test.ts rename to test/integration/calling.test.ts index 32afb807..0cc0238f 100644 --- a/src/integrations/calling.test.ts +++ b/test/integration/calling.test.ts @@ -1,4 +1,3 @@ -import { testEnv } from "../../test/testEnv.js"; import { Faucet, HttpTransport, @@ -9,7 +8,8 @@ import { convertEthToWei, generateRandomPrivateKey, waitTillCompleted, -} from "../index.js"; +} from "../../src/index.js"; +import { testEnv } from "../testEnv.js"; const client = new PublicClient({ transport: new HttpTransport({ endpoint: testEnv.endpoint, diff --git a/src/integrations/deploy.test.ts b/test/integration/deploy.test.ts similarity index 98% rename from src/integrations/deploy.test.ts rename to test/integration/deploy.test.ts index b78a64fd..2b357f5c 100644 --- a/src/integrations/deploy.test.ts +++ b/test/integration/deploy.test.ts @@ -1,5 +1,4 @@ import type { Abi } from "abitype"; -import { testEnv } from "../../test/testEnv.js"; import { Faucet, HttpTransport, @@ -11,7 +10,8 @@ import { externalDeploymentMessage, generateRandomPrivateKey, waitTillCompleted, -} from "../index.js"; +} from "../../src/index.js"; +import { testEnv } from "../testEnv.js"; const client = new PublicClient({ transport: new HttpTransport({ endpoint: testEnv.endpoint, diff --git a/src/integrations/receipt.test.ts b/test/integration/receipt.test.ts similarity index 82% rename from src/integrations/receipt.test.ts rename to test/integration/receipt.test.ts index b660dc0c..425e269b 100644 --- a/src/integrations/receipt.test.ts +++ b/test/integration/receipt.test.ts @@ -1,13 +1,14 @@ -import { testEnv } from "../../test/testEnv.js"; -import { Faucet, WalletV1 } from "../contracts/index.js"; import { + Faucet, HttpTransport, + LocalECDSAKeySigner, PublicClient, + WalletV1, convertEthToWei, + generateRandomPrivateKey, waitTillCompleted, -} from "../index.js"; -import { LocalECDSAKeySigner } from "../signers/LocalECDSAKeySigner.js"; -import { generateRandomPrivateKey } from "../signers/privateKey.js"; +} from "../../src/index.js"; +import { testEnv } from "../../test/testEnv.js"; const client = new PublicClient({ transport: new HttpTransport({ diff --git a/src/integrations/tokens.test.ts b/test/integration/tokens.test.ts similarity index 97% rename from src/integrations/tokens.test.ts rename to test/integration/tokens.test.ts index 96a6473f..402b570a 100644 --- a/src/integrations/tokens.test.ts +++ b/test/integration/tokens.test.ts @@ -1,5 +1,4 @@ import { encodeFunctionData } from "viem"; -import { testEnv } from "../../test/testEnv.js"; import { Faucet, HttpTransport, @@ -14,7 +13,8 @@ import { hexToBigInt, toHex, waitTillCompleted, -} from "../index.js"; +} from "../../src/index.js"; +import { testEnv } from "../testEnv.js"; const client = new PublicClient({ transport: new HttpTransport({ endpoint: testEnv.endpoint, diff --git a/test/testEnv.ts b/test/testEnv.ts index 9ef7e355..653df964 100644 --- a/test/testEnv.ts +++ b/test/testEnv.ts @@ -1,9 +1,6 @@ const defaultRpcEndpoint = "http://127.0.0.1:8529"; -const defaultPrivateKey = - "41285f03e8692676bf80a98e4052a008026427a7302ca97cb06edcd60689850b"; const testEnv = { - localPrivKey: process.env.LOCAL_PRIV_KEY ?? defaultPrivateKey, endpoint: process.env.RPC_ENDPOINT ?? defaultRpcEndpoint, } as const; diff --git a/test/vitest.integration.config.ts b/test/vitest.integration.config.ts index 0a7578d6..79d0d74a 100644 --- a/test/vitest.integration.config.ts +++ b/test/vitest.integration.config.ts @@ -4,7 +4,7 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { environment: "node", - include: ["src/integrations/*.test.ts"], + include: ["test/integration/*.test.ts"], hookTimeout: 20_000, testTimeout: 40_000, globals: true,