From 0fd7d8f0cc5c49c23330b4f1c4de4fdfb87e2ac3 Mon Sep 17 00:00:00 2001 From: Shreyas Patil Date: Fri, 3 Apr 2026 02:26:40 +0530 Subject: [PATCH 1/3] test: add vitest testing infrastructure with 106 unit tests --- package-lock.json | 1190 ++++++++++++++++- package.json | 8 +- src/lib/__tests__/api-response.test.ts | 83 ++ src/lib/__tests__/chain-registry.test.ts | 94 ++ .../__tests__/payment-link-validation.test.ts | 131 ++ src/lib/__tests__/quote-aggregator.test.ts | 184 +++ src/lib/__tests__/token-filter.test.ts | 169 +++ src/lib/__tests__/token-price.test.ts | 73 + src/lib/__tests__/webhooks.test.ts | 112 ++ vitest.config.ts | 20 + 10 files changed, 2059 insertions(+), 5 deletions(-) create mode 100644 src/lib/__tests__/api-response.test.ts create mode 100644 src/lib/__tests__/chain-registry.test.ts create mode 100644 src/lib/__tests__/payment-link-validation.test.ts create mode 100644 src/lib/__tests__/quote-aggregator.test.ts create mode 100644 src/lib/__tests__/token-filter.test.ts create mode 100644 src/lib/__tests__/token-price.test.ts create mode 100644 src/lib/__tests__/webhooks.test.ts create mode 100644 vitest.config.ts diff --git a/package-lock.json b/package-lock.json index acc9ce7..fb7ed05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -63,6 +63,7 @@ "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", + "@vitest/coverage-v8": "^4.1.2", "eslint": "^9", "eslint-config-next": "16.1.6", "eslint-config-prettier": "^10.1.8", @@ -70,7 +71,8 @@ "shadcn": "^3.8.2", "tailwindcss": "^4", "tw-animate-css": "^1.4.0", - "typescript": "^5" + "typescript": "^5", + "vitest": "^4.1.2" } }, "node_modules/@0no-co/graphql.web": { @@ -758,6 +760,16 @@ } } }, + "node_modules/@bcoe/v8-coverage": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz", + "integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@bigmi/core": { "version": "0.6.5", "resolved": "https://registry.npmjs.org/@bigmi/core/-/core-0.6.5.tgz", @@ -7868,6 +7880,16 @@ "@opentelemetry/api": "^1.1.0" } }, + "node_modules/@oxc-project/types": { + "version": "0.122.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.122.0.tgz", + "integrity": "sha512-oLAl5kBpV4w69UtFZ9xqcmTi+GENWOcPF7FCrczTiBbmC0ibXxCwyvZGbO39rCVEuLGAZM84DH0pUIyyv/YJzA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/Boshen" + } + }, "node_modules/@particle-network/analytics": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@particle-network/analytics/-/analytics-1.0.2.tgz", @@ -11998,6 +12020,287 @@ "multiformats": "^9.4.2" } }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.0.0-rc.12.tgz", + "integrity": "sha512-pv1y2Fv0JybcykuiiD3qBOBdz6RteYojRFY1d+b95WVuzx211CRh+ytI/+9iVyWQ6koTh5dawe4S/yRfOFjgaA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.0.0-rc.12.tgz", + "integrity": "sha512-cFYr6zTG/3PXXF3pUO+umXxt1wkRK/0AYT8lDwuqvRC+LuKYWSAQAQZjCWDQpAH172ZV6ieYrNnFzVVcnSflAg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.0.0-rc.12.tgz", + "integrity": "sha512-ZCsYknnHzeXYps0lGBz8JrF37GpE9bFVefrlmDrAQhOEi4IOIlcoU1+FwHEtyXGx2VkYAvhu7dyBf75EJQffBw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.0.0-rc.12.tgz", + "integrity": "sha512-dMLeprcVsyJsKolRXyoTH3NL6qtsT0Y2xeuEA8WQJquWFXkEC4bcu1rLZZSnZRMtAqwtrF/Ib9Ddtpa/Gkge9Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.0.0-rc.12.tgz", + "integrity": "sha512-YqWjAgGC/9M1lz3GR1r1rP79nMgo3mQiiA+Hfo+pvKFK1fAJ1bCi0ZQVh8noOqNacuY1qIcfyVfP6HoyBRZ85Q==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.0.0-rc.12.tgz", + "integrity": "sha512-/I5AS4cIroLpslsmzXfwbe5OmWvSsrFuEw3mwvbQ1kDxJ822hFHIx+vsN/TAzNVyepI/j/GSzrtCIwQPeKCLIg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.0.0-rc.12.tgz", + "integrity": "sha512-V6/wZztnBqlx5hJQqNWwFdxIKN0m38p8Jas+VoSfgH54HSj9tKTt1dZvG6JRHcjh6D7TvrJPWFGaY9UBVOaWPw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.0.0-rc.12.tgz", + "integrity": "sha512-AP3E9BpcUYliZCxa3w5Kwj9OtEVDYK6sVoUzy4vTOJsjPOgdaJZKFmN4oOlX0Wp0RPV2ETfmIra9x1xuayFB7g==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.0.0-rc.12.tgz", + "integrity": "sha512-nWwpvUSPkoFmZo0kQazZYOrT7J5DGOJ/+QHHzjvNlooDZED8oH82Yg67HvehPPLAg5fUff7TfWFHQS8IV1n3og==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.0.0-rc.12.tgz", + "integrity": "sha512-RNrafz5bcwRy+O9e6P8Z/OCAJW/A+qtBczIqVYwTs14pf4iV1/+eKEjdOUta93q2TsT/FI0XYDP3TCky38LMAg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.0.0-rc.12.tgz", + "integrity": "sha512-Jpw/0iwoKWx3LJ2rc1yjFrj+T7iHZn2JDg1Yny1ma0luviFS4mhAIcd1LFNxK3EYu3DHWCps0ydXQ5i/rrJ2ig==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.0.0-rc.12.tgz", + "integrity": "sha512-vRugONE4yMfVn0+7lUKdKvN4D5YusEiPilaoO2sgUWpCvrncvWgPMzK00ZFFJuiPgLwgFNP5eSiUlv2tfc+lpA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.0.0-rc.12.tgz", + "integrity": "sha512-ykGiLr/6kkiHc0XnBfmFJuCjr5ZYKKofkx+chJWDjitX+KsJuAmrzWhwyOMSHzPhzOHOy7u9HlFoa5MoAOJ/Zg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@napi-rs/wasm-runtime": "^1.1.1" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.2.tgz", + "integrity": "sha512-sNXv5oLJ7ob93xkZ1XnxisYhGYXfaG9f65/ZgYuAu3qt7b3NadcOEhLvx28hv31PgX8SZJRYrAIPQilQmFpLVw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1", + "@emnapi/runtime": "^1.7.1" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.0.0-rc.12.tgz", + "integrity": "sha512-5eOND4duWkwx1AzCxadcOrNeighiLwMInEADT0YM7xeEOOFcovWZCq8dadXgcRHSf3Ulh1kFo/qvzoFiCLOL1Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.0.0-rc.12.tgz", + "integrity": "sha512-PyqoipaswDLAZtot351MLhrlrh6lcZPo2LSYE+VDxbVk24LVKAGOuE4hb8xZQmrPAuEtTZW8E6D2zc5EUZX4Lw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.12.tgz", + "integrity": "sha512-HHMwmarRKvoFsJorqYlFeFRzXZqCt2ETQlEDOb9aqssrnVBB1/+xgTGtuTrIk5vzLNX1MjMtTf7W9z3tsSbrxw==", + "dev": true, + "license": "MIT" + }, "node_modules/@rollup/plugin-commonjs": { "version": "28.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-28.0.1.tgz", @@ -18140,6 +18443,17 @@ "@types/node": "*" } }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -18158,6 +18472,13 @@ "@types/ms": "*" } }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -18922,6 +19243,160 @@ "uncrypto": "^0.1.3" } }, + "node_modules/@vitest/coverage-v8": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.1.2.tgz", + "integrity": "sha512-sPK//PHO+kAkScb8XITeB1bf7fsk85Km7+rt4eeuRR3VS1/crD47cmV5wicisJmjNdfeokTZwjMk4Mj2d58Mgg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@bcoe/v8-coverage": "^1.0.2", + "@vitest/utils": "4.1.2", + "ast-v8-to-istanbul": "^1.0.0", + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.2.0", + "magicast": "^0.5.2", + "obug": "^2.1.1", + "std-env": "^4.0.0-rc.1", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@vitest/browser": "4.1.2", + "vitest": "4.1.2" + }, + "peerDependenciesMeta": { + "@vitest/browser": { + "optional": true + } + } + }, + "node_modules/@vitest/expect": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.2.tgz", + "integrity": "sha512-gbu+7B0YgUJ2nkdsRJrFFW6X7NTP44WlhiclHniUhxADQJH5Szt9mZ9hWnJPJ8YwOK5zUOSSlSvyzRf0u1DSBQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.1.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.1.2", + "@vitest/utils": "4.1.2", + "chai": "^6.2.2", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.2.tgz", + "integrity": "sha512-Ize4iQtEALHDttPRCmN+FKqOl2vxTiNUhzobQFFt/BM1lRUTG7zRCLOykG/6Vo4E4hnUdfVLo5/eqKPukcWW7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.1.2", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker/node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.2.tgz", + "integrity": "sha512-dwQga8aejqeuB+TvXCMzSQemvV9hNEtDDpgUKDzOmNQayl2OG241PSWeJwKRH3CiC+sESrmoFd49rfnq7T4RnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.2.tgz", + "integrity": "sha512-Gr+FQan34CdiYAwpGJmQG8PgkyFVmARK8/xSijia3eTFgVfpcpztWLuP6FttGNfPLJhaZVP/euvujeNYar36OQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.1.2", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.2.tgz", + "integrity": "sha512-g7yfUmxYS4mNxk31qbOYsSt2F4m1E02LFqO53Xpzg3zKMhLAPZAjjfyl9e6z7HrW6LvUdTwAQR3HHfLjpko16A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.2", + "@vitest/utils": "4.1.2", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.2.tgz", + "integrity": "sha512-DU4fBnbVCJGNBwVA6xSToNXrkZNSiw59H8tcuUspVMsBDBST4nfvsPsEHDHGtWRRnqBERBQu7TrTKskmjqTXKA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.2.tgz", + "integrity": "sha512-xw2/TiX82lQHA06cgbqRKFb5lCAy3axQ4H4SoUFhUsg+wztiet+co86IAMDtF6Vm1hc7J6j09oh/rgDn+JdKIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.1.2", + "convert-source-map": "^2.0.0", + "tinyrainbow": "^3.1.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/@wagmi/connectors": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/@wagmi/connectors/-/connectors-6.2.0.tgz", @@ -23591,6 +24066,16 @@ "util": "^0.12.5" } }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/ast-types": { "version": "0.16.1", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.16.1.tgz", @@ -23611,6 +24096,35 @@ "dev": true, "license": "MIT" }, + "node_modules/ast-v8-to-istanbul": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.0.tgz", + "integrity": "sha512-1fSfIwuDICFA4LKkCzRPO7F0hzFf0B7+Xqrl27ynQaa+Rh0e1Es0v6kWHPott3lU10AyAr7oKHa65OppjLn3Rg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.31", + "estree-walker": "^3.0.3", + "js-tokens": "^10.0.0" + } + }, + "node_modules/ast-v8-to-istanbul/node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/ast-v8-to-istanbul/node_modules/js-tokens": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz", + "integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==", + "dev": true, + "license": "MIT" + }, "node_modules/async-function": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/async-function/-/async-function-1.0.0.tgz", @@ -24482,6 +24996,16 @@ "node": ">=6" } }, + "node_modules/chai": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz", + "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -25912,6 +26436,13 @@ "node": ">= 0.4" } }, + "node_modules/es-module-lexer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.0.0.tgz", + "integrity": "sha512-5POEcUuZybH7IdmGsD8wlf0AI55wMecM9rVBTI/qEAy2c1kTOm3DjFYjrBdI2K3BaJjJYfYFeRtM0t9ssnRuxw==", + "dev": true, + "license": "MIT" + }, "node_modules/es-object-atoms": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", @@ -26881,6 +27412,16 @@ "integrity": "sha512-Z+ktTxTwv9ILfgKCk32OX3n/doe+OcLTRtqK9pcL+JsP3J1/VW8Uvl4ZjLlKqeW4rzK4oesDOGMEMRIZqtP4Iw==", "license": "BSD-3-Clause" }, + "node_modules/expect-type": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz", + "integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/exponential-backoff": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.3.tgz", @@ -28085,6 +28626,13 @@ "integrity": "sha512-LgOWAkrN0rFaQpfdWBQlv/VhkOxb5AsBjk6NQVx4yEzWS923T07X0M1Y0VNko2H52HeSpZrZNNMJ0aFqsdVzQg==", "license": "ISC" }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true, + "license": "MIT" + }, "node_modules/http-errors": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", @@ -29133,6 +29681,45 @@ "ws": "*" } }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-report": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^4.0.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-reports": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.2.0.tgz", + "integrity": "sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/iterator.prototype": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.5.tgz", @@ -30149,6 +30736,47 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/magicast": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.2.tgz", + "integrity": "sha512-E3ZJh4J3S9KfwdjZhe2afj6R9lGIN5Pher1pF39UGrXRqq/VDaGVIGN13BjHd2u8B61hArAGOnso7nBOouW3TQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.0", + "@babel/types": "^7.29.0", + "source-map-js": "^1.2.1" + } + }, + "node_modules/make-dir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/map-obj": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.3.0.tgz", @@ -31314,6 +31942,17 @@ "node": ">=16" } }, + "node_modules/obug": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.1.tgz", + "integrity": "sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT" + }, "node_modules/ofetch": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/ofetch/-/ofetch-1.5.1.tgz", @@ -31765,6 +32404,13 @@ "dev": true, "license": "MIT" }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, "node_modules/pbkdf2": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.5.tgz", @@ -32007,9 +32653,9 @@ } }, "node_modules/postcss": { - "version": "8.5.6", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", - "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", + "version": "8.5.8", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.8.tgz", + "integrity": "sha512-OW/rX8O/jXnm82Ey1k44pObPtdblfiuWnrd8X7GJ7emImCOstunGbXUpp7HdBrFQX6rJzn3sPT397Wp5aCwCHg==", "dev": true, "funding": [ { @@ -33509,6 +34155,40 @@ "rlp": "bin/rlp" } }, + "node_modules/rolldown": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0-rc.12.tgz", + "integrity": "sha512-yP4USLIMYrwpPHEFB5JGH1uxhcslv6/hL0OyvTuY+3qlOSJvZ7ntYnoWpehBxufkgN0cvXxppuTu5hHa/zPh+A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.122.0", + "@rolldown/pluginutils": "1.0.0-rc.12" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm64": "1.0.0-rc.12", + "@rolldown/binding-darwin-arm64": "1.0.0-rc.12", + "@rolldown/binding-darwin-x64": "1.0.0-rc.12", + "@rolldown/binding-freebsd-x64": "1.0.0-rc.12", + "@rolldown/binding-linux-arm-gnueabihf": "1.0.0-rc.12", + "@rolldown/binding-linux-arm64-gnu": "1.0.0-rc.12", + "@rolldown/binding-linux-arm64-musl": "1.0.0-rc.12", + "@rolldown/binding-linux-ppc64-gnu": "1.0.0-rc.12", + "@rolldown/binding-linux-s390x-gnu": "1.0.0-rc.12", + "@rolldown/binding-linux-x64-gnu": "1.0.0-rc.12", + "@rolldown/binding-linux-x64-musl": "1.0.0-rc.12", + "@rolldown/binding-openharmony-arm64": "1.0.0-rc.12", + "@rolldown/binding-wasm32-wasi": "1.0.0-rc.12", + "@rolldown/binding-win32-arm64-msvc": "1.0.0-rc.12", + "@rolldown/binding-win32-x64-msvc": "1.0.0-rc.12" + } + }, "node_modules/rollup": { "version": "4.57.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.57.1.tgz", @@ -34297,6 +34977,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, "node_modules/signal-exit": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", @@ -34501,6 +35188,13 @@ "dev": true, "license": "MIT" }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, "node_modules/stacktrace-parser": { "version": "0.1.11", "resolved": "https://registry.npmjs.org/stacktrace-parser/-/stacktrace-parser-0.1.11.tgz", @@ -34523,6 +35217,13 @@ "node": ">= 0.8" } }, + "node_modules/std-env": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.0.0.tgz", + "integrity": "sha512-zUMPtQ/HBY3/50VbpkupYHbRroTRZJPRLvreamgErJVys0ceuzMkD44J/QjqhHjOzK42GQ3QZIeFG1OYfOtKqQ==", + "dev": true, + "license": "MIT" + }, "node_modules/stdin-discarder": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz", @@ -35148,6 +35849,13 @@ "integrity": "sha512-fGTi3gxV/23FTYdAoUtLYp6qySe2KE3teyZitipKNRuVYcBkoP/bB3guXN/XVKUe9mxCHXnc9C4ocyz8OmgN0g==", "license": "MIT" }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, "node_modules/tinyexec": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.2.tgz", @@ -35206,6 +35914,16 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/tinyrainbow": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.0.tgz", + "integrity": "sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/tldts": { "version": "7.0.21", "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.0.21.tgz", @@ -36251,6 +36969,84 @@ } } }, + "node_modules/vite": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.0.3.tgz", + "integrity": "sha512-B9ifbFudT1TFhfltfaIPgjo9Z3mDynBTJSUYxTjOQruf/zHH+ezCQKcoqO+h7a9Pw9Nm/OtlXAiGT1axBgwqrQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.32.0", + "picomatch": "^4.0.4", + "postcss": "^8.5.8", + "rolldown": "1.0.0-rc.12", + "tinyglobby": "^0.2.15" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.1.0", + "esbuild": "^0.27.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, "node_modules/vite-compatible-readable-stream": { "version": "3.6.1", "resolved": "https://registry.npmjs.org/vite-compatible-readable-stream/-/vite-compatible-readable-stream-3.6.1.tgz", @@ -36265,6 +37061,375 @@ "node": ">= 6" } }, + "node_modules/vite/node_modules/lightningcss": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz", + "integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.32.0", + "lightningcss-darwin-arm64": "1.32.0", + "lightningcss-darwin-x64": "1.32.0", + "lightningcss-freebsd-x64": "1.32.0", + "lightningcss-linux-arm-gnueabihf": "1.32.0", + "lightningcss-linux-arm64-gnu": "1.32.0", + "lightningcss-linux-arm64-musl": "1.32.0", + "lightningcss-linux-x64-gnu": "1.32.0", + "lightningcss-linux-x64-musl": "1.32.0", + "lightningcss-win32-arm64-msvc": "1.32.0", + "lightningcss-win32-x64-msvc": "1.32.0" + } + }, + "node_modules/vite/node_modules/lightningcss-android-arm64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz", + "integrity": "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-darwin-arm64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz", + "integrity": "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-darwin-x64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz", + "integrity": "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-freebsd-x64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz", + "integrity": "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz", + "integrity": "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz", + "integrity": "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-linux-arm64-musl": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz", + "integrity": "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-linux-x64-gnu": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz", + "integrity": "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-linux-x64-musl": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz", + "integrity": "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz", + "integrity": "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/lightningcss-win32-x64-msvc": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz", + "integrity": "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/vite/node_modules/picomatch": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", + "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/vitest": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.2.tgz", + "integrity": "sha512-xjR1dMTVHlFLh98JE3i/f/WePqJsah4A0FK9cc8Ehp9Udk0AZk6ccpIZhh1qJ/yxVWRZ+Q54ocnD8TXmkhspGg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.1.2", + "@vitest/mocker": "4.1.2", + "@vitest/pretty-format": "4.1.2", + "@vitest/runner": "4.1.2", + "@vitest/snapshot": "4.1.2", + "@vitest/spy": "4.1.2", + "@vitest/utils": "4.1.2", + "es-module-lexer": "^2.0.0", + "expect-type": "^1.3.0", + "magic-string": "^0.30.21", + "obug": "^2.1.1", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^4.0.0-rc.1", + "tinybench": "^2.9.0", + "tinyexec": "^1.0.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.1.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.1.2", + "@vitest/browser-preview": "4.1.2", + "@vitest/browser-webdriverio": "4.1.2", + "@vitest/ui": "4.1.2", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/vitest/node_modules/picomatch": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", + "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/vlq": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/vlq/-/vlq-2.0.4.tgz", @@ -36481,6 +37646,23 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/wif": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/wif/-/wif-5.0.0.tgz", diff --git a/package.json b/package.json index 79022b5..f874fd2 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,10 @@ "build": "next build", "start": "next start", "lint": "eslint", + "typecheck": "tsc --noEmit", + "test": "vitest run", + "test:watch": "vitest", + "test:coverage": "vitest run --coverage", "inngest": "npx inngest-cli@latest dev" }, "dependencies": { @@ -65,6 +69,7 @@ "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", + "@vitest/coverage-v8": "^4.1.2", "eslint": "^9", "eslint-config-next": "16.1.6", "eslint-config-prettier": "^10.1.8", @@ -72,7 +77,8 @@ "shadcn": "^3.8.2", "tailwindcss": "^4", "tw-animate-css": "^1.4.0", - "typescript": "^5" + "typescript": "^5", + "vitest": "^4.1.2" }, "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/lib/__tests__/api-response.test.ts b/src/lib/__tests__/api-response.test.ts new file mode 100644 index 0000000..fa061c7 --- /dev/null +++ b/src/lib/__tests__/api-response.test.ts @@ -0,0 +1,83 @@ +/** + * @vitest-environment node + * + * api-response uses NextResponse which requires a polyfilled Request/Response. + * We mock next/server to test the pure logic without Next.js runtime. + */ +import { describe, it, expect, vi } from 'vitest' + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type MockedResponse = { body: any, status: number } + +// Mock NextResponse.json to return a plain object +vi.mock('next/server', () => ({ + NextResponse: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + json: (body: any, init?: { status?: number }) => ({ + body, + status: init?.status ?? 200, + }), + }, +})) + +import { success, error, ApiError } from '../api-response' + +// ─── success() ──────────────────────────────────────────────────── + +describe('success', () => { + it('returns correct shape', () => { + const res = success({ id: '123' }) as unknown as MockedResponse + expect(res.body).toEqual({ success: true, data: { id: '123' } }) + expect(res.status).toBe(200) + }) + + it('supports custom status code', () => { + const res = success('created', 201) as unknown as MockedResponse + expect(res.status).toBe(201) + }) +}) + +// ─── error() ────────────────────────────────────────────────────── + +describe('error', () => { + it('returns correct shape', () => { + const res = error('Something went wrong', 400, 'BAD_REQUEST') as unknown as MockedResponse + expect(res.body).toEqual({ + success: false, + error: { message: 'Something went wrong', code: 'BAD_REQUEST' }, + }) + expect(res.status).toBe(400) + }) + + it('defaults to status 400', () => { + const res = error('Oops') as unknown as MockedResponse + expect(res.status).toBe(400) + }) +}) + +// ─── ApiError shortcuts ─────────────────────────────────────────── + +describe('ApiError', () => { + const cases = [ + { method: 'badRequest' as const, status: 400, code: 'BAD_REQUEST' }, + { method: 'unauthorized' as const, status: 401, code: 'UNAUTHORIZED' }, + { method: 'forbidden' as const, status: 403, code: 'FORBIDDEN' }, + { method: 'notFound' as const, status: 404, code: 'NOT_FOUND' }, + { method: 'conflict' as const, status: 409, code: 'CONFLICT' }, + { method: 'internal' as const, status: 500, code: 'INTERNAL_ERROR' }, + ] + + for (const { method, status, code } of cases) { + it(`${method}() returns ${status} with code ${code}`, () => { + const res = ApiError[method]() as unknown as MockedResponse + expect(res.status).toBe(status) + expect(res.body.success).toBe(false) + expect(res.body.error.code).toBe(code) + }) + } + + it('supports custom error messages', () => { + const res = ApiError.notFound('Payment link not found') as unknown as MockedResponse + expect(res.body.error.message).toBe('Payment link not found') + }) +}) diff --git a/src/lib/__tests__/chain-registry.test.ts b/src/lib/__tests__/chain-registry.test.ts new file mode 100644 index 0000000..a54e949 --- /dev/null +++ b/src/lib/__tests__/chain-registry.test.ts @@ -0,0 +1,94 @@ +import { describe, it, expect } from 'vitest' +import { + chainKeyToChainId, + chainIdToKey, + normalizeChainType, + emptyProviderSupport, +} from '../chain-registry' + +// ─── chainKeyToChainId ──────────────────────────────────────────── + +describe('chainKeyToChainId', () => { + it('returns number for numeric string keys', () => { + expect(chainKeyToChainId('1')).toBe(1) + expect(chainKeyToChainId('137')).toBe(137) + expect(chainKeyToChainId('42161')).toBe(42161) + }) + + it('returns string for non-numeric keys', () => { + expect(chainKeyToChainId('solana')).toBe('solana') + expect(chainKeyToChainId('bitcoin')).toBe('bitcoin') + expect(chainKeyToChainId('near')).toBe('near') + }) + + it('handles edge case: "0" is numeric', () => { + expect(chainKeyToChainId('0')).toBe(0) + }) +}) + +// ─── chainIdToKey ───────────────────────────────────────────────── + +describe('chainIdToKey', () => { + it('converts number to string', () => { + expect(chainIdToKey(1)).toBe('1') + expect(chainIdToKey(137)).toBe('137') + }) + + it('passes through strings unchanged', () => { + expect(chainIdToKey('solana')).toBe('solana') + }) +}) + +// ─── normalizeChainType ─────────────────────────────────────────── + +describe('normalizeChainType', () => { + const mappings = [ + ['evm', 'evm'], + ['EVM', 'evm'], + ['svm', 'solana'], + ['solana', 'solana'], + ['utxo', 'bitcoin'], + ['bitcoin', 'bitcoin'], + ['btc', 'bitcoin'], + ['cosmos', 'cosmos'], + ['near', 'near'], + ['tron', 'tron'], + ['sui', 'sui'], + ['ton', 'ton'], + ['starknet', 'starknet'], + ['aptos', 'aptos'], + ] as const + + for (const [input, expected] of mappings) { + it(`maps "${input}" → "${expected}"`, () => { + expect(normalizeChainType(input)).toBe(expected) + }) + } + + it('defaults unknown types to "evm"', () => { + expect(normalizeChainType('unknown_chain')).toBe('evm') + expect(normalizeChainType('')).toBe('evm') + }) +}) + +// ─── emptyProviderSupport ───────────────────────────────────────── + +describe('emptyProviderSupport', () => { + it('returns all providers as false', () => { + const support = emptyProviderSupport() + expect(support.lifi).toBe(false) + expect(support.rango).toBe(false) + expect(support.rubic).toBe(false) + expect(support.symbiosis).toBe(false) + expect(support.nearIntents).toBe(false) + expect(support.cctp).toBe(false) + }) + + it('returns a new object each time (no shared reference)', () => { + const a = emptyProviderSupport() + const b = emptyProviderSupport() + expect(a).not.toBe(b) + a.lifi = true + expect(b.lifi).toBe(false) + }) +}) diff --git a/src/lib/__tests__/payment-link-validation.test.ts b/src/lib/__tests__/payment-link-validation.test.ts new file mode 100644 index 0000000..d310aec --- /dev/null +++ b/src/lib/__tests__/payment-link-validation.test.ts @@ -0,0 +1,131 @@ +import { describe, it, expect } from 'vitest' +import { createPaymentLinkSchema, updatePaymentLinkSchema } from '../validations/payment-link' + +// ─── createPaymentLinkSchema ────────────────────────────────────── + +describe('createPaymentLinkSchema', () => { + const validBase = { + title: 'Test Product', + amount: 49.99, + currency: 'USD', + recipient_address: '0xabc123', + receive_mode: 'same_chain' as const, + } + + it('accepts valid minimal input', () => { + const result = createPaymentLinkSchema.safeParse(validBase) + expect(result.success).toBe(true) + }) + + it('accepts full input with all optional fields', () => { + const result = createPaymentLinkSchema.safeParse({ + ...validBase, + description: 'A test product', + receive_token: '0xtoken', + receive_token_symbol: 'USDC', + receive_chain_id: 8453, + use_stealth: true, + max_uses: 10, + expires_at: '2026-12-31T23:59:59Z', + config: { + theme: 'dark', + logoUrl: 'https://example.com/logo.png', + redirectUrl: 'https://example.com/success', + }, + }) + expect(result.success).toBe(true) + }) + + it('rejects missing title', () => { + const { title: _title, ...noTitle } = validBase + const result = createPaymentLinkSchema.safeParse(noTitle) + expect(result.success).toBe(false) + }) + + it('rejects empty title', () => { + const result = createPaymentLinkSchema.safeParse({ ...validBase, title: '' }) + expect(result.success).toBe(false) + }) + + it('rejects title over 100 chars', () => { + const result = createPaymentLinkSchema.safeParse({ + ...validBase, + title: 'A'.repeat(101), + }) + expect(result.success).toBe(false) + }) + + it('rejects negative amount', () => { + const result = createPaymentLinkSchema.safeParse({ ...validBase, amount: -10 }) + expect(result.success).toBe(false) + }) + + it('rejects zero amount', () => { + const result = createPaymentLinkSchema.safeParse({ ...validBase, amount: 0 }) + expect(result.success).toBe(false) + }) + + it('rejects missing recipient_address', () => { + const { recipient_address: _addr, ...noAddr } = validBase + const result = createPaymentLinkSchema.safeParse(noAddr) + expect(result.success).toBe(false) + }) + + it('rejects invalid receive_mode', () => { + const result = createPaymentLinkSchema.safeParse({ + ...validBase, + receive_mode: 'invalid', + }) + expect(result.success).toBe(false) + }) + + it('accepts receive_chain_id as string', () => { + const result = createPaymentLinkSchema.safeParse({ + ...validBase, + receive_chain_id: 'solana', + }) + expect(result.success).toBe(true) + }) + + it('rejects invalid config theme', () => { + const result = createPaymentLinkSchema.safeParse({ + ...validBase, + config: { theme: 'neon' }, + }) + expect(result.success).toBe(false) + }) + + it('rejects invalid expires_at format', () => { + const result = createPaymentLinkSchema.safeParse({ + ...validBase, + expires_at: 'not-a-date', + }) + expect(result.success).toBe(false) + }) +}) + +// ─── updatePaymentLinkSchema ────────────────────────────────────── + +describe('updatePaymentLinkSchema', () => { + it('accepts partial updates (only status)', () => { + const result = updatePaymentLinkSchema.safeParse({ status: 'paused' }) + expect(result.success).toBe(true) + }) + + it('accepts empty object (all fields optional)', () => { + const result = updatePaymentLinkSchema.safeParse({}) + expect(result.success).toBe(true) + }) + + it('rejects invalid status', () => { + const result = updatePaymentLinkSchema.safeParse({ status: 'deleted' }) + expect(result.success).toBe(false) + }) + + it('accepts valid status values', () => { + for (const status of ['active', 'paused', 'archived', 'expired']) { + const result = updatePaymentLinkSchema.safeParse({ status }) + expect(result.success).toBe(true) + } + }) +}) diff --git a/src/lib/__tests__/quote-aggregator.test.ts b/src/lib/__tests__/quote-aggregator.test.ts new file mode 100644 index 0000000..3cd6ad5 --- /dev/null +++ b/src/lib/__tests__/quote-aggregator.test.ts @@ -0,0 +1,184 @@ +/** + * Tests for pure utility functions extracted from the quote aggregator. + * + * We cannot import the QuoteAggregator directly because it pulls in providers + * with heavy SDK deps (LiFi, Rango, etc). Instead we test the exported pure logic: + * normalizeChainId, calculateTieBreakerScore, rankQuotes + * + * These are rewritten here since they're not exported from the module. + * If they get exported in the future, switch to direct imports. + */ +import { describe, it, expect } from 'vitest' + +// ─── Recreate pure functions from quote-aggregator ──────────────── + +const CHAIN_ID_ALIASES: Record = { + sol: 'solana', + btc: 'bitcoin', + doge: 'dogecoin', + '-239': 'ton', + '728126428': 'tron', + '1151111081099710': 'solana', + '23448594291968336': 'starknet', +} + +type ChainId = string | number + +function normalizeChainId(id: ChainId): ChainId { + if (typeof id === 'string' && CHAIN_ID_ALIASES[id]) return CHAIN_ID_ALIASES[id] + if (typeof id === 'number' && CHAIN_ID_ALIASES[String(id)]) return CHAIN_ID_ALIASES[String(id)] + return id +} + +const PROVIDER_RELIABILITY: Record = { + 'cctp': 98, + 'lifi': 95, + 'rango': 90, + 'symbiosis': 88, + 'rubic': 85, + 'near-intents': 80, +} + +interface MockQuote { + provider: string + toAmount: string + fees?: { totalFeeUSD?: string } + estimatedGas?: string + estimatedDuration?: number +} + +function calculateTieBreakerScore(quote: MockQuote): number { + const totalFeeUSD = parseFloat(quote.fees?.totalFeeUSD || '0') + const gasCostUSD = parseFloat(quote.estimatedGas || '0') + const duration = quote.estimatedDuration || 600 + const reliability = PROVIDER_RELIABILITY[quote.provider] || 50 + + const totalCost = totalFeeUSD + gasCostUSD + const feeScore = Math.max(0, 30 * (1 - Math.min(totalCost, 30) / 30)) + const speedScore = Math.max(0, 10 * (1 - Math.min(duration, 1800) / 1800)) + const reliabilityScore = (reliability / 100) * 10 + + return feeScore + speedScore + reliabilityScore +} + +function rankQuotes(quotes: MockQuote[]): MockQuote[] { + return [...quotes].sort((a, b) => { + const amountA = BigInt(a.toAmount || '0') + const amountB = BigInt(b.toAmount || '0') + + if (amountA !== amountB) { + return amountA > amountB ? -1 : 1 + } + + return calculateTieBreakerScore(b) - calculateTieBreakerScore(a) + }) +} + +// ─── normalizeChainId ───────────────────────────────────────────── + +describe('normalizeChainId', () => { + it('maps "sol" → "solana"', () => { + expect(normalizeChainId('sol')).toBe('solana') + }) + + it('maps "btc" → "bitcoin"', () => { + expect(normalizeChainId('btc')).toBe('bitcoin') + }) + + it('maps numeric alias 728126428 → "tron"', () => { + expect(normalizeChainId(728126428)).toBe('tron') + }) + + it('maps string numeric alias "-239" → "ton"', () => { + expect(normalizeChainId('-239')).toBe('ton') + }) + + it('passes through standard EVM chain IDs', () => { + expect(normalizeChainId(1)).toBe(1) + expect(normalizeChainId(137)).toBe(137) + expect(normalizeChainId(8453)).toBe(8453) + }) + + it('passes through unknown string keys', () => { + expect(normalizeChainId('ethereum')).toBe('ethereum') + }) +}) + +// ─── calculateTieBreakerScore ───────────────────────────────────── + +describe('calculateTieBreakerScore', () => { + it('higher reliability = higher score (same fees/speed)', () => { + const cctp = calculateTieBreakerScore({ provider: 'cctp', toAmount: '100', estimatedDuration: 300 }) + const rubic = calculateTieBreakerScore({ provider: 'rubic', toAmount: '100', estimatedDuration: 300 }) + expect(cctp).toBeGreaterThan(rubic) + }) + + it('lower fees = higher score', () => { + const lowFee = calculateTieBreakerScore({ + provider: 'lifi', toAmount: '100', + fees: { totalFeeUSD: '1' }, estimatedGas: '0', + }) + const highFee = calculateTieBreakerScore({ + provider: 'lifi', toAmount: '100', + fees: { totalFeeUSD: '25' }, estimatedGas: '0', + }) + expect(lowFee).toBeGreaterThan(highFee) + }) + + it('faster routes score higher', () => { + const fast = calculateTieBreakerScore({ + provider: 'lifi', toAmount: '100', estimatedDuration: 60, + }) + const slow = calculateTieBreakerScore({ + provider: 'lifi', toAmount: '100', estimatedDuration: 1800, + }) + expect(fast).toBeGreaterThan(slow) + }) + + it('returns non-negative for worst-case inputs', () => { + const score = calculateTieBreakerScore({ + provider: 'unknown', toAmount: '0', + fees: { totalFeeUSD: '999' }, estimatedGas: '999', estimatedDuration: 99999, + }) + expect(score).toBeGreaterThanOrEqual(0) + }) +}) + +// ─── rankQuotes ─────────────────────────────────────────────────── + +describe('rankQuotes', () => { + it('ranks by output amount (highest first)', () => { + const quotes: MockQuote[] = [ + { provider: 'rubic', toAmount: '100' }, + { provider: 'lifi', toAmount: '200' }, + { provider: 'rango', toAmount: '150' }, + ] + + const ranked = rankQuotes(quotes) + expect(ranked[0].provider).toBe('lifi') + expect(ranked[1].provider).toBe('rango') + expect(ranked[2].provider).toBe('rubic') + }) + + it('uses tie-breaker when amounts are equal', () => { + const quotes: MockQuote[] = [ + { provider: 'rubic', toAmount: '100', fees: { totalFeeUSD: '10' } }, + { provider: 'cctp', toAmount: '100', fees: { totalFeeUSD: '1' } }, + ] + + const ranked = rankQuotes(quotes) + // cctp has higher reliability AND lower fees + expect(ranked[0].provider).toBe('cctp') + }) + + it('handles single quote', () => { + const quotes: MockQuote[] = [{ provider: 'lifi', toAmount: '500' }] + const ranked = rankQuotes(quotes) + expect(ranked).toHaveLength(1) + expect(ranked[0].provider).toBe('lifi') + }) + + it('handles empty array', () => { + expect(rankQuotes([])).toEqual([]) + }) +}) diff --git a/src/lib/__tests__/token-filter.test.ts b/src/lib/__tests__/token-filter.test.ts new file mode 100644 index 0000000..38e33d4 --- /dev/null +++ b/src/lib/__tests__/token-filter.test.ts @@ -0,0 +1,169 @@ +import { describe, it, expect } from 'vitest' +import { + isSpamToken, + filterSpamTokens, + STABLECOIN_SYMBOLS, + MAX_SYMBOL_LENGTH, +} from '../token-filter' + +// ─── Helpers ─────────────────────────────────────────────────────── + +function makeToken(overrides: Partial<{ + address: string + symbol: string + name: string + isNative: boolean + logoUrl: string +}> = {}) { + return { + address: overrides.address ?? '0xaaaa000000000000000000000000000000000001', + symbol: overrides.symbol ?? 'TEST', + name: overrides.name ?? 'Test Token', + isNative: overrides.isNative ?? false, + logoUrl: overrides.logoUrl, + } +} + +const EMPTY_CANONICAL = new Set() + +// ─── isSpamToken ─────────────────────────────────────────────────── + +describe('isSpamToken', () => { + describe('allowlist bypasses', () => { + it('native tokens always pass', () => { + const token = makeToken({ isNative: true, symbol: 'SCAM', name: 'Visit scam.com' }) + expect(isSpamToken(token, 0, EMPTY_CANONICAL)).toBe(false) + }) + + it('canonical address tokens always pass', () => { + const addr = '0xCanonical00000000000000000000000000000001' + const canonical = new Set([addr.toLowerCase()]) + const token = makeToken({ address: addr, symbol: 'SCAM' }) + expect(isSpamToken(token, 0, canonical)).toBe(false) + }) + + it('multi-provider stablecoins always pass', () => { + for (const symbol of STABLECOIN_SYMBOLS) { + const token = makeToken({ symbol }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(false) + } + }) + + it('single-provider stablecoins are NOT bypassed', () => { + const token = makeToken({ symbol: 'USDC' }) + // providerCount=1 + no logo → should be spam + expect(isSpamToken(token, 1, EMPTY_CANONICAL)).toBe(true) + }) + }) + + describe('heuristic: invalid characters', () => { + it('flags symbols with emoji', () => { + const token = makeToken({ symbol: '🚀MOON' }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(true) + }) + + it('allows symbols with dots, hyphens, parens', () => { + const token = makeToken({ symbol: 'USDC.e', logoUrl: 'https://img.com/usdc.png' }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(false) + }) + }) + + describe('heuristic: symbol length', () => { + it('flags symbols longer than MAX_SYMBOL_LENGTH', () => { + const token = makeToken({ + symbol: 'A'.repeat(MAX_SYMBOL_LENGTH + 1), + logoUrl: 'https://img.com/a.png', + }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(true) + }) + + it('allows symbols at exactly MAX_SYMBOL_LENGTH', () => { + const token = makeToken({ + symbol: 'A'.repeat(MAX_SYMBOL_LENGTH), + logoUrl: 'https://img.com/a.png', + }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(false) + }) + }) + + describe('heuristic: scam patterns', () => { + const scamCases = [ + { symbol: 'visit-scam.com', desc: 'URL in symbol' }, + { name: 'Free Airdrop Claim Now', desc: 'lure words in name' }, + { symbol: 'https://scam.io', desc: 'full URL in symbol' }, + { name: 'Visit www.phishing.xyz', desc: 'www + .xyz in name' }, + ] + + for (const tc of scamCases) { + it(`flags: ${tc.desc}`, () => { + const token = makeToken({ + symbol: tc.symbol ?? 'LEGIT', + name: tc.name ?? 'Legit Token', + logoUrl: 'https://img.com/a.png', + }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(true) + }) + } + }) + + describe('heuristic: empty metadata', () => { + it('flags empty symbol', () => { + const token = makeToken({ symbol: '', logoUrl: 'https://img.com/a.png' }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(true) + }) + + it('flags UNKNOWN symbol', () => { + const token = makeToken({ symbol: 'UNKNOWN', logoUrl: 'https://img.com/a.png' }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(true) + }) + + it('flags Unknown name', () => { + const token = makeToken({ name: 'Unknown', logoUrl: 'https://img.com/a.png' }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(true) + }) + }) + + describe('heuristic: single provider + no logo', () => { + it('flags single-provider token with no logo', () => { + const token = makeToken({ symbol: 'ABC', name: 'Abc Token' }) + expect(isSpamToken(token, 1, EMPTY_CANONICAL)).toBe(true) + }) + + it('allows single-provider token with logo', () => { + const token = makeToken({ symbol: 'ABC', name: 'Abc Token', logoUrl: 'https://logo.png' }) + expect(isSpamToken(token, 1, EMPTY_CANONICAL)).toBe(false) + }) + + it('allows multi-provider token with no logo', () => { + const token = makeToken({ symbol: 'ABC', name: 'Abc Token' }) + expect(isSpamToken(token, 2, EMPTY_CANONICAL)).toBe(false) + }) + }) + + it('passes clean tokens with logo and multi-provider', () => { + const token = makeToken({ symbol: 'WETH', name: 'Wrapped Ether', logoUrl: 'https://logo.png' }) + expect(isSpamToken(token, 3, EMPTY_CANONICAL)).toBe(false) + }) +}) + +// ─── filterSpamTokens ───────────────────────────────────────────── + +describe('filterSpamTokens', () => { + it('filters out spam and keeps clean tokens', () => { + const tokens = [ + makeToken({ address: '0x1', symbol: 'WETH', name: 'Wrapped Ether', logoUrl: 'https://a.png' }), + makeToken({ address: '0x2', symbol: 'Visit scam.com', name: 'Scam' }), + makeToken({ address: '0x3', symbol: '', name: 'Unknown' }), + ] as Parameters[0] + + const counts = new Map([ + ['0x1', 3], + ['0x2', 1], + ['0x3', 1], + ]) + + const result = filterSpamTokens(tokens, counts) + expect(result).toHaveLength(1) + expect(result[0].symbol).toBe('WETH') + }) +}) diff --git a/src/lib/__tests__/token-price.test.ts b/src/lib/__tests__/token-price.test.ts new file mode 100644 index 0000000..c47e966 --- /dev/null +++ b/src/lib/__tests__/token-price.test.ts @@ -0,0 +1,73 @@ +import { describe, it, expect } from 'vitest' +import { getSlippageBuffer, calculateFromAmount } from '../../services/token-price' + +// ─── getSlippageBuffer ──────────────────────────────────────────── + +describe('getSlippageBuffer', () => { + it('returns 0.5% for stablecoin-to-stablecoin', () => { + expect(getSlippageBuffer('USDC', 'USDT')).toBe(0.5) + expect(getSlippageBuffer('DAI', 'USDC.e')).toBe(0.5) + expect(getSlippageBuffer('USDbC', 'fUSDT')).toBe(0.5) + }) + + it('returns 1.0% when source is not stablecoin', () => { + expect(getSlippageBuffer('ETH', 'USDC')).toBe(1.0) + expect(getSlippageBuffer('WBTC', 'USDT')).toBe(1.0) + }) + + it('returns 1.0% when destination is not stablecoin', () => { + expect(getSlippageBuffer('USDC', 'ETH')).toBe(1.0) + expect(getSlippageBuffer('USDT', 'WBTC')).toBe(1.0) + }) + + it('returns 1.0% for non-stablecoin pairs', () => { + expect(getSlippageBuffer('ETH', 'WBTC')).toBe(1.0) + expect(getSlippageBuffer('SOL', 'AVAX')).toBe(1.0) + }) +}) + +// ─── calculateFromAmount ────────────────────────────────────────── + +describe('calculateFromAmount', () => { + it('calculates correct base amount without slippage', () => { + // $100 at $1/token, 0% slippage = 100 tokens + const result = parseFloat(calculateFromAmount(100, 1, 0)) + expect(result).toBeCloseTo(100, 2) + }) + + it('applies slippage buffer correctly', () => { + // $100 at $1/token, 1% slippage = 101 tokens + const result = parseFloat(calculateFromAmount(100, 1, 1)) + expect(result).toBeCloseTo(101, 2) + }) + + it('uses 8 decimal precision for high-price tokens (>$100)', () => { + // BTC-like: $50000/token + const result = calculateFromAmount(100, 50000, 1) + expect(result.split('.')[1]?.length).toBe(8) + }) + + it('uses 6 decimal precision for mid-range tokens ($1-$100)', () => { + // SOL-like: $50/token + const result = calculateFromAmount(100, 50, 1) + expect(result.split('.')[1]?.length).toBe(6) + }) + + it('uses 4 decimal precision for low-price tokens ($0.01-$1)', () => { + const result = calculateFromAmount(100, 0.5, 1) + expect(result.split('.')[1]?.length).toBe(4) + }) + + it('uses 2 decimal precision for very low price tokens (<$0.01)', () => { + const result = calculateFromAmount(100, 0.001, 1) + expect(result.split('.')[1]?.length).toBe(2) + }) + + it('throws on zero price', () => { + expect(() => calculateFromAmount(100, 0, 1)).toThrow('Invalid token price') + }) + + it('throws on negative price', () => { + expect(() => calculateFromAmount(100, -5, 1)).toThrow('Invalid token price') + }) +}) diff --git a/src/lib/__tests__/webhooks.test.ts b/src/lib/__tests__/webhooks.test.ts new file mode 100644 index 0000000..e208d6f --- /dev/null +++ b/src/lib/__tests__/webhooks.test.ts @@ -0,0 +1,112 @@ +import { describe, it, expect } from 'vitest' +import { generateWebhookSecret, signPayload, buildWebhookPayload } from '../webhooks' + +// ─── generateWebhookSecret ──────────────────────────────────────── + +describe('generateWebhookSecret', () => { + it('starts with whsec_ prefix', () => { + const secret = generateWebhookSecret() + expect(secret).toMatch(/^whsec_/) + }) + + it('has correct length (whsec_ + 64 hex chars = 70)', () => { + const secret = generateWebhookSecret() + expect(secret).toHaveLength(70) + }) + + it('generates unique secrets', () => { + const a = generateWebhookSecret() + const b = generateWebhookSecret() + expect(a).not.toBe(b) + }) +}) + +// ─── signPayload ────────────────────────────────────────────────── + +describe('signPayload', () => { + it('returns sha256= prefixed signature', () => { + const sig = signPayload('{"test": true}', 'whsec_abc123') + expect(sig).toMatch(/^sha256=[a-f0-9]{64}$/) + }) + + it('is deterministic for same input', () => { + const body = '{"amount": 100}' + const secret = 'whsec_deadbeef' + expect(signPayload(body, secret)).toBe(signPayload(body, secret)) + }) + + it('produces different signatures for different bodies', () => { + const secret = 'whsec_deadbeef' + const sig1 = signPayload('body1', secret) + const sig2 = signPayload('body2', secret) + expect(sig1).not.toBe(sig2) + }) + + it('strips whsec_ prefix before signing', () => { + const body = '{"test": true}' + // Signing with raw hex should match signing with prefixed secret + const withPrefix = signPayload(body, 'whsec_abc123') + const withoutPrefix = signPayload(body, 'abc123') + expect(withPrefix).toBe(withoutPrefix) + }) +}) + +// ─── buildWebhookPayload ────────────────────────────────────────── + +describe('buildWebhookPayload', () => { + const mockTransaction = { + id: 'tx-123', + payment_link_id: 'pl-456', + status: 'completed', + customer_wallet: '0xabc', + from_chain_id: '137', + from_token_symbol: 'USDC', + from_amount: '50.00', + to_chain_id: '1', + to_token_symbol: 'ETH', + to_amount: '0.025', + actual_output: '0.025', + provider: 'lifi', + source_tx_hash: '0xsrc', + dest_tx_hash: '0xdst', + completed_at: '2026-01-01T00:00:00Z', + } + + it('creates correct structure for payment.completed', () => { + const payload = buildWebhookPayload('payment.completed', mockTransaction) + + expect(payload.type).toBe('payment.completed') + expect(payload.id).toMatch(/^evt_/) + expect(payload.created_at).toBeDefined() + expect(payload.data.transaction_id).toBe('tx-123') + expect(payload.data.payment_link_id).toBe('pl-456') + expect(payload.data.provider).toBe('lifi') + }) + + it('includes error fields for payment.failed', () => { + const failedTx = { + ...mockTransaction, + status: 'failed', + error_message: 'Bridge timeout', + failure_stage: 'bridge', + } + + const payload = buildWebhookPayload('payment.failed', failedTx) + + expect(payload.data.error_message).toBe('Bridge timeout') + expect(payload.data.failure_stage).toBe('bridge') + }) + + it('does NOT include error fields for payment.completed', () => { + const payload = buildWebhookPayload('payment.completed', mockTransaction) + + expect(payload.data).not.toHaveProperty('error_message') + expect(payload.data).not.toHaveProperty('failure_stage') + }) + + it('generates unique event IDs', () => { + const a = buildWebhookPayload('payment.completed', mockTransaction) + const b = buildWebhookPayload('payment.completed', mockTransaction) + expect(a.id).not.toBe(b.id) + }) +}) diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..518247b --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from 'vitest/config' +import path from 'path' + +export default defineConfig({ + test: { + globals: true, + environment: 'node', + include: ['src/**/__tests__/**/*.test.ts'], + coverage: { + provider: 'v8', + include: ['src/lib/**/*.ts'], + exclude: ['src/lib/__tests__/**', 'src/lib/hooks/**'], + }, + }, + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, +}) From e309ee94c310678e17499e3930e72ddbd22b40d4 Mon Sep 17 00:00:00 2001 From: Shreyas Patil Date: Fri, 3 Apr 2026 02:27:06 +0530 Subject: [PATCH 2/3] ci: add lint, typecheck, and unit test pipeline for PRs --- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ eslint.config.mjs | 15 +++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0c98aba --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: ✅ CI + +on: + pull_request: + types: [opened, synchronize] + +concurrency: + group: ci-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + ci: + runs-on: ubuntu-latest + name: Lint, Typecheck & Test + + if: | + !github.event.pull_request.draft && + github.event.pull_request.user.login != 'dependabot[bot]' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install Dependencies + run: npm ci + + - name: ESLint + run: npm run lint + + - name: TypeScript Typecheck + run: npm run typecheck + + - name: Unit Tests + run: npm test diff --git a/eslint.config.mjs b/eslint.config.mjs index 05e726d..60e96eb 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -5,6 +5,19 @@ import nextTs from "eslint-config-next/typescript"; const eslintConfig = defineConfig([ ...nextVitals, ...nextTs, + { + // Allow underscore-prefixed vars to be unused (standard destructuring pattern) + rules: { + "@typescript-eslint/no-unused-vars": [ + "warn", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + destructuredArrayIgnorePattern: "^_", + }, + ], + }, + }, // Override default ignores of eslint-config-next. globalIgnores([ // Default ignores of eslint-config-next: @@ -12,6 +25,8 @@ const eslintConfig = defineConfig([ "out/**", "build/**", "next-env.d.ts", + // Non-Next.js files + "scripts/**", ]), ]); From d56e60922090c4d9b324289ea1838e34f8248678 Mon Sep 17 00:00:00 2001 From: Shreyas Patil Date: Fri, 3 Apr 2026 02:42:47 +0530 Subject: [PATCH 3/3] fix: allow Flash Review to post comments on fork PRs --- .github/workflows/ai-pr-review.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ai-pr-review.yml b/.github/workflows/ai-pr-review.yml index 39c2777..b219136 100644 --- a/.github/workflows/ai-pr-review.yml +++ b/.github/workflows/ai-pr-review.yml @@ -1,7 +1,7 @@ name: ⚡ Flash PR Review on: - pull_request: + pull_request_target: types: [opened, synchronize] permissions: @@ -22,9 +22,10 @@ jobs: github.event.pull_request.user.login != 'dependabot[bot]' steps: - - name: Checkout + - name: Checkout PR Head uses: actions/checkout@v4 with: + ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 - name: Setup Node