diff --git a/tests/account.test.ts b/tests/ep6/account.test.ts similarity index 94% rename from tests/account.test.ts rename to tests/ep6/account.test.ts index 1a44f04de..9b2e76b28 100644 --- a/tests/account.test.ts +++ b/tests/ep6/account.test.ts @@ -13,15 +13,17 @@ import type { Client, PublicClient } from "viem" import { privateKeyToAccount } from "viem/accounts" import { - ENTRYPOINT_ADDRESS_V06, type UserOperation, walletClientToSmartAccountSigner } from "permissionless" import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts" -import { DEFAULT_ECDSA_OWNERSHIP_MODULE } from "../src/accounts/utils/constants.js" -import { validateUserOp } from "../src/accounts/utils/helpers.js" -import { createSmartAccountClient, signerToSmartAccount } from "../src/index.js" -import { checkBalance } from "./utils.js" +import { DEFAULT_ECDSA_OWNERSHIP_MODULE } from "../../src/accounts/utils/constants.js" +import { validateUserOp } from "../../src/accounts/utils/helpers.js" +import { + createSmartAccountClient, + signerToSmartAccount +} from "../../src/index.js" +import { checkBalance } from "../utils.js" describe("Biconomy Smart Account V2 EP v6 tests", () => { let smartAccount: Awaited> @@ -30,11 +32,8 @@ describe("Biconomy Smart Account V2 EP v6 tests", () => { let smartAccountClient: Awaited> const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e" - const privateKey = - "0x2e5d78c6f2e6dca5fcbb22cca841d6c43465c483f59cbd6839a24d4ec89b977b" - const account = privateKeyToAccount(privateKey) + const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`) const bundlerUrl = process.env.BUNDLER_URL ?? "" - const entryPoint = ENTRYPOINT_ADDRESS_V06 // const chainId = extractChainIdFromBundlerUrl(bundlerUrl) // const chain = getChain(baseSepolia.id) const chain = baseSepolia diff --git a/tests/ep6/account_signature.test.ts b/tests/ep6/account_signature.test.ts new file mode 100644 index 000000000..9523923d3 --- /dev/null +++ b/tests/ep6/account_signature.test.ts @@ -0,0 +1,248 @@ +import { baseSepolia } from "viem/chains" +import { beforeAll, describe, expect, test } from "vitest" + +import { http, createPublicClient, createWalletClient } from "viem" +import type { Client, PublicClient } from "viem" +import { privateKeyToAccount } from "viem/accounts" + +import { walletClientToSmartAccountSigner } from "permissionless" +import { + createSmartAccountClient, + signerToSmartAccount +} from "../../src/index.js" + +describe("Biconomy Smart Account V2 EP v6 - Signature tests", () => { + let smartAccount: Awaited> + let walletClient: Client + let publicClient: PublicClient + let smartAccountClient: Awaited> + + const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`) + const bundlerUrl = process.env.BUNDLER_URL ?? "" + const chain = baseSepolia + + beforeAll(async () => { + publicClient = createPublicClient({ + transport: http("https://public.stackup.sh/api/v1/node/base-sepolia") + }) + + walletClient = createWalletClient({ + account, + chain, + transport: http("https://public.stackup.sh/api/v1/node/base-sepolia") + }) + + smartAccount = await signerToSmartAccount(publicClient, { + signer: walletClientToSmartAccountSigner(walletClient) + }) + + smartAccountClient = createSmartAccountClient({ + account: smartAccount, + chain, + bundlerTransport: http(bundlerUrl) + }) + }) + + test("verifySignature of deployed", async () => { + const message = "hello world" + + const signature = await smartAccountClient.signMessage({ + message + }) + + const isVerified = await publicClient.verifyMessage({ + address: smartAccountClient.account.address, + message, + signature + }) + + expect(isVerified).toBeTruthy() + }) + + test("verifySignature of not deployed", async () => { + const initialEcdsaSmartAccount = await signerToSmartAccount(publicClient, { + signer: walletClientToSmartAccountSigner(walletClient), + index: 10000n + }) + + const smartAccountClient = createSmartAccountClient({ + account: initialEcdsaSmartAccount, + chain, + bundlerTransport: http(bundlerUrl) + }) + + const message = "hello world" + + const signature = await smartAccountClient.signMessage({ + message + }) + + const isVerified = await publicClient.verifyMessage({ + address: smartAccountClient.account.address, + message, + signature + }) + + expect(isVerified).toBeTruthy() + }) + + test("verifySignature with signTypedData", async () => { + const initialEcdsaSmartAccount = await signerToSmartAccount(publicClient, { + signer: walletClientToSmartAccountSigner(walletClient) + }) + + const smartAccountClient = createSmartAccountClient({ + account: initialEcdsaSmartAccount, + chain, + bundlerTransport: http(bundlerUrl) + }) + + const signature = await smartAccountClient.signTypedData({ + domain: { + name: "Ether Mail", + version: "1", + chainId: 1, + verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" + }, + types: { + Person: [ + { name: "name", type: "string" }, + { name: "wallet", type: "address" } + ], + Mail: [ + { name: "from", type: "Person" }, + { name: "to", type: "Person" }, + { name: "contents", type: "string" } + ] + }, + primaryType: "Mail", + message: { + from: { + name: "Cow", + wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" + }, + to: { + name: "Bob", + wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" + }, + contents: "Hello, Bob!" + } + }) + + const isVerified = await publicClient.verifyTypedData({ + address: smartAccountClient.account.address, + domain: { + name: "Ether Mail", + version: "1", + chainId: 1, + verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" + }, + types: { + Person: [ + { name: "name", type: "string" }, + { name: "wallet", type: "address" } + ], + Mail: [ + { name: "from", type: "Person" }, + { name: "to", type: "Person" }, + { name: "contents", type: "string" } + ] + }, + primaryType: "Mail", + message: { + from: { + name: "Cow", + wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" + }, + to: { + name: "Bob", + wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" + }, + contents: "Hello, Bob!" + }, + signature + }) + + expect(isVerified).toBeTruthy() + }) + + test("verifySignature with signTypedData for not deployed", async () => { + const initialEcdsaSmartAccount = await signerToSmartAccount(publicClient, { + signer: walletClientToSmartAccountSigner(walletClient) + }) + + const smartAccountClient = createSmartAccountClient({ + account: initialEcdsaSmartAccount, + chain, + bundlerTransport: http(bundlerUrl) + }) + + const signature = await smartAccountClient.signTypedData({ + domain: { + name: "Ether Mail", + version: "1", + chainId: 1, + verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" + }, + types: { + Person: [ + { name: "name", type: "string" }, + { name: "wallet", type: "address" } + ], + Mail: [ + { name: "from", type: "Person" }, + { name: "to", type: "Person" }, + { name: "contents", type: "string" } + ] + }, + primaryType: "Mail", + message: { + from: { + name: "Cow", + wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" + }, + to: { + name: "Bob", + wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" + }, + contents: "Hello, Bob!" + } + }) + + const isVerified = await publicClient.verifyTypedData({ + address: smartAccountClient.account.address, + domain: { + name: "Ether Mail", + version: "1", + chainId: 1, + verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" + }, + types: { + Person: [ + { name: "name", type: "string" }, + { name: "wallet", type: "address" } + ], + Mail: [ + { name: "from", type: "Person" }, + { name: "to", type: "Person" }, + { name: "contents", type: "string" } + ] + }, + primaryType: "Mail", + message: { + from: { + name: "Cow", + wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" + }, + to: { + name: "Bob", + wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" + }, + contents: "Hello, Bob!" + }, + signature + }) + + expect(isVerified).toBeTruthy() + }) +}) diff --git a/tests/bundler.test.ts b/tests/ep6/bundler.test.ts similarity index 80% rename from tests/bundler.test.ts rename to tests/ep6/bundler.test.ts index dc5787844..f8bf7ef19 100644 --- a/tests/bundler.test.ts +++ b/tests/ep6/bundler.test.ts @@ -2,9 +2,9 @@ import { http } from "viem" import { describe, expect, it } from "vitest" import { privateKeyToAccount } from "viem/accounts" -import { getChain } from "../src/accounts/utils/helpers.js" -import { createBundlerClient } from "../src/bundler/createBundlerClient.js" -import { extractChainIdFromBundlerUrl } from "../src/bundler/utils/helpers.js" +import { getChain } from "../../src/accounts/utils/helpers.js" +import { createBundlerClient } from "../../src/bundler/createBundlerClient.js" +import { extractChainIdFromBundlerUrl } from "../../src/bundler/utils/helpers.js" describe("Bundler tests", () => { const bundlerUrl = process.env.BUNDLER_URL ?? "" diff --git a/tests/modules/ecdsaOwnershipModule.test.ts b/tests/ep6/modules/ecdsaOwnershipModule.test.ts similarity index 84% rename from tests/modules/ecdsaOwnershipModule.test.ts rename to tests/ep6/modules/ecdsaOwnershipModule.test.ts index 1d23ba5e5..8bfd8e9ac 100644 --- a/tests/modules/ecdsaOwnershipModule.test.ts +++ b/tests/ep6/modules/ecdsaOwnershipModule.test.ts @@ -9,10 +9,10 @@ import { } from "viem" import type { PublicClient } from "viem" import { privateKeyToAccount } from "viem/accounts" -import { DEFAULT_ECDSA_OWNERSHIP_MODULE } from "../../src/accounts/utils/constants.js" -import { getChain } from "../../src/accounts/utils/helpers.js" -import { extractChainIdFromBundlerUrl } from "../../src/bundler/utils/helpers.js" -import { signerToSmartAccount } from "../../src/index.js" +import { DEFAULT_ECDSA_OWNERSHIP_MODULE } from "../../../src/accounts/utils/constants.js" +import { getChain } from "../../../src/accounts/utils/helpers.js" +import { extractChainIdFromBundlerUrl } from "../../../src/bundler/utils/helpers.js" +import { signerToSmartAccount } from "../../../src/index.js" describe("Biconomy Smart Account core tests", () => { let smartAccount: Awaited> diff --git a/tests/paymaster.test.ts b/tests/ep6/paymaster.test.ts similarity index 78% rename from tests/paymaster.test.ts rename to tests/ep6/paymaster.test.ts index 309d05b72..a99ea2e33 100644 --- a/tests/paymaster.test.ts +++ b/tests/ep6/paymaster.test.ts @@ -1,9 +1,9 @@ import { http } from "viem" import { describe, expect, it } from "vitest" -import { getChain } from "../src/accounts/utils/helpers.js" -import { createPaymasterClient } from "../src/paymaster/createPaymasterClient.js" -import { extractChainIdFromPaymasterUrl } from "../src/paymaster/utils/helpers.js" +import { getChain } from "../../src/accounts/utils/helpers.js" +import { createPaymasterClient } from "../../src/paymaster/createPaymasterClient.js" +import { extractChainIdFromPaymasterUrl } from "../../src/paymaster/utils/helpers.js" describe("Paymaster tests", () => { const paymasterUrl = process.env.PAYMASTER_URL ?? ""