From f0c71ae5423cf78a7246ae47dc75e8c99723f081 Mon Sep 17 00:00:00 2001 From: sven Date: Fri, 20 Dec 2024 23:06:05 +0800 Subject: [PATCH] fix sdk-kit e2e test --- pnpm-lock.yaml | 30 ++----------------- sdk/typescript/rooch-sdk-kit/package.json | 3 +- .../test/case/use-default-client.test.tsx | 4 +-- .../rooch-sdk-kit/test/mocks/mock-wallet.ts | 23 +++++++++++--- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebe5fa0c32..a2a13d578e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -739,6 +739,9 @@ importers: vite: specifier: ^5.4.4 version: 5.4.4(@types/node@22.5.4)(terser@5.32.0) + vitest: + specifier: 2.1.0 + version: 2.1.0(@types/node@22.5.4)(happy-dom@15.7.4)(jsdom@25.0.0)(terser@5.32.0) sdk/typescript/templates/mini-app: dependencies: @@ -2861,42 +2864,36 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [glibc] '@napi-rs/simple-git-linux-arm64-musl@0.1.19': resolution: {integrity: sha512-OwTRF+H4IZYxmDFRi1IrLMfqbdIpvHeYbJl2X94NVsLVOY+3NUHvEzL3fYaVx5urBaMnIK0DD3wZLbcueWvxbA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [musl] '@napi-rs/simple-git-linux-powerpc64le-gnu@0.1.19': resolution: {integrity: sha512-p7zuNNVyzpRvkCt2RIGv9FX/WPcPbZ6/FRUgUTZkA2WU33mrbvNqSi4AOqCCl6mBvEd+EOw5NU4lS9ORRJvAEg==} engines: {node: '>= 10'} cpu: [powerpc64le] os: [linux] - libc: [glibc] '@napi-rs/simple-git-linux-s390x-gnu@0.1.19': resolution: {integrity: sha512-6N2vwJUPLiak8GLrS0a3is0gSb0UwI2CHOOqtvQxPmv+JVI8kn3vKiUscsktdDb0wGEPeZ8PvZs0y8UWix7K4g==} engines: {node: '>= 10'} cpu: [s390x] os: [linux] - libc: [glibc] '@napi-rs/simple-git-linux-x64-gnu@0.1.19': resolution: {integrity: sha512-61YfeO1J13WK7MalLgP3QlV6of2rWnVw1aqxWkAgy/lGxoOFSJ4Wid6ANVCEZk4tJpPX/XNeneqkUz5xpeb2Cw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] '@napi-rs/simple-git-linux-x64-musl@0.1.19': resolution: {integrity: sha512-cCTWNpMJnN3PrUBItWcs3dQKCydsIasbrS3laMzq8k7OzF93Zrp2LWDTPlLCO9brbBVpBzy2Qk5Xg9uAfe/Ukw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] '@napi-rs/simple-git-win32-arm64-msvc@0.1.19': resolution: {integrity: sha512-sWavb1BjeLKKBA+PbTsRSSzVNfb7V/dOpaJvkgR5d2kWFn/AHmCZHSSj/3nyZdYf0BdDC+DIvqk3daAEZ6QMVw==} @@ -2952,56 +2949,48 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [glibc] '@next/swc-linux-arm64-gnu@14.2.11': resolution: {integrity: sha512-Ulo9TZVocYmUAtzvZ7FfldtwUoQY0+9z3BiXZCLSUwU2bp7GqHA7/bqrfsArDlUb2xeGwn3ZuBbKtNK8TR0A8w==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [glibc] '@next/swc-linux-arm64-musl@13.4.19': resolution: {integrity: sha512-aU0HkH2XPgxqrbNRBFb3si9Ahu/CpaR5RPmN2s9GiM9qJCiBBlZtRTiEca+DC+xRPyCThTtWYgxjWHgU7ZkyvA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [musl] '@next/swc-linux-arm64-musl@14.2.11': resolution: {integrity: sha512-fH377DnKGyUnkWlmUpFF1T90m0dADBfK11dF8sOQkiELF9M+YwDRCGe8ZyDzvQcUd20Rr5U7vpZRrAxKwd3Rzg==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [musl] '@next/swc-linux-x64-gnu@13.4.19': resolution: {integrity: sha512-htwOEagMa/CXNykFFeAHHvMJeqZfNQEoQvHfsA4wgg5QqGNqD5soeCer4oGlCol6NGUxknrQO6VEustcv+Md+g==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] '@next/swc-linux-x64-gnu@14.2.11': resolution: {integrity: sha512-a0TH4ZZp4NS0LgXP/488kgvWelNpwfgGTUCDXVhPGH6pInb7yIYNgM4kmNWOxBFt+TIuOH6Pi9NnGG4XWFUyXQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] '@next/swc-linux-x64-musl@13.4.19': resolution: {integrity: sha512-4Gj4vvtbK1JH8ApWTT214b3GwUh9EKKQjY41hH/t+u55Knxi/0wesMzwQRhppK6Ddalhu0TEttbiJ+wRcoEj5Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] '@next/swc-linux-x64-musl@14.2.11': resolution: {integrity: sha512-DYYZcO4Uir2gZxA4D2JcOAKVs8ZxbOFYPpXSVIgeoQbREbeEHxysVsg3nY4FrQy51e5opxt5mOHl/LzIyZBoKA==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] '@next/swc-win32-arm64-msvc@13.4.19': resolution: {integrity: sha512-bUfDevQK4NsIAHXs3/JNgnvEY+LRyneDN788W2NYiRIIzmILjba7LaQTfihuFawZDhRtkYCv3JDC3B4TwnmRJw==} @@ -4135,55 +4124,46 @@ packages: resolution: {integrity: sha512-btVgIsCjuYFKUjopPoWiDqmoUXQDiW2A4C3Mtmp5vACm7/GnyuprqIDPNczeyR5W8rTXEbkmrJux7cJmD99D2g==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.21.3': resolution: {integrity: sha512-zmjbSphplZlau6ZTkxd3+NMtE4UKVy7U4aVFMmHcgO5CUbw17ZP6QCgyxhzGaU/wFFdTfiojjbLG3/0p9HhAqA==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.21.3': resolution: {integrity: sha512-nSZfcZtAnQPRZmUkUQwZq2OjQciR6tEoJaZVFvLHsj0MF6QhNMg0fQ6mUOsiCUpTqxTx0/O6gX0V/nYc7LrgPw==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.21.3': resolution: {integrity: sha512-MnvSPGO8KJXIMGlQDYfvYS3IosFN2rKsvxRpPO2l2cum+Z3exiExLwVU+GExL96pn8IP+GdH8Tz70EpBhO0sIQ==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.21.3': resolution: {integrity: sha512-+W+p/9QNDr2vE2AXU0qIy0qQE75E8RTwTwgqS2G5CRQ11vzq0tbnfBd6brWhS9bCRjAjepJe2fvvkvS3dno+iw==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.21.3': resolution: {integrity: sha512-yXH6K6KfqGXaxHrtr+Uoy+JpNlUlI46BKVyonGiaD74ravdnF9BUNC+vV+SIuB96hUMGShhKV693rF9QDfO6nQ==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.21.3': resolution: {integrity: sha512-R8cwY9wcnApN/KDYWTH4gV/ypvy9yZUHlbJvfaiXSB48JO3KpwSpjOGqO4jnGkLDSk1hgjYkTbTt6Q7uvPf8eg==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.21.3': resolution: {integrity: sha512-kZPbX/NOPh0vhS5sI+dR8L1bU2cSO9FgxwM8r7wHzGydzfSjLRCFAT87GR5U9scj2rhzN3JPYVC7NoBbl4FZ0g==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.21.3': resolution: {integrity: sha512-S0Yq+xA1VEH66uiMNhijsWAafffydd2X5b77eLHfRmfLsRSpbiAWiRHV6DEpz6aOToPsgid7TI9rGd6zB1rhbg==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.21.3': resolution: {integrity: sha512-9isNzeL34yquCPyerog+IMCNxKR8XYmGd0tHSV+OVx0TmE0aJOo9uw4fZfUuk2qxobP5sug6vNdZR6u7Mw7Q+Q==} @@ -4397,28 +4377,24 @@ packages: engines: {node: '>=10'} cpu: [arm64] os: [linux] - libc: [glibc] '@swc/core-linux-arm64-musl@1.7.26': resolution: {integrity: sha512-3w8iZICMkQQON0uIcvz7+Q1MPOW6hJ4O5ETjA0LSP/tuKqx30hIniCGOgPDnv3UTMruLUnQbtBwVCZTBKR3Rkg==} engines: {node: '>=10'} cpu: [arm64] os: [linux] - libc: [musl] '@swc/core-linux-x64-gnu@1.7.26': resolution: {integrity: sha512-c+pp9Zkk2lqb06bNGkR2Looxrs7FtGDMA4/aHjZcCqATgp348hOKH5WPvNLBl+yPrISuWjbKDVn3NgAvfvpH4w==} engines: {node: '>=10'} cpu: [x64] os: [linux] - libc: [glibc] '@swc/core-linux-x64-musl@1.7.26': resolution: {integrity: sha512-PgtyfHBF6xG87dUSSdTJHwZ3/8vWZfNIXQV2GlwEpslrOkGqy+WaiiyE7Of7z9AvDILfBBBcJvJ/r8u980wAfQ==} engines: {node: '>=10'} cpu: [x64] os: [linux] - libc: [musl] '@swc/core-win32-arm64-msvc@1.7.26': resolution: {integrity: sha512-9TNXPIJqFynlAOrRD6tUQjMq7KApSklK3R/tXgIxc7Qx+lWu8hlDQ/kVPLpU7PWvMMwC/3hKBW+p5f+Tms1hmA==} diff --git a/sdk/typescript/rooch-sdk-kit/package.json b/sdk/typescript/rooch-sdk-kit/package.json index f683232682..e3efab6f37 100644 --- a/sdk/typescript/rooch-sdk-kit/package.json +++ b/sdk/typescript/rooch-sdk-kit/package.json @@ -79,7 +79,8 @@ "react-dom": "^18.3.1", "size-limit": "^11.1.5", "typescript": "^5.6.2", - "vite": "^5.4.4" + "vite": "^5.4.4", + "vitest": "2.1.0" }, "dependencies": { "@roochnetwork/rooch-sdk": "workspace:*", diff --git a/sdk/typescript/rooch-sdk-kit/test/case/use-default-client.test.tsx b/sdk/typescript/rooch-sdk-kit/test/case/use-default-client.test.tsx index 8cda910123..0d3022b65c 100644 --- a/sdk/typescript/rooch-sdk-kit/test/case/use-default-client.test.tsx +++ b/sdk/typescript/rooch-sdk-kit/test/case/use-default-client.test.tsx @@ -17,7 +17,7 @@ import { useConnectWallet, useCreateSessionKey, useCurrentSession, - useSession, + useSessions, } from '../../src/index.js' describe('useDefaultClient', () => { @@ -38,7 +38,7 @@ describe('useDefaultClient', () => { function useTestHook() { const { mutateAsync: connectWallet } = useConnectWallet() const { mutateAsync: createSessionKey } = useCreateSessionKey() - const sessions = useSession() + const sessions = useSessions() const currentSession = useCurrentSession() const networks = { test: { url: 'http://localhost:6767' } } const defaultClient = useDefaultClient({ currentNetwork: 'test', networks }) diff --git a/sdk/typescript/rooch-sdk-kit/test/mocks/mock-wallet.ts b/sdk/typescript/rooch-sdk-kit/test/mocks/mock-wallet.ts index 64567b48cc..cf84551033 100644 --- a/sdk/typescript/rooch-sdk-kit/test/mocks/mock-wallet.ts +++ b/sdk/typescript/rooch-sdk-kit/test/mocks/mock-wallet.ts @@ -18,6 +18,7 @@ import { import { SupportChain } from '../../src/feature/index.js' import { Wallet } from '../../src/wellet/wallet.js' import { Mock, vi } from 'vitest' +import { WalletNetworkType } from '../../src/index.js' export class MockBitcoinWallet extends Wallet { private kp: Keypair @@ -55,8 +56,8 @@ export class MockBitcoinWallet extends Wallet { return 'mock' } - getNetwork(): string { - return 'testnet' + getNetwork(): Promise { + return Promise.resolve('testnet') } getPublicKey(): PublicKey
{ @@ -67,7 +68,7 @@ export class MockBitcoinWallet extends Wallet { return this.kp.getRoochAddress() } - getSupportNetworks(): string[] { + getSupportNetworks(): WalletNetworkType[] { return ['testnet', 'livenet'] } @@ -98,7 +99,9 @@ export class MockBitcoinWallet extends Wallet { switchAccount(_: string): void {} - switchNetwork(_: string): void {} + switchNetwork(_: string): Promise { + return Promise.resolve() + } getDescription(): string { return '' @@ -111,4 +114,16 @@ export class MockBitcoinWallet extends Wallet { getInstallUrl(): string { return '' } + + sendBtc(input: { + toAddress: string + satoshis: number + options?: { feeRate: number } + }): Promise { + throw new Error('Method not implemented.') + } + + getBalance(): Promise<{ confirmed: number; unconfirmed: number; total: string }> { + throw new Error('Method not implemented.') + } }