From 317842dc9b839aae7685aeecf45af89e0419d92d Mon Sep 17 00:00:00 2001 From: ethan-57blocks Date: Thu, 29 Feb 2024 18:09:48 +0800 Subject: [PATCH] house keeping --- .env.example | 9 + config/config.ts | 54 ++++++ {script => config}/mintAbi.json | 0 package.json | 21 +- pnpm-lock.yaml | 286 ++++++++++++++++++++++++++++ test/e2e/e2e.ts | 30 +++ {script => test/e2e/flows}/flow1.ts | 4 +- {script => test/e2e/flows}/flow2.ts | 4 +- {script => test/e2e/flows}/flow3.ts | 4 +- {script => test/e2e/flows}/flow4.ts | 4 +- {script => test/e2e/flows}/flow5.ts | 4 +- {script => test/e2e/flows}/flow6.ts | 4 +- tsconfig.json | 30 +++ {script => utils}/utils.ts | 92 ++++----- 14 files changed, 472 insertions(+), 74 deletions(-) create mode 100644 .env.example create mode 100644 config/config.ts rename {script => config}/mintAbi.json (100%) create mode 100644 test/e2e/e2e.ts rename {script => test/e2e/flows}/flow1.ts (83%) rename {script => test/e2e/flows}/flow2.ts (85%) rename {script => test/e2e/flows}/flow3.ts (89%) rename {script => test/e2e/flows}/flow4.ts (81%) rename {script => test/e2e/flows}/flow5.ts (93%) rename {script => test/e2e/flows}/flow6.ts (96%) create mode 100644 tsconfig.json rename {script => utils}/utils.ts (72%) diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cb8ffa8 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +TEST_WALLET_A_ADDRESS = 0x0000000000000000000000000000000000000000 +TEST_WALLET_B_ADDRESS = 0x0000000000000000000000000000000000000000 +TEST_WALLET_C_ADDRESS = 0x0000000000000000000000000000000000000000 +PRIVATE_KEYS = privateKey1,privateKey2,privateKey3 +NFT_CONTRACT_ADDRESS = 0x0000000000000000000000000000000000000000 +RPC_URL = https://rpc.ankr.com/eth_sepolia +LICENSE_MODULE = 0x0000000000000000000000000000000000000000 +MINT_FEE_TOKEN = 0x0000000000000000000000000000000000000000 +ROYALTY_POLICY = 0x0000000000000000000000000000000000000000 \ No newline at end of file diff --git a/config/config.ts b/config/config.ts new file mode 100644 index 0000000..d62a598 --- /dev/null +++ b/config/config.ts @@ -0,0 +1,54 @@ +import "dotenv/config"; +import { + Hex, + createWalletClient, + http, + PrivateKeyAccount, +} from "viem"; +import { privateKeyToAccount } from "viem/accounts"; +import { StoryClient, StoryConfig } from "@story-protocol/core-sdk"; + +import { sepolia } from "viem/chains"; + +export const getStoryConfig = (account: PrivateKeyAccount) => ({ + transport: http(RPC_URL), + account, +}) as StoryConfig; + +export const TOKEN_CONTRACT_ADDRESS = "0x7ee32b8B515dEE0Ba2F25f612A04a731eEc24F49"; +export const TEST_WALLET_A_ADDRESS = (process.env.TEST_WALLET_A_ADDRESS || "0x") as `0x${string}`; +export const TEST_WALLET_B_ADDRESS = (process.env.TEST_WALLET_B_ADDRESS || "0x") as `0x${string}`; +export const TEST_WALLET_C_ADDRESS = (process.env.TEST_WALLET_C_ADDRESS || "0x") as `0x${string}`; +export const NFT_CONTRACT_ADDRESS = (process.env.NFT_CONTRACT_ADDRESS || "0x") as `0x${string}`; +export const RPC_URL = process.env.RPC_URL || ""; +export const LICENSE_MODULE = (process.env.LICENSE_MODULE || "") as `0x${string}`; +export const MINT_FEE_TOKEN = (process.env.MINT_FEE_TOKEN || "") as `0x${string}`; +export const ROYALTY_POLICY = (process.env.ROYALTY_POLICY || "") as `0x${string}`; + +export const accountA = privateKeyToAccount((process.env.PRIVATE_KEYS?.split(',')[0] || '0x') as Hex); +export const accountB = privateKeyToAccount((process.env.PRIVATE_KEYS?.split(',')[1] || '0x') as Hex); +export const accountC = privateKeyToAccount((process.env.PRIVATE_KEYS?.split(',')[2] || '0x') as Hex); + +const configA: StoryConfig = getStoryConfig(accountA); +const configB: StoryConfig = getStoryConfig(accountB); +const configC: StoryConfig = getStoryConfig(accountC); + +export const storyClientA: StoryClient = StoryClient.newClient(configA); +export const storyClientB: StoryClient = StoryClient.newClient(configB); +export const storyClientC: StoryClient = StoryClient.newClient(configC); + +export const walletClientA = createWalletClient({ + transport: http(RPC_URL), + chain: sepolia, + account: accountA, +}); +export const walletClientB = createWalletClient({ + transport: http(RPC_URL), + chain: sepolia, + account: accountB, +}); +export const walletClientC = createWalletClient({ + transport: http(RPC_URL), + chain: sepolia, + account: accountC, +}); diff --git a/script/mintAbi.json b/config/mintAbi.json similarity index 100% rename from script/mintAbi.json rename to config/mintAbi.json diff --git a/package.json b/package.json index 2924985..3d69abd 100644 --- a/package.json +++ b/package.json @@ -3,29 +3,36 @@ "version": "1.0.0", "description": "", "main": "index.js", + "type": "module", "scripts": { - "test:flow1": "node -e 'require(\"./script/flow1.ts\").testFlow1()'", - "test:flow2": "node -e 'require(\"./script/flow2.ts\").testFlow3()'", - "test:flow3": "node -e 'require(\"./script/flow3.ts\").testFlow3()'", - "test:all": "npm-run-all test:flow1 test:flow2 test:flow3" + "test:flow1": "TEST_FLOWS=flow1 tsx test/e2e/e2e.ts", + "test:flow2": "TEST_FLOWS=flow2 tsx test/e2e/e2e.ts", + "test:flow3": "TEST_FLOWS=flow3 tsx test/e2e/e2e.ts", + "test:flow4": "TEST_FLOWS=flow4 tsx test/e2e/e2e.ts", + "test:flow5": "TEST_FLOWS=flow5 tsx test/e2e/e2e.ts", + "test:flow6": "TEST_FLOWS=flow6 tsx test/e2e/e2e.ts", + "test:all": "TEST_FLOWS=flow1,flow2,flow3,flow4,flow5,flow6 tsx test/e2e/e2e.ts" }, "engines": { "node": "20.0.0" }, "repository": { "type": "git", - "url": "git+https://github.com/storyprotocol/sdk-e2e-tests.git" + "url": "https://github.com/storyprotocol/sdk-e2e-tests.git" }, "dependencies": { "@story-protocol/core-sdk": "0.0.1-beta-rc.9", + "dotenv": "^16.4.5", + "tsx": "^4.7.1", "viem": "^1.18.4" }, "devDependencies": { + "@types/node": "^20.11.22", "npm-run-all": "^4.1.5", "typescript": "^5.2.2" }, - "author": "", - "license": "ISC", + "author": "storyprotocol engineering ", + "license": "MIT", "bugs": { "url": "https://github.com/storyprotocol/sdk-e2e-tests/issues" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e68826d..9cc7904 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,11 +8,20 @@ dependencies: '@story-protocol/core-sdk': specifier: 0.0.1-beta-rc.9 version: 0.0.1-beta-rc.9(typescript@5.3.3) + dotenv: + specifier: ^16.4.5 + version: 16.4.5 + tsx: + specifier: ^4.7.1 + version: 4.7.1 viem: specifier: ^1.18.4 version: 1.21.4(typescript@5.3.3) devDependencies: + '@types/node': + specifier: ^20.11.22 + version: 20.11.22 npm-run-all: specifier: ^4.1.5 version: 4.1.5 @@ -26,6 +35,213 @@ packages: resolution: {integrity: sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==} dev: false + /@esbuild/aix-ppc64@0.19.12: + resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [aix] + requiresBuild: true + dev: false + optional: true + + /@esbuild/android-arm64@0.19.12: + resolution: {integrity: sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/android-arm@0.19.12: + resolution: {integrity: sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/android-x64@0.19.12: + resolution: {integrity: sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/darwin-arm64@0.19.12: + resolution: {integrity: sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@esbuild/darwin-x64@0.19.12: + resolution: {integrity: sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@esbuild/freebsd-arm64@0.19.12: + resolution: {integrity: sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/freebsd-x64@0.19.12: + resolution: {integrity: sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-arm64@0.19.12: + resolution: {integrity: sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-arm@0.19.12: + resolution: {integrity: sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-ia32@0.19.12: + resolution: {integrity: sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-loong64@0.19.12: + resolution: {integrity: sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-mips64el@0.19.12: + resolution: {integrity: sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-ppc64@0.19.12: + resolution: {integrity: sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-riscv64@0.19.12: + resolution: {integrity: sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-s390x@0.19.12: + resolution: {integrity: sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-x64@0.19.12: + resolution: {integrity: sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/netbsd-x64@0.19.12: + resolution: {integrity: sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/openbsd-x64@0.19.12: + resolution: {integrity: sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/sunos-x64@0.19.12: + resolution: {integrity: sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: false + optional: true + + /@esbuild/win32-arm64@0.19.12: + resolution: {integrity: sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@esbuild/win32-ia32@0.19.12: + resolution: {integrity: sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@esbuild/win32-x64@0.19.12: + resolution: {integrity: sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@noble/curves@1.2.0: resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} dependencies: @@ -71,6 +287,12 @@ packages: - zod dev: false + /@types/node@20.11.22: + resolution: {integrity: sha512-/G+IxWxma6V3E+pqK1tSl2Fo1kl41pK1yeCyDsgkF9WlVAme4j5ISYM2zR11bgLFJGLN5sVK40T4RJNuiZbEjA==} + dependencies: + undici-types: 5.26.5 + dev: true + /abitype@0.10.3(typescript@5.3.3): resolution: {integrity: sha512-tRN+7XIa7J9xugdbRzFv/95ka5ivR/sRe01eiWvM0HWWjHuigSZEACgKa0sj4wGuekTDtghCx+5Izk/cOi78pQ==} peerDependencies: @@ -323,6 +545,37 @@ packages: is-symbol: 1.0.4 dev: true + /esbuild@0.19.12: + resolution: {integrity: sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/aix-ppc64': 0.19.12 + '@esbuild/android-arm': 0.19.12 + '@esbuild/android-arm64': 0.19.12 + '@esbuild/android-x64': 0.19.12 + '@esbuild/darwin-arm64': 0.19.12 + '@esbuild/darwin-x64': 0.19.12 + '@esbuild/freebsd-arm64': 0.19.12 + '@esbuild/freebsd-x64': 0.19.12 + '@esbuild/linux-arm': 0.19.12 + '@esbuild/linux-arm64': 0.19.12 + '@esbuild/linux-ia32': 0.19.12 + '@esbuild/linux-loong64': 0.19.12 + '@esbuild/linux-mips64el': 0.19.12 + '@esbuild/linux-ppc64': 0.19.12 + '@esbuild/linux-riscv64': 0.19.12 + '@esbuild/linux-s390x': 0.19.12 + '@esbuild/linux-x64': 0.19.12 + '@esbuild/netbsd-x64': 0.19.12 + '@esbuild/openbsd-x64': 0.19.12 + '@esbuild/sunos-x64': 0.19.12 + '@esbuild/win32-arm64': 0.19.12 + '@esbuild/win32-ia32': 0.19.12 + '@esbuild/win32-x64': 0.19.12 + dev: false + /escape-string-regexp@1.0.5: resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==} engines: {node: '>=0.8.0'} @@ -353,6 +606,14 @@ packages: mime-types: 2.1.35 dev: false + /fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + requiresBuild: true + dev: false + optional: true + /function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} dev: true @@ -391,6 +652,12 @@ packages: get-intrinsic: 1.2.4 dev: true + /get-tsconfig@4.7.2: + resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} + dependencies: + resolve-pkg-maps: 1.0.0 + dev: false + /globalthis@1.0.3: resolution: {integrity: sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA==} engines: {node: '>= 0.4'} @@ -722,6 +989,10 @@ packages: set-function-name: 2.0.2 dev: true + /resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + dev: false + /resolve@1.22.8: resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} hasBin: true @@ -876,6 +1147,17 @@ packages: engines: {node: '>= 0.4'} dev: true + /tsx@4.7.1: + resolution: {integrity: sha512-8d6VuibXHtlN5E3zFkgY8u4DX7Y3Z27zvvPKVmLon/D4AjuKzarkUBTLDBgj9iTQ0hg5xM7c/mYiRVM+HETf0g==} + engines: {node: '>=18.0.0'} + hasBin: true + dependencies: + esbuild: 0.19.12 + get-tsconfig: 4.7.2 + optionalDependencies: + fsevents: 2.3.3 + dev: false + /typed-array-buffer@1.0.2: resolution: {integrity: sha512-gEymJYKZtKXzzBzM4jqa9w6Q1Jjm7x2d+sh19AdsD4wqnMPDYyvwpsIc2Q/835kHuo3BEQ7CjelGhfTsoBb2MQ==} engines: {node: '>= 0.4'} @@ -934,6 +1216,10 @@ packages: which-boxed-primitive: 1.0.2 dev: true + /undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + dev: true + /validate-npm-package-license@3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} dependencies: diff --git a/test/e2e/e2e.ts b/test/e2e/e2e.ts new file mode 100644 index 0000000..e2ac155 --- /dev/null +++ b/test/e2e/e2e.ts @@ -0,0 +1,30 @@ +import testFlow1 from './flows/flow1'; +import testFlow2 from './flows/flow2'; +import testFlow3 from './flows/flow3'; +import testFlow4 from './flows/flow4'; +import testFlow5 from './flows/flow5'; +import testFlow6 from './flows/flow6'; + +type flowsTestMapType = { + [key: string]: Function +} +const flowsTestMap: flowsTestMapType = { + flow1: testFlow1, + flow2: testFlow2, + flow3: testFlow3, + flow4: testFlow4, + flow5: testFlow5, + flow6: testFlow6, +} +process.env.TEST_FLOWS?.split(',').forEach(async (flow: keyof flowsTestMapType) => { + if(flowsTestMap[flow]) { + try { + console.log(`testing ${flow}...`); + await flowsTestMap[flow](); + console.log(`${flow} succeeded`); + } catch (err) { + console.log(`${flow} failed with error: ${(err as Error).message}`); + throw new Error(`${flow} failed with error: ${(err as Error).message}`); + } + } +}) \ No newline at end of file diff --git a/script/flow1.ts b/test/e2e/flows/flow1.ts similarity index 83% rename from script/flow1.ts rename to test/e2e/flows/flow1.ts index 7576d86..dfc626b 100644 --- a/script/flow1.ts +++ b/test/e2e/flows/flow1.ts @@ -1,7 +1,7 @@ import { Hex } from 'viem'; -import { mintNFT, registerRootIp, registerSocialRemixPolicy, registerDerivativeIP, mintLicense, sleep } from './utils'; +import { mintNFT, registerRootIp, registerSocialRemixPolicy, registerDerivativeIP, mintLicense, sleep } from '../../../utils/utils'; -export async function testFlow1() { +export default async function testFlow1() { // const NFTIdOfA = await mintNFT('A'); // const NFTIdOfB = await mintNFT('B'); const policyId = await registerSocialRemixPolicy(); diff --git a/script/flow2.ts b/test/e2e/flows/flow2.ts similarity index 85% rename from script/flow2.ts rename to test/e2e/flows/flow2.ts index 56c275c..becc86b 100644 --- a/script/flow2.ts +++ b/test/e2e/flows/flow2.ts @@ -1,7 +1,7 @@ import { Hex } from 'viem'; -import { mintNFT, sleep, registerSocialRemixPolicy, registerRootIp, linkIpToParent, mintLicense } from './utils'; +import { mintNFT, sleep, registerSocialRemixPolicy, registerRootIp, linkIpToParent, mintLicense } from '../../../utils/utils'; -export async function testFlow2() { +export default async function testFlow2() { // const NFTIdOfA = await mintNFT('A'); // const NFTIdOfB = await mintNFT('B'); const policyId = await registerSocialRemixPolicy(); diff --git a/script/flow3.ts b/test/e2e/flows/flow3.ts similarity index 89% rename from script/flow3.ts rename to test/e2e/flows/flow3.ts index cfce76d..e5aa91f 100644 --- a/script/flow3.ts +++ b/test/e2e/flows/flow3.ts @@ -6,9 +6,9 @@ import { registerSocialRemixPolicy, mintLicense, registerDerivativeIP, -} from './utils'; +} from '../../../utils/utils'; -export async function testFlow3() { +export default async function testFlow3() { const policyId = await registerSocialRemixPolicy(); // const NFTIdOfA = await mintNFT('A'); // const NFTIdOfB = await mintNFT('B'); diff --git a/script/flow4.ts b/test/e2e/flows/flow4.ts similarity index 81% rename from script/flow4.ts rename to test/e2e/flows/flow4.ts index 7b84757..647f10f 100644 --- a/script/flow4.ts +++ b/test/e2e/flows/flow4.ts @@ -1,7 +1,7 @@ import { Hex } from 'viem'; -import { mintNFT, sleep, grantIp, registerSocialRemixPolicy, mintLicense, registerRootIp } from './utils'; +import { mintNFT, sleep, grantIp, registerSocialRemixPolicy, mintLicense, registerRootIp } from '../../../utils/utils'; -export async function testFlow4() { +export default async function testFlow4() { const policyId = await registerSocialRemixPolicy(); // const NFTIdOfA = await mintNFT('A'); const NFTIdOfA = '204'; diff --git a/script/flow5.ts b/test/e2e/flows/flow5.ts similarity index 93% rename from script/flow5.ts rename to test/e2e/flows/flow5.ts index 1bbfcb9..7338567 100644 --- a/script/flow5.ts +++ b/test/e2e/flows/flow5.ts @@ -6,9 +6,9 @@ import { registerDerivativeIP, sleep, mintLicense, -} from './utils'; +} from '../../../utils/utils'; -export async function testFlow5() { +export default async function testFlow5() { const policyId = await registerCommercialUsePolicy(); // const NFTIdOfA = await mintNFT('A'); // const NFTIdOfB = await mintNFT('B'); diff --git a/script/flow6.ts b/test/e2e/flows/flow6.ts similarity index 96% rename from script/flow6.ts rename to test/e2e/flows/flow6.ts index 29537d0..9bcbba1 100644 --- a/script/flow6.ts +++ b/test/e2e/flows/flow6.ts @@ -10,9 +10,9 @@ import { addOnePolicyToIp, mintLicense, registerDerivativeIP, -} from './utils'; +} from '../../../utils/utils'; -export async function testFlow6() { +export default async function testFlow6() { // const NFTIdOfA = await mintNFT('A'); // const NFTIdOfB = await mintNFT('B'); const remixPolicyId1 = await registerSocialRemixPolicy(); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2aea5fa --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,30 @@ +{ + "exclude": ["node_modules"], + "compilerOptions": { + "composite": true, + "target": "ES2020", + "module": "ESNext", + "lib": ["dom", "ESNext"], + "importHelpers": true, + "declaration": true, + "sourceMap": true, + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "alwaysStrict": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "esModuleInterop": true, + "skipLibCheck": true, + }, + "ts-node": { + "esm": true, + "experimentalSpecifierResolution": "node" + }, + "include": ["test", "config", "utils"], +} \ No newline at end of file diff --git a/script/utils.ts b/utils/utils.ts similarity index 72% rename from script/utils.ts rename to utils/utils.ts index 249f5c2..104e836 100644 --- a/script/utils.ts +++ b/utils/utils.ts @@ -1,64 +1,46 @@ -import { createWalletClient, Hex, http } from 'viem'; -import { privateKeyToAccount } from 'viem/accounts'; -import { sepolia } from 'viem/chains'; -import { StoryClient } from '@story-protocol/core-sdk'; +import { http, Hex } from "viem"; +import { PrivateKeyAccount } from 'viem/accounts'; import type { StoryConfig } from '@story-protocol/core-sdk'; +import { sepolia } from 'viem/chains'; +import { + walletClientA, + walletClientB, + walletClientC, + accountA, + accountB, + accountC, + storyClientA, + storyClientB, + storyClientC, + TEST_WALLET_A_ADDRESS, + TEST_WALLET_B_ADDRESS, + TEST_WALLET_C_ADDRESS, + NFT_CONTRACT_ADDRESS, + MINT_FEE_TOKEN, + ROYALTY_POLICY, + LICENSE_MODULE, + RPC_URL, +} from '../config/config'; export type Who = 'A' | 'B' | 'C'; -export const accountA = privateKeyToAccount((import.meta.env.VITE_PRIVATE_KEYS?.split(',')[0] || '0x') as Hex); -export const accountB = privateKeyToAccount((import.meta.env.VITE_PRIVATE_KEYS?.split(',')[1] || '0x') as Hex); -export const accountC = privateKeyToAccount((import.meta.env.VITE_PRIVATE_KEYS?.split(',')[2] || '0x') as Hex); -const configA: StoryConfig = { - transport: http(import.meta.env.VITE_RPC_URL), - account: accountA, -}; -const configB: StoryConfig = { - transport: http(import.meta.env.VITE_RPC_URL), - account: accountB, -}; -const configC: StoryConfig = { - transport: http(import.meta.env.VITE_RPC_URL), - account: accountC, -}; - -export const clientA = createWalletClient({ - transport: http('https://rpc.ankr.com/eth_sepolia'), - chain: sepolia, - account: accountA, -}); -export const clientB = createWalletClient({ - transport: http('https://rpc.ankr.com/eth_sepolia'), - chain: sepolia, - account: accountB, -}); -export const clientC = createWalletClient({ - transport: http('https://rpc.ankr.com/eth_sepolia'), - chain: sepolia, - account: accountC, -}); - -export const storyClientA = StoryClient.newClient(configA); -export const storyClientB = StoryClient.newClient(configB); -export const storyClientC = StoryClient.newClient(configC); - export async function mintNFT(who: Who) { - let client = clientA; + let client = walletClientA; let account = accountA; if (who === 'B') { - client = clientB; + client = walletClientB; account = accountB; } if (who === 'C') { - client = clientC; + client = walletClientC; account = accountC; } const hash = await client.writeContract({ account, - address: import.meta.env.VITE_NFT_CONTRACT, + address: (NFT_CONTRACT_ADDRESS || '0x') as `0x${string}`, chain: sepolia, abi: [], - functionName: 'mint', + functionName: 'mint' as never, args: [], }); @@ -74,9 +56,9 @@ function getStoryClient(who?: Who) { } function getReceiverAddress(receiver?: Who) { - let receiverAddress = import.meta.env.VITE_WALLET_A_ADDRESS; - if (receiver === 'B') receiverAddress = import.meta.env.VITE_WALLET_B_ADDRESS; - if (receiver === 'C') receiverAddress = import.meta.env.VITE_WALLET_C_ADDRESS; + let receiverAddress = TEST_WALLET_A_ADDRESS; + if (receiver === 'B') receiverAddress = TEST_WALLET_B_ADDRESS; + if (receiver === 'C') receiverAddress = TEST_WALLET_C_ADDRESS; return receiverAddress; } @@ -87,7 +69,7 @@ export function sleep(second: number) { export const registerRootIp = async (tokenId: string, who: Who = 'A') => { const storyClient = getStoryClient(who); const response = await storyClient.ipAsset.registerRootIp({ - tokenContractAddress: import.meta.env.VITE_NFT_CONTRACT, + tokenContractAddress: NFT_CONTRACT_ADDRESS, tokenId, txOptions: { waitForTransaction: true, @@ -101,7 +83,7 @@ export const registerIpWithExistingPolicy = async (tokenId: string, policyId: st const storyClient = getStoryClient(who); const response = await storyClient.ipAsset.registerRootIp({ policyId, - tokenContractAddress: import.meta.env.VITE_NFT_CONTRACT, + tokenContractAddress: NFT_CONTRACT_ADDRESS, tokenId, txOptions: { waitForTransaction: true, @@ -163,9 +145,9 @@ export const registerSocialRemixPolicy3 = async () => { export const registerCommercialUsePolicy = async () => { const response = await storyClientA.policy.registerPILPolicy({ transferable: true, - mintingFeeToken: import.meta.env.VITE_MINT_FEE_TOKEN, + mintingFeeToken: MINT_FEE_TOKEN, mintingFee: '1000000000000000000', - royaltyPolicy: import.meta.env.VITE_ROYALTY_POLICY, + royaltyPolicy: ROYALTY_POLICY, commercialRevShare: 100, attribution: true, commercialUse: true, @@ -198,7 +180,7 @@ export const grantIp = async (ipId: Hex, receiver: Who = 'B', promoter: Who = 'A const response = await storyClient.permission.setPermission({ ipId, signer: receiverAddress, - to: import.meta.env.VITE_LICENSE_MODULE, + to: LICENSE_MODULE, func: '0x00000000', // permission level can be 0 (ABSTAIN), 1 (ALLOW), or * 2 (DENY) permission: 1, @@ -241,7 +223,7 @@ export const registerDerivativeIP = async (tokenId: string, licenseIds: string[] const storyClient = getStoryClient(who); const response = await storyClient.ipAsset.registerDerivativeIp({ licenseIds, - tokenContractAddress: import.meta.env.VITE_NFT_CONTRACT, + tokenContractAddress: NFT_CONTRACT_ADDRESS, tokenId, txOptions: { waitForTransaction: true, @@ -249,4 +231,4 @@ export const registerDerivativeIP = async (tokenId: string, licenseIds: string[] }); console.log(`${who} RegisterDerivativeIP with licenses ${licenseIds}: `, response); return response.ipId; -}; +}; \ No newline at end of file