Skip to content

Commit

Permalink
feat: account signature tests (#24)
Browse files Browse the repository at this point in the history
* feat: account signature tests + test folder restructure

---------

Co-authored-by: GabiDev <[email protected]>
  • Loading branch information
VGabriel45 and GabiDev45 authored Mar 14, 2024
1 parent 5c73393 commit d26a37a
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 19 deletions.
17 changes: 8 additions & 9 deletions tests/account.test.ts → tests/ep6/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof signerToSmartAccount>>
Expand All @@ -30,11 +32,8 @@ describe("Biconomy Smart Account V2 EP v6 tests", () => {
let smartAccountClient: Awaited<ReturnType<typeof createSmartAccountClient>>

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
Expand Down
248 changes: 248 additions & 0 deletions tests/ep6/account_signature.test.ts
Original file line number Diff line number Diff line change
@@ -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<ReturnType<typeof signerToSmartAccount>>
let walletClient: Client
let publicClient: PublicClient
let smartAccountClient: Awaited<ReturnType<typeof createSmartAccountClient>>

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()
})
})
6 changes: 3 additions & 3 deletions tests/bundler.test.ts → tests/ep6/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof signerToSmartAccount>>
Expand Down
6 changes: 3 additions & 3 deletions tests/paymaster.test.ts → tests/ep6/paymaster.test.ts
Original file line number Diff line number Diff line change
@@ -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 ?? ""
Expand Down

0 comments on commit d26a37a

Please sign in to comment.