From 9cb45e6d63b68c8a0198ad40c34797deb9b3031d Mon Sep 17 00:00:00 2001 From: Ayush Date: Fri, 6 Sep 2024 01:17:21 +0530 Subject: [PATCH] added tests for esm and cjs, removed jest, tests split into seperate files :sparkles: --- .github/workflows/tests.yaml | 2 +- jest.config.js | 16 - package-lock.json | 874 ++++++++++------------- package.json | 13 +- tests/bankrun_test/tests/bankrun.test.ts | 51 ++ tests/package.json | 10 + tests/{ => src}/airdrop.test.ts | 5 +- tests/{ => src}/explorer.test.ts | 5 +- tests/{ => src}/keypair.test.ts | 29 +- tests/{ => src}/logs.test.ts | 11 +- tests/{ => src}/token.test.ts | 3 +- tests/{ => src}/transaction.test.ts | 3 +- tests/tsconfig.test.json | 20 + tsconfig.test.json | 19 - 14 files changed, 512 insertions(+), 549 deletions(-) delete mode 100644 jest.config.js create mode 100644 tests/bankrun_test/tests/bankrun.test.ts create mode 100644 tests/package.json rename tests/{ => src}/airdrop.test.ts (96%) rename tests/{ => src}/explorer.test.ts (95%) rename tests/{ => src}/keypair.test.ts (84%) rename tests/{ => src}/logs.test.ts (90%) rename tests/{ => src}/token.test.ts (98%) rename tests/{ => src}/transaction.test.ts (97%) create mode 100644 tests/tsconfig.test.json delete mode 100644 tsconfig.test.json diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 47ac343..c1f3473 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -28,4 +28,4 @@ jobs: run: echo $PATH; which solana-keygen - name: Run tests - run: npm test + run: npm run test:ci diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 1d01187..0000000 --- a/jest.config.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} **/ -export default { - testEnvironment: "node", - preset: 'ts-jest', - testMatch: ['**/tests/**/*.test.ts'], - testPathIgnorePatterns: ['/node_modules/', '/tests/bankrun_test/'], - transform: { - '^.+\\.(ts|tsx)?$': ["ts-jest",{ - tsconfig: 'tsconfig.test.json', - diagnostics: { - exclude: ['tests/bankrun_test/**'], - } - }], - }, - testTimeout: 1200000 -}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 82c8f03..c4a4d42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,17 +9,22 @@ "version": "2.5.2", "license": "MIT", "dependencies": { + "@coral-xyz/anchor": "^0.30.1", "@solana/spl-token": "^0.4.8", "@solana/spl-token-metadata": "^0.1.4", "@solana/web3.js": "^1.95.2", + "anchor-bankrun": "^0.4.0", + "bn.js": "^5.2.1", "bs58": "^6.0.0", "dotenv": "^16.4.5" }, "devDependencies": { + "@types/bn.js": "^5.1.5", "@types/jest": "^29.5.12", "@types/node": "^20.16.1", "c8": "^10.1.2", - "esrun": "^3.2.26", + "esbuild": "^0.23.1", + "esbuild-register": "^3.6.0", "prettier": "^3.0.3", "ts-jest": "^29.2.5", "tsup": "^8.2.4", @@ -662,6 +667,99 @@ "dev": true, "license": "MIT" }, + "node_modules/@coral-xyz/anchor": { + "version": "0.30.1", + "resolved": "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.30.1.tgz", + "integrity": "sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ==", + "license": "(MIT OR Apache-2.0)", + "dependencies": { + "@coral-xyz/anchor-errors": "^0.30.1", + "@coral-xyz/borsh": "^0.30.1", + "@noble/hashes": "^1.3.1", + "@solana/web3.js": "^1.68.0", + "bn.js": "^5.1.2", + "bs58": "^4.0.1", + "buffer-layout": "^1.2.2", + "camelcase": "^6.3.0", + "cross-fetch": "^3.1.5", + "crypto-hash": "^1.3.0", + "eventemitter3": "^4.0.7", + "pako": "^2.0.3", + "snake-case": "^3.0.4", + "superstruct": "^0.15.4", + "toml": "^3.0.0" + }, + "engines": { + "node": ">=11" + } + }, + "node_modules/@coral-xyz/anchor-errors": { + "version": "0.30.1", + "resolved": "https://registry.npmjs.org/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz", + "integrity": "sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=10" + } + }, + "node_modules/@coral-xyz/anchor/node_modules/base-x": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.10.tgz", + "integrity": "sha512-7d0s06rR9rYaIWHkpfLIFICM/tkSVdoPC9qYAQRpxn9DdKNWNsKC0uk++akckyLq16Tx2WIinnZ6WRriAt6njQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/@coral-xyz/anchor/node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "license": "MIT", + "dependencies": { + "base-x": "^3.0.2" + } + }, + "node_modules/@coral-xyz/anchor/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@coral-xyz/anchor/node_modules/eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "license": "MIT" + }, + "node_modules/@coral-xyz/anchor/node_modules/superstruct": { + "version": "0.15.5", + "resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.15.5.tgz", + "integrity": "sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ==", + "license": "MIT" + }, + "node_modules/@coral-xyz/borsh": { + "version": "0.30.1", + "resolved": "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.30.1.tgz", + "integrity": "sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ==", + "license": "Apache-2.0", + "dependencies": { + "bn.js": "^5.1.2", + "buffer-layout": "^1.2.0" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@solana/web3.js": "^1.68.0" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", @@ -690,12 +788,6 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, - "node_modules/@digitak/grubber": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/@digitak/grubber/-/grubber-3.1.4.tgz", - "integrity": "sha512-pqsnp2BUYlDoTXWG34HWgEJse/Eo1okRgNex8IG84wHrJp8h3SakeR5WhB4VxSA2+/D+frNYJ0ch3yXzsfNDoA==", - "dev": true - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.23.1", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", @@ -765,19 +857,20 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.19.tgz", - "integrity": "sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", + "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/darwin-x64": { @@ -2676,6 +2769,16 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/bn.js": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-5.1.5.tgz", + "integrity": "sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -2830,6 +2933,20 @@ "node": ">= 8.0.0" } }, + "node_modules/anchor-bankrun": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/anchor-bankrun/-/anchor-bankrun-0.4.0.tgz", + "integrity": "sha512-s+K7E0IGAlmkhuo8nbiqVsQf2yJ+3l9GjNQJSmkRDe25dQj4Yef9rJh77FH6EQ5H6yQYfzuhgm/5GD6JMjdTZg==", + "license": "MIT", + "engines": { + "node": ">= 10" + }, + "peerDependencies": { + "@coral-xyz/anchor": "^0.30.0", + "@solana/web3.js": "^1.78.4", + "solana-bankrun": "^0.2.0" + } + }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -3344,6 +3461,15 @@ "license": "MIT", "peer": true }, + "node_modules/buffer-layout": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/buffer-layout/-/buffer-layout-1.2.2.tgz", + "integrity": "sha512-kWSuLN694+KTk8SrYvCqwP2WcgQjoRCiF5b4QDvkkz8EmgD+aWAIceGFKMIAdmF/pH+vpgNV3d3kAKorcdAmWA==", + "license": "MIT", + "engines": { + "node": ">=4.5" + } + }, "node_modules/bufferutil": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.7.tgz", @@ -3687,6 +3813,15 @@ "optional": true, "peer": true }, + "node_modules/cross-fetch": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", + "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", + "license": "MIT", + "dependencies": { + "node-fetch": "^2.6.12" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -3701,6 +3836,18 @@ "node": ">= 8" } }, + "node_modules/crypto-hash": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/crypto-hash/-/crypto-hash-1.3.0.tgz", + "integrity": "sha512-lyAZ0EMyjDkVvz8WOeVnuCPvKVBXcMv1l5SVqO1yC7PzTwrD/pPje/BIRbWhMoPe436U+Y2nD7f5bFx0kt+Sbg==", + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/debug": { "version": "4.3.6", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", @@ -3810,6 +3957,16 @@ "node": ">=8" } }, + "node_modules/dot-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", + "integrity": "sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==", + "license": "MIT", + "dependencies": { + "no-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, "node_modules/dotenv": { "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", @@ -3881,417 +4038,76 @@ "dev": true, "license": "MIT", "peer": true, - "dependencies": { - "is-arrayish": "^0.2.1" - } - }, - "node_modules/es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", - "license": "MIT" - }, - "node_modules/es6-promisify": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", - "integrity": "sha512-C+d6UdsYDk0lMebHNR4S2NybQMMngAOnOwYBQjTOiv0MkoJMP0Myw2mgpDLBcpfCmRLxyFqYhS/CfOENq4SJhQ==", - "license": "MIT", - "dependencies": { - "es6-promise": "^4.0.3" - } - }, - "node_modules/esbuild": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.19.tgz", - "integrity": "sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==", - "dev": true, - "hasInstallScript": true, - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=12" - }, - "optionalDependencies": { - "@esbuild/android-arm": "0.17.19", - "@esbuild/android-arm64": "0.17.19", - "@esbuild/android-x64": "0.17.19", - "@esbuild/darwin-arm64": "0.17.19", - "@esbuild/darwin-x64": "0.17.19", - "@esbuild/freebsd-arm64": "0.17.19", - "@esbuild/freebsd-x64": "0.17.19", - "@esbuild/linux-arm": "0.17.19", - "@esbuild/linux-arm64": "0.17.19", - "@esbuild/linux-ia32": "0.17.19", - "@esbuild/linux-loong64": "0.17.19", - "@esbuild/linux-mips64el": "0.17.19", - "@esbuild/linux-ppc64": "0.17.19", - "@esbuild/linux-riscv64": "0.17.19", - "@esbuild/linux-s390x": "0.17.19", - "@esbuild/linux-x64": "0.17.19", - "@esbuild/netbsd-x64": "0.17.19", - "@esbuild/openbsd-x64": "0.17.19", - "@esbuild/sunos-x64": "0.17.19", - "@esbuild/win32-arm64": "0.17.19", - "@esbuild/win32-ia32": "0.17.19", - "@esbuild/win32-x64": "0.17.19" - } - }, - "node_modules/esbuild/node_modules/@esbuild/android-arm": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.19.tgz", - "integrity": "sha512-rIKddzqhmav7MSmoFCmDIb6e2W57geRsM94gV2l38fzhXMwq7hZoClug9USI2pFRGL06f4IOPHHpFNOkWieR8A==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/android-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.19.tgz", - "integrity": "sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/android-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.19.tgz", - "integrity": "sha512-uUTTc4xGNDT7YSArp/zbtmbhO0uEEK9/ETW29Wk1thYUJBz3IVnvgEiEwEa9IeLyvnpKrWK64Utw2bgUmDveww==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/darwin-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.19.tgz", - "integrity": "sha512-IJM4JJsLhRYr9xdtLytPLSH9k/oxR3boaUIYiHkAawtwNOXKE8KoU8tMvryogdcT8AU+Bflmh81Xn6Q0vTZbQw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/freebsd-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.19.tgz", - "integrity": "sha512-pBwbc7DufluUeGdjSU5Si+P3SoMF5DQ/F/UmTSb8HXO80ZEAJmrykPyzo1IfNbAoaqw48YRpv8shwd1NoI0jcQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/freebsd-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.19.tgz", - "integrity": "sha512-4lu+n8Wk0XlajEhbEffdy2xy53dpR06SlzvhGByyg36qJw6Kpfk7cp45DR/62aPH9mtJRmIyrXAS5UWBrJT6TQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-arm": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.19.tgz", - "integrity": "sha512-cdmT3KxjlOQ/gZ2cjfrQOtmhG4HJs6hhvm3mWSRDPtZ/lP5oe8FWceS10JaSJC13GBd4eH/haHnqf7hhGNLerA==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.19.tgz", - "integrity": "sha512-ct1Tg3WGwd3P+oZYqic+YZF4snNl2bsnMKRkb3ozHmnM0dGWuxcPTTntAF6bOP0Sp4x0PjSF+4uHQ1xvxfRKqg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-ia32": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.19.tgz", - "integrity": "sha512-w4IRhSy1VbsNxHRQpeGCHEmibqdTUx61Vc38APcsRbuVgK0OPEnQ0YD39Brymn96mOx48Y2laBQGqgZ0j9w6SQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-loong64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.19.tgz", - "integrity": "sha512-2iAngUbBPMq439a+z//gE+9WBldoMp1s5GWsUSgqHLzLJ9WoZLZhpwWuym0u0u/4XmZ3gpHmzV84PonE+9IIdQ==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-mips64el": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.19.tgz", - "integrity": "sha512-LKJltc4LVdMKHsrFe4MGNPp0hqDFA1Wpt3jE1gEyM3nKUvOiO//9PheZZHfYRfYl6AwdTH4aTcXSqBerX0ml4A==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-ppc64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.19.tgz", - "integrity": "sha512-/c/DGybs95WXNS8y3Ti/ytqETiW7EU44MEKuCAcpPto3YjQbyK3IQVKfF6nbghD7EcLUGl0NbiL5Rt5DMhn5tg==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-riscv64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.19.tgz", - "integrity": "sha512-FC3nUAWhvFoutlhAkgHf8f5HwFWUL6bYdvLc/TTuxKlvLi3+pPzdZiFKSWz/PF30TB1K19SuCxDTI5KcqASJqA==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-s390x": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.19.tgz", - "integrity": "sha512-IbFsFbxMWLuKEbH+7sTkKzL6NJmG2vRyy6K7JJo55w+8xDk7RElYn6xvXtDW8HCfoKBFK69f3pgBJSUSQPr+4Q==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/linux-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.19.tgz", - "integrity": "sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/netbsd-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.19.tgz", - "integrity": "sha512-CwFq42rXCR8TYIjIfpXCbRX0rp1jo6cPIUPSaWwzbVI4aOfX96OXY8M6KNmtPcg7QjYeDmN+DD0Wp3LaBOLf4Q==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/openbsd-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.19.tgz", - "integrity": "sha512-cnq5brJYrSZ2CF6c35eCmviIN3k3RczmHz8eYaVlNasVqsNY+JKohZU5MKmaOI+KkllCdzOKKdPs762VCPC20g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild/node_modules/@esbuild/sunos-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.19.tgz", - "integrity": "sha512-vCRT7yP3zX+bKWFeP/zdS6SqdWB8OIpaRq/mbXQxTGHnIxspRtigpkUcDMlSCOejlHowLqII7K2JKevwyRP2rg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" + "dependencies": { + "is-arrayish": "^0.2.1" } }, - "node_modules/esbuild/node_modules/@esbuild/win32-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.19.tgz", - "integrity": "sha512-yYx+8jwowUstVdorcMdNlzklLYhPxjniHWFKgRqH7IFlUEa0Umu3KuYplf1HUZZ422e3NU9F4LGb+4O0Kdcaag==", - "cpu": [ - "arm64" - ], - "dev": true, + "node_modules/es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "license": "MIT" + }, + "node_modules/es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha512-C+d6UdsYDk0lMebHNR4S2NybQMMngAOnOwYBQjTOiv0MkoJMP0Myw2mgpDLBcpfCmRLxyFqYhS/CfOENq4SJhQ==", "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" + "dependencies": { + "es6-promise": "^4.0.3" } }, - "node_modules/esbuild/node_modules/@esbuild/win32-ia32": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.19.tgz", - "integrity": "sha512-eggDKanJszUtCdlVs0RB+h35wNlb5v4TWEkq4vZcmVt5u/HiDZrTXe2bWFQUez3RgNHwx/x4sk5++4NSSicKkw==", - "cpu": [ - "ia32" - ], + "node_modules/esbuild": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", + "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", "dev": true, + "hasInstallScript": true, "license": "MIT", - "optional": true, - "os": [ - "win32" - ], + "bin": { + "esbuild": "bin/esbuild" + }, "engines": { - "node": ">=12" + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.23.1", + "@esbuild/android-arm": "0.23.1", + "@esbuild/android-arm64": "0.23.1", + "@esbuild/android-x64": "0.23.1", + "@esbuild/darwin-arm64": "0.23.1", + "@esbuild/darwin-x64": "0.23.1", + "@esbuild/freebsd-arm64": "0.23.1", + "@esbuild/freebsd-x64": "0.23.1", + "@esbuild/linux-arm": "0.23.1", + "@esbuild/linux-arm64": "0.23.1", + "@esbuild/linux-ia32": "0.23.1", + "@esbuild/linux-loong64": "0.23.1", + "@esbuild/linux-mips64el": "0.23.1", + "@esbuild/linux-ppc64": "0.23.1", + "@esbuild/linux-riscv64": "0.23.1", + "@esbuild/linux-s390x": "0.23.1", + "@esbuild/linux-x64": "0.23.1", + "@esbuild/netbsd-x64": "0.23.1", + "@esbuild/openbsd-arm64": "0.23.1", + "@esbuild/openbsd-x64": "0.23.1", + "@esbuild/sunos-x64": "0.23.1", + "@esbuild/win32-arm64": "0.23.1", + "@esbuild/win32-ia32": "0.23.1", + "@esbuild/win32-x64": "0.23.1" } }, - "node_modules/esbuild/node_modules/@esbuild/win32-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.19.tgz", - "integrity": "sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==", - "cpu": [ - "x64" - ], + "node_modules/esbuild-register": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/esbuild-register/-/esbuild-register-3.6.0.tgz", + "integrity": "sha512-H2/S7Pm8a9CL1uhp9OvjwrBh5Pvx0H8qVOxNu8Wed9Y7qv56MPtq+GGM8RJpq6glYJn9Wspr8uw7l55uyinNeg==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" + "dependencies": { + "debug": "^4.3.4" + }, + "peerDependencies": { + "esbuild": ">=0.12 <1" } }, "node_modules/escalade": { @@ -4329,23 +4145,6 @@ "node": ">=4" } }, - "node_modules/esrun": { - "version": "3.2.26", - "resolved": "https://registry.npmjs.org/esrun/-/esrun-3.2.26.tgz", - "integrity": "sha512-gDjP87qj4RW0BryZXPY3/L161hPo9uG6luBTjLsuHG3cKnhSMrzB7eNzSzvDyBLg7OgugyvzSgB2ov7mZ/oa7Q==", - "dev": true, - "dependencies": { - "@digitak/grubber": "^3.1.4", - "chokidar": "^3.5.1", - "esbuild": "^0.17.4" - }, - "bin": { - "esrun": "bin.js" - }, - "engines": { - "node": ">=14.0" - } - }, "node_modules/eventemitter3": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", @@ -6756,6 +6555,15 @@ "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", "dev": true }, + "node_modules/lower-case": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", + "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.0.3" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -6899,6 +6707,16 @@ "license": "MIT", "peer": true }, + "node_modules/no-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", + "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", + "license": "MIT", + "dependencies": { + "lower-case": "^2.0.2", + "tslib": "^2.0.3" + } + }, "node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -7052,6 +6870,12 @@ "dev": true, "license": "BlueOak-1.0.0" }, + "node_modules/pako": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz", + "integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==", + "license": "(MIT AND Zlib)" + }, "node_modules/parse-json": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", @@ -7665,6 +7489,139 @@ "node": ">=8" } }, + "node_modules/snake-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/snake-case/-/snake-case-3.0.4.tgz", + "integrity": "sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==", + "license": "MIT", + "dependencies": { + "dot-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, + "node_modules/solana-bankrun": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/solana-bankrun/-/solana-bankrun-0.2.0.tgz", + "integrity": "sha512-TS6vYoO/9YJZng7oiLOVyuz8V7yLow5Hp4SLYWW71XM3702v+z9f1fvUBKudRfa4dfpta4tRNufApSiBIALxJQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "@solana/web3.js": "^1.68.0", + "bs58": "^4.0.1" + }, + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "solana-bankrun-darwin-arm64": "0.2.0", + "solana-bankrun-darwin-universal": "0.2.0", + "solana-bankrun-darwin-x64": "0.2.0", + "solana-bankrun-linux-x64-gnu": "0.2.0", + "solana-bankrun-linux-x64-musl": "0.2.0" + } + }, + "node_modules/solana-bankrun-darwin-arm64": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/solana-bankrun-darwin-arm64/-/solana-bankrun-darwin-arm64-0.2.0.tgz", + "integrity": "sha512-ENQ5Z/CYeY8ZVWIc2VutY/gMlBaHi93/kDw9w0iVwewoV+/YpQmP2irwrshIKu6ggRPTF3Ehlh2V6fGVIYWcXw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 10" + } + }, + "node_modules/solana-bankrun-darwin-universal": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/solana-bankrun-darwin-universal/-/solana-bankrun-darwin-universal-0.2.0.tgz", + "integrity": "sha512-HE45TvZXzBipm1fMn87+fkHeIuQ/KFAi5G/S29y/TLuBYt4RDI935RkWiT0rEQ7KwnwO6Y1aTsOaQXldY5R7uQ==", + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 10" + } + }, + "node_modules/solana-bankrun-darwin-x64": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/solana-bankrun-darwin-x64/-/solana-bankrun-darwin-x64-0.2.0.tgz", + "integrity": "sha512-42UsVrnac2Oo4UaIDo60zfI3Xn1i8W6fmcc9ixJQZNTtdO8o2/sY4mFxcJx9lhLMhda5FPHrQbGYgYdIs0kK0g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 10" + } + }, + "node_modules/solana-bankrun-linux-x64-gnu": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/solana-bankrun-linux-x64-gnu/-/solana-bankrun-linux-x64-gnu-0.2.0.tgz", + "integrity": "sha512-WnqQjfBBdcI0ZLysjvRStI8gX7vm1c3CI6CC03lgkUztH+Chcq9C4LI9m2M8mXza8Xkn9ryeKAmX36Bx/yoVzg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 10" + } + }, + "node_modules/solana-bankrun-linux-x64-musl": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/solana-bankrun-linux-x64-musl/-/solana-bankrun-linux-x64-musl-0.2.0.tgz", + "integrity": "sha512-8mtf14ZBoah30+MIJBUwb5BlGLRZyK5cZhCkYnC/ROqaIDN8RxMM44NL63gTUIaNHsFwWGA9xR0KSeljeh3PKQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 10" + } + }, + "node_modules/solana-bankrun/node_modules/base-x": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.10.tgz", + "integrity": "sha512-7d0s06rR9rYaIWHkpfLIFICM/tkSVdoPC9qYAQRpxn9DdKNWNsKC0uk++akckyLq16Tx2WIinnZ6WRriAt6njQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/solana-bankrun/node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "license": "MIT", + "peer": true, + "dependencies": { + "base-x": "^3.0.2" + } + }, "node_modules/source-map": { "version": "0.8.0-beta.0", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", @@ -8098,6 +8055,12 @@ "node": ">=8.0" } }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", + "license": "MIT" + }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", @@ -8285,23 +8248,6 @@ } } }, - "node_modules/tsup/node_modules/@esbuild/darwin-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", - "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, "node_modules/tsup/node_modules/bundle-require": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/bundle-require/-/bundle-require-5.0.0.tgz", @@ -8318,46 +8264,6 @@ "esbuild": ">=0.18" } }, - "node_modules/tsup/node_modules/esbuild": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", - "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "@esbuild/aix-ppc64": "0.23.1", - "@esbuild/android-arm": "0.23.1", - "@esbuild/android-arm64": "0.23.1", - "@esbuild/android-x64": "0.23.1", - "@esbuild/darwin-arm64": "0.23.1", - "@esbuild/darwin-x64": "0.23.1", - "@esbuild/freebsd-arm64": "0.23.1", - "@esbuild/freebsd-x64": "0.23.1", - "@esbuild/linux-arm": "0.23.1", - "@esbuild/linux-arm64": "0.23.1", - "@esbuild/linux-ia32": "0.23.1", - "@esbuild/linux-loong64": "0.23.1", - "@esbuild/linux-mips64el": "0.23.1", - "@esbuild/linux-ppc64": "0.23.1", - "@esbuild/linux-riscv64": "0.23.1", - "@esbuild/linux-s390x": "0.23.1", - "@esbuild/linux-x64": "0.23.1", - "@esbuild/netbsd-x64": "0.23.1", - "@esbuild/openbsd-arm64": "0.23.1", - "@esbuild/openbsd-x64": "0.23.1", - "@esbuild/sunos-x64": "0.23.1", - "@esbuild/win32-arm64": "0.23.1", - "@esbuild/win32-ia32": "0.23.1", - "@esbuild/win32-x64": "0.23.1" - } - }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", diff --git a/package.json b/package.json index a828465..4770560 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "sideEffects": false, "scripts": { "build": "npm run build:esm && npm run build:cjs", - "build:esm": "tsc", + "build:esm": "tsc -p tsconfig.json", "build:cjs": "tsc -p tsconfig.cjs.json", "clean": "rm -rf dist", - "test": "esrun src/index.test.ts", - "typecheck": "tsc --noEmit" + "test": "cd tests && npm run test", + "test:ci": "cd tests && npm run test:ci" }, "keywords": [ "solana", @@ -48,17 +48,22 @@ ], "license": "MIT", "dependencies": { + "@coral-xyz/anchor": "^0.30.1", "@solana/spl-token": "^0.4.8", "@solana/spl-token-metadata": "^0.1.4", "@solana/web3.js": "^1.95.2", + "anchor-bankrun": "^0.4.0", + "bn.js": "^5.2.1", "bs58": "^6.0.0", "dotenv": "^16.4.5" }, "devDependencies": { + "@types/bn.js": "^5.1.5", "@types/jest": "^29.5.12", "@types/node": "^20.16.1", "c8": "^10.1.2", - "esrun": "^3.2.26", + "esbuild": "^0.23.1", + "esbuild-register": "^3.6.0", "prettier": "^3.0.3", "ts-jest": "^29.2.5", "tsup": "^8.2.4", diff --git a/tests/bankrun_test/tests/bankrun.test.ts b/tests/bankrun_test/tests/bankrun.test.ts new file mode 100644 index 0000000..74f14b4 --- /dev/null +++ b/tests/bankrun_test/tests/bankrun.test.ts @@ -0,0 +1,51 @@ +import * as anchor from "@coral-xyz/anchor"; +import { Program } from "@coral-xyz/anchor"; +import { BankrunTest } from "../target/types/bankrun_test"; +import { BanksClient, startAnchor } from "solana-bankrun"; +import { BankrunProvider } from "anchor-bankrun"; +import { + PublicKey, + sendAndConfirmTransaction, + Transaction, +} from "@solana/web3.js"; +import { BankrunContextWrapper } from "../../../src/index"; +import { assert } from "chai"; +import { describe, it } from "node:test"; + +const IDL = require("../target/idl/bankrun_test.json"); +const PROGRAM_ID = new PublicKey(IDL.address); + +describe("bankrun_test", async () => { + const context = await startAnchor( + "", + [{ name: "bankrun_test", programId: PROGRAM_ID }], + [] + ); + const provider = new BankrunProvider(context); + const wallet = provider.wallet as anchor.Wallet; + const bankrunContextWrapper = new BankrunContextWrapper(context); + const connection = bankrunContextWrapper.connection.toConnection(); + const program = new anchor.Program(IDL, provider); + const client = context.banksClient; + + it("Is initialized!", async () => { + const ix = await program.methods.initialize().instruction(); + const tx = new Transaction().add(ix); + const { blockhash, lastValidBlockHeight } = + await connection.getLatestBlockhash(); + const sig = await sendAndConfirmTransaction(connection, tx, [wallet.payer]); + const status = await client.getTransactionStatus(sig); + + assert(typeof blockhash === "string", "blockhash is not a string"); + assert( + typeof lastValidBlockHeight === "number", + "lastValidBlockHeight is not a number" + ); + assert( + typeof sig === "string", + "Signature from transaction is not a string" + ); + console.log() + assert.ok(status.confirmationStatus !== "confirmed", "Txn wasn't confirmed"); + }); +}); diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..f939223 --- /dev/null +++ b/tests/package.json @@ -0,0 +1,10 @@ +{ + "scripts": { + "clean": "rm -rf dist", + "test": "npm run test:esm", + "test:ci": "npm run test:cjs && npm run test:esm", + "pretest:cjs": "npm run clean && tsc -p tsconfig.test.json", + "test:cjs": "node --test dist/tests/src/**/*.test.js", + "test:esm": "node --test --require esbuild-register src/**" + } +} diff --git a/tests/airdrop.test.ts b/tests/src/airdrop.test.ts similarity index 96% rename from tests/airdrop.test.ts rename to tests/src/airdrop.test.ts index ee443c0..d5f8371 100644 --- a/tests/airdrop.test.ts +++ b/tests/src/airdrop.test.ts @@ -1,5 +1,6 @@ +import { describe, test } from "node:test"; import { Connection } from "@solana/web3.js"; -import { airdropIfRequired, initializeKeypair, InitializeKeypairOptions } from "../src"; +import { airdropIfRequired, initializeKeypair, type InitializeKeypairOptions } from "../../src"; import assert from "node:assert"; import dotenv from "dotenv"; import { unlink as deleteFile } from "node:fs/promises" @@ -135,4 +136,4 @@ describe("airdropIfRequired", () => { // Check second airdrop happened assert.equal(finalBalance, 2 * LAMPORTS_PER_SOL - 1); }); -}); \ No newline at end of file +}); diff --git a/tests/explorer.test.ts b/tests/src/explorer.test.ts similarity index 95% rename from tests/explorer.test.ts rename to tests/src/explorer.test.ts index 776738b..1fdc469 100644 --- a/tests/explorer.test.ts +++ b/tests/src/explorer.test.ts @@ -1,4 +1,5 @@ -import { getExplorerLink } from "../src"; +import { getExplorerLink } from "../../src/index.js"; +import { describe, test } from "node:test"; import assert from "node:assert"; describe("getExplorerLink", () => { @@ -64,4 +65,4 @@ describe("getExplorerLink", () => { "https://explorer.solana.com/tx/2QC8BkDVZgaPHUXG9HuPw7aE5d6kN5DTRXLe2inT1NzurkYTCFhraSEo883CPNe18BZ2peJC1x1nojZ5Jmhs94pL?cluster=custom&customUrl=http%3A%2F%2Flocalhost%3A8899", ); }); -}); \ No newline at end of file +}); diff --git a/tests/keypair.test.ts b/tests/src/keypair.test.ts similarity index 84% rename from tests/keypair.test.ts rename to tests/src/keypair.test.ts index 14c0da9..247dacd 100644 --- a/tests/keypair.test.ts +++ b/tests/src/keypair.test.ts @@ -1,21 +1,22 @@ +import { describe, test, before } from "node:test"; import assert from "node:assert"; -import { addKeypairToEnvFile, getKeypairFromEnvironment, getKeypairFromFile, makeKeypairs } from "../src"; +import { addKeypairToEnvFile, getKeypairFromEnvironment, getKeypairFromFile, makeKeypairs } from "../../src"; import { Keypair } from "@solana/web3.js"; import base58 from "bs58"; // See https://m.media-amazon.com/images/I/51TJeGHxyTL._SY445_SX342_.jpg -import { exec as execNoPromises } from "child_process"; +import { exec as execNoPromises } from "node:child_process"; import { promisify } from "node:util"; import { writeFile, unlink as deleteFile } from "node:fs/promises"; import dotenv from "dotenv"; const exec = promisify(execNoPromises); -const TEMP_DIR = "tests/temp"; +const TEMP_DIR = "temp"; describe("addKeypairToEnvFile", () => { - let TEST_ENV_VAR_ARRAY_OF_NUMBERS = "TEST_ENV_VAR_ARRAY_OF_NUMBERS"; + const TEST_ENV_VAR_ARRAY_OF_NUMBERS = "TEST_ENV_VAR_ARRAY_OF_NUMBERS"; let testKeypair: Keypair; - beforeAll(async () => { + before(async () => { testKeypair = Keypair.generate(); process.env[TEST_ENV_VAR_ARRAY_OF_NUMBERS] = JSON.stringify( @@ -32,7 +33,7 @@ describe("addKeypairToEnvFile", () => { dotenv.config({ path: envFileName }); // Get the secret from the .env file - const secretKeyString = process.env["TEMP_KEYPAIR"]; + const secretKeyString = process.env.TEMP_KEYPAIR; if (!secretKeyString) { throw new Error("TEMP_KEYPAIR not found in environment"); @@ -72,10 +73,10 @@ describe("makeKeypairs", () => { }); describe("getKeypairFromFile", () => { - let TEST_FILE_NAME = `${TEMP_DIR}/test-keyfile-do-not-use.json`; - let MISSING_FILE_NAME = "THIS FILE DOES NOT EXIST"; - let CORRUPT_TEST_FILE_NAME = `${TEMP_DIR}/corrupt-keyfile-do-not-use.json`; - beforeAll(async () => { + const TEST_FILE_NAME = `${TEMP_DIR}/test-keyfile-do-not-use.json`; + const MISSING_FILE_NAME = "THIS FILE DOES NOT EXIST"; + const CORRUPT_TEST_FILE_NAME = `${TEMP_DIR}/corrupt-keyfile-do-not-use.json`; + before(async () => { const { stdout } = await exec( `solana-keygen new --force --no-bip39-passphrase -o ${TEST_FILE_NAME}`, ); @@ -102,11 +103,11 @@ describe("getKeypairFromFile", () => { }); describe("getKeypairFromEnvironment", () => { - let TEST_ENV_VAR_ARRAY_OF_NUMBERS = "TEST_ENV_VAR_ARRAY_OF_NUMBERS"; - let TEST_ENV_VAR_BASE58 = "TEST_ENV_VAR_BASE58"; - let TEST_ENV_VAR_WITH_BAD_VALUE = "TEST_ENV_VAR_WITH_BAD_VALUE"; + const TEST_ENV_VAR_ARRAY_OF_NUMBERS = "TEST_ENV_VAR_ARRAY_OF_NUMBERS"; + const TEST_ENV_VAR_BASE58 = "TEST_ENV_VAR_BASE58"; + const TEST_ENV_VAR_WITH_BAD_VALUE = "TEST_ENV_VAR_WITH_BAD_VALUE"; - beforeAll(async () => { + before(async () => { const randomKeypair = Keypair.generate(); process.env[TEST_ENV_VAR_ARRAY_OF_NUMBERS] = JSON.stringify( diff --git a/tests/logs.test.ts b/tests/src/logs.test.ts similarity index 90% rename from tests/logs.test.ts rename to tests/src/logs.test.ts index 02e5991..444696b 100644 --- a/tests/logs.test.ts +++ b/tests/src/logs.test.ts @@ -1,5 +1,6 @@ +import { describe, test } from "node:test"; import { Connection } from "@solana/web3.js"; -import { airdropIfRequired, getCustomErrorMessage, getLogs } from "../src"; +import { airdropIfRequired, getCustomErrorMessage, getLogs } from "../../src"; import { LAMPORTS_PER_SOL } from "@solana/web3.js"; import { Keypair } from "@solana/web3.js"; import { Transaction } from "@solana/web3.js"; @@ -8,8 +9,8 @@ import assert from "node:assert"; const LOCALHOST = "http://127.0.0.1:8899"; -describe(`getLogs`, () => { - test(`getLogs works`, async () => { +describe("getLogs", () => { + test("getLogs works", async () => { const connection = new Connection(LOCALHOST); const [sender, recipient] = [Keypair.generate(), Keypair.generate()]; const lamportsToAirdrop = 2 * LAMPORTS_PER_SOL; @@ -40,8 +41,8 @@ describe(`getLogs`, () => { }); -describe(`getCustomErrorMessage`, () => { - test(`we turn error messages with hex codes into error messages for the program`, () => { +describe("getCustomErrorMessage", () => { + test("we turn error messages with hex codes into error messages for the program", () => { // This example set of error is from the token program // https://github.com/solana-labs/solana-program-library/blob/master/token/program/src/error.rs const programErrors = [ diff --git a/tests/token.test.ts b/tests/src/token.test.ts similarity index 98% rename from tests/token.test.ts rename to tests/src/token.test.ts index 6860193..6e3dfe6 100644 --- a/tests/token.test.ts +++ b/tests/src/token.test.ts @@ -1,5 +1,6 @@ +import { describe, test } from "node:test"; import { LAMPORTS_PER_SOL } from "@solana/web3.js"; -import { airdropIfRequired, createAccountsMintsAndTokenAccounts, makeTokenMint } from "../src"; +import { airdropIfRequired, createAccountsMintsAndTokenAccounts, makeTokenMint } from "../../src"; import { Connection } from "@solana/web3.js"; import { Keypair } from "@solana/web3.js"; import { getTokenMetadata } from "@solana/spl-token"; diff --git a/tests/transaction.test.ts b/tests/src/transaction.test.ts similarity index 97% rename from tests/transaction.test.ts rename to tests/src/transaction.test.ts index 17177d7..3bf0481 100644 --- a/tests/transaction.test.ts +++ b/tests/src/transaction.test.ts @@ -1,7 +1,8 @@ +import { describe, test } from "node:test"; import { Keypair } from "@solana/web3.js"; import { LAMPORTS_PER_SOL } from "@solana/web3.js"; import { Connection } from "@solana/web3.js"; -import { airdropIfRequired, confirmTransaction, getSimulationComputeUnits } from "../src"; +import { airdropIfRequired, confirmTransaction, getSimulationComputeUnits } from "../../src"; import { sendAndConfirmTransaction } from "@solana/web3.js"; import { Transaction } from "@solana/web3.js"; import { SystemProgram } from "@solana/web3.js"; diff --git a/tests/tsconfig.test.json b/tests/tsconfig.test.json new file mode 100644 index 0000000..3626865 --- /dev/null +++ b/tests/tsconfig.test.json @@ -0,0 +1,20 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "target": "ES2022", + "moduleResolution": "node", + "rootDir": "../", + "outDir": "../tests/dist", + "types": ["node"], + "esModuleInterop": true + }, + "include": ["src/**/*", "tests/src/*"], + "exclude": [ + "node_modules", + "dist", + "tests/bankrun_test", + "coverage/**", + "**/*.d.ts" + ] +} \ No newline at end of file diff --git a/tsconfig.test.json b/tsconfig.test.json deleted file mode 100644 index f6339bb..0000000 --- a/tsconfig.test.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "types": ["node", "jest"], - "module": "ESNext", - "moduleResolution": "node", - "target": "ES2022", - "noEmit": true, - "allowImportingTsExtensions": true - }, - "include": ["src/**/*", "tests/**/*"], - "exclude": [ - "node_modules", - "dist", - "tests/bankrun_test", - "coverage/**", - "**/*.d.ts", - ] -}