Skip to content

Commit

Permalink
chore: teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Aug 23, 2024
1 parent fc97af7 commit 567f5fa
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 117 deletions.
11 changes: 4 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
E2E_PRIVATE_KEY_ONE=
E2E_PRIVATE_KEY_TWO=
BUNDLER_URL=https://bundler.biconomy.io/api/v2/11155111/cJPK7B3ru.dd7f7861-190d-45ic-af80-6877f74b8f44
E2E_BICO_PAYMASTER_KEY_AMOY=
E2E_BICO_PAYMASTER_KEY_BASE=
CHAIN_ID=31337
CODECOV_TOKEN=
TESTING=false
CHAIN_ID=84532
RPC_URL=
BUNDLER_URL=
BICONOMY_SDK_DEBUG=false
6 changes: 0 additions & 6 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ jobs:
run: bun run test
env:
E2E_PRIVATE_KEY_ONE: ${{ secrets.E2E_PRIVATE_KEY_ONE }}
E2E_PRIVATE_KEY_TWO: ${{ secrets.E2E_PRIVATE_KEY_TWO }}
BUNDLER_URL: https://bundler.biconomy.io/api/v2/11155111/cJPK7B3ru.dd7f7861-190d-45ic-af80-6877f74b8f44
E2E_BICO_PAYMASTER_KEY_BASE: ${{ secrets.E2E_BICO_PAYMASTER_KEY_BASE }}
E2E_BICO_PAYMASTER_KEY_AMOY: ${{ secrets.E2E_BICO_PAYMASTER_KEY_AMOY }}
CHAIN_ID: 11155111
TESTING: true

- name: report coverage
uses: davelosert/vitest-coverage-report-action@v2
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,3 @@ jobs:
run: bun run test:ci
env:
E2E_PRIVATE_KEY_ONE: ${{ secrets.E2E_PRIVATE_KEY_ONE }}
E2E_PRIVATE_KEY_TWO: ${{ secrets.E2E_PRIVATE_KEY_TWO }}
BUNDLER_URL: https://bundler.biconomy.io/api/v2/11155111/cJPK7B3ru.dd7f7861-190d-45ic-af80-6877f74b8f44
E2E_BICO_PAYMASTER_KEY_BASE: ${{ secrets.E2E_BICO_PAYMASTER_KEY_BASE }}
E2E_BICO_PAYMASTER_KEY_AMOY: ${{ secrets.E2E_BICO_PAYMASTER_KEY_AMOY }}
CHAIN_ID: 11155111
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@
"build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types",
"clean": "rimraf ./dist/_esm ./dist/_cjs ./dist/_types ./dist/tsconfig",
"test": "vitest dev -c ./tests/vitest.config.ts",
"playground": "bun run test -t=Playground --watch",
"test:readOnly": "bun run test read",
"playground": "RUN_PLAYGROUND=true bun run test -t=Playground",
"playground:watch": "RUN_PLAYGROUND=true bun run test -t=Playground --watch",
"test:watch": "bun run test --watch",
"test:watch:readOnly": "bun run test:readOnly --watch",
"test:coverage": "CI=true vitest -c ./tests/vitest.config.ts --coverage",
"test:ci": "CI=true vitest -c ./tests/vitest.config.ts",
"size": "size-limit",
Expand Down
49 changes: 0 additions & 49 deletions scripts/sendUserOperation.ts

This file was deleted.

26 changes: 21 additions & 5 deletions src/account/NexusSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
}
return this.accountAddress
}
public getAccountAddress = this.getAddress

/**
* Returns an upper estimate for the gas spent on a specific user operation
Expand Down Expand Up @@ -827,9 +828,22 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
userOp: Partial<UserOperationStruct>
): Promise<UserOperationStruct> {
this.isActiveValidationModuleDefined()
// TODO REMOVE COMMENT AND CHECK FOR PIMLICO USER OP FIELDS
// const requiredFields: UserOperationKey[] = [
// "sender",
// "nonce",
// "callGasLimit",
// "signature",
// "maxFeePerGas",
// "maxPriorityFeePerGas",
// ]
// this.validateUserOp(userOp, requiredFields)
const userOpHash = await this.getUserOpHash(userOp)
const eoaSignature =
await this.activeValidationModule.signUserOpHash(userOpHash)

const eoaSignature = (await this.activeValidationModule.signUserOpHash(
userOpHash
)) as Hex

userOp.signature = eoaSignature
return userOp as UserOperationStruct
}
Expand Down Expand Up @@ -1033,9 +1047,11 @@ export class NexusSmartAccount extends BaseSmartContractAccount {
async sendUserOp(
userOp: Partial<UserOperationStruct>
): Promise<UserOpResponse> {
const { signature, ...rest } = userOp // signature will be set when signing the userOp
const signedUserOp = await this.signUserOp(rest)
const bundlerResponse = await this.sendSignedUserOp(signedUserOp)
// biome-ignore lint/performance/noDelete: <explanation>
delete userOp.signature
const userOperation = await this.signUserOp(userOp)

const bundlerResponse = await this.sendSignedUserOp(userOperation)

return bundlerResponse
}
Expand Down
4 changes: 2 additions & 2 deletions src/account/utils/getChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const getCustomChain = (
name: string,
id: number,
rpcUrl: StringOrStrings,
blockExplorer: StringOrStrings,
blockExplorer?: StringOrStrings,
nativeCurrency?: Chain["nativeCurrency"],
contracts?: Chain["contracts"]
): Chain => {
Expand All @@ -117,7 +117,7 @@ export const getCustomChain = (
blockExplorers: {
default: {
name: "Explorer",
url: stringOrStringsToArray(blockExplorer)[0]
url: blockExplorer ? stringOrStringsToArray(blockExplorer)[0] : ""
}
},
...((contracts && { contracts }) || {})
Expand Down
3 changes: 2 additions & 1 deletion src/modules/validators/K1ValidatorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class K1ValidatorModule extends BaseValidationModule {
data: await signer.getAddress(),
additionalContext: "0x"
}
return new K1ValidatorModule(module, signer)
const instance = new K1ValidatorModule(module, signer)
return instance
}
}
20 changes: 6 additions & 14 deletions tests/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import {
type ChainConfig,
type ChainConfigWithBundler,
initChain
} from "./test.utils"
import { type ChainConfig, initChain, killAllNetworks } from "./test.utils"

let globalConfig: ChainConfigWithBundler
export default async function setup({ provide }) {
globalConfig = await initChain()
const { bundlerInstance, instance, ...serializeableConfig } = globalConfig
export async function setup({ provide }) {
const network = await initChain()
const { bundlerInstance, instance, ...serializeableConfig } = network
provide("globalNetwork", serializeableConfig)
}

export const teardown = async () => {
await Promise.all([
globalConfig.instance.stop(),
globalConfig.bundlerInstance.stop()
])
export async function teardown() {
await killAllNetworks()
}

declare module "vitest" {
Expand Down
17 changes: 12 additions & 5 deletions tests/instances/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ import {
type WalletClient,
createWalletClient
} from "viem"
import { beforeAll, describe, expect, test } from "vitest"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import {
type NexusSmartAccount,
type NexusSmartAccountConfig,
createSmartAccountClient
} from "../../src/account"
import { fundAndDeploy, getTestAccount, toTestClient } from "../test.utils"
import {
fundAndDeploy,
getTestAccount,
killNetwork,
toTestClient
} from "../test.utils"
import type { ChainConfig, MasterClient } from "../test.utils"
import { type TestFileNetworkType, toNetwork } from "../testSetup"

const NETWORK_TYPE: TestFileNetworkType = "GLOBAL"
const NETWORK_TYPE: TestFileNetworkType = "LOCAL"

describe("account", () => {
describe.skip("account", () => {
let network: ChainConfig
let chain: Chain
let bundlerUrl: string
Expand All @@ -34,7 +39,6 @@ describe("account", () => {

beforeAll(async () => {
network = await toNetwork(NETWORK_TYPE)
console.log(network.chain.rpcUrls, network.bundlerUrl)

const testConfig: Partial<NexusSmartAccountConfig> = {
factoryAddress: network.deployment.k1FactoryAddress,
Expand Down Expand Up @@ -79,6 +83,9 @@ describe("account", () => {
recipientSmartAccountAddress = await recipientSmartAccount.getAddress()
await fundAndDeploy(testClient, [smartAccount, recipientSmartAccount])
})
afterAll(async () => {
await killNetwork([network.rpcPort, network.bundlerPort])
})

test("should have account addresses", async () => {
const addresses = await Promise.all([
Expand Down
15 changes: 11 additions & 4 deletions tests/instances/bundler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ import {
type WalletClient,
createWalletClient
} from "viem"
import { beforeAll, describe, expect, test } from "vitest"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import {
type NexusSmartAccount,
type NexusSmartAccountConfig,
createSmartAccountClient
} from "../../src/account"
import { fundAndDeploy, getTestAccount, toTestClient } from "../test.utils"
import {
fundAndDeploy,
getTestAccount,
killNetwork,
toTestClient
} from "../test.utils"
import type { ChainConfig, MasterClient } from "../test.utils"
import { type TestFileNetworkType, toNetwork } from "../testSetup"

const NETWORK_TYPE: TestFileNetworkType = "LOCAL"

describe("bundler", () => {
describe.skip("bundler", () => {
let network: ChainConfig
let chain: Chain
let bundlerUrl: string
Expand All @@ -34,7 +39,6 @@ describe("bundler", () => {

beforeAll(async () => {
network = await toNetwork(NETWORK_TYPE)
console.log(network.chain.rpcUrls, network.bundlerUrl)

const testConfig: Partial<NexusSmartAccountConfig> = {
factoryAddress: network.deployment.k1FactoryAddress,
Expand Down Expand Up @@ -79,6 +83,9 @@ describe("bundler", () => {
recipientSmartAccountAddress = await recipientSmartAccount.getAddress()
await fundAndDeploy(testClient, [smartAccount, recipientSmartAccount])
})
afterAll(async () => {
await killNetwork([network.rpcPort, network.bundlerPort])
})

test("should have account addresses", async () => {
const addresses = await Promise.all([
Expand Down
15 changes: 11 additions & 4 deletions tests/instances/hook.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ import {
type WalletClient,
createWalletClient
} from "viem"
import { beforeAll, describe, expect, test } from "vitest"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import {
type NexusSmartAccount,
type NexusSmartAccountConfig,
createSmartAccountClient
} from "../../src/account"
import { fundAndDeploy, getTestAccount, toTestClient } from "../test.utils"
import {
fundAndDeploy,
getTestAccount,
killNetwork,
toTestClient
} from "../test.utils"
import type { ChainConfig, MasterClient } from "../test.utils"
import { type TestFileNetworkType, toNetwork } from "../testSetup"

const NETWORK_TYPE: TestFileNetworkType = "LOCAL"

describe("hook.module", () => {
describe.skip("hook.module", () => {
let network: ChainConfig
let chain: Chain
let bundlerUrl: string
Expand All @@ -34,7 +39,6 @@ describe("hook.module", () => {

beforeAll(async () => {
network = await toNetwork(NETWORK_TYPE)
console.log(network.chain.rpcUrls, network.bundlerUrl)

const testConfig: Partial<NexusSmartAccountConfig> = {
factoryAddress: network.deployment.k1FactoryAddress,
Expand Down Expand Up @@ -79,6 +83,9 @@ describe("hook.module", () => {
recipientSmartAccountAddress = await recipientSmartAccount.getAddress()
await fundAndDeploy(testClient, [smartAccount, recipientSmartAccount])
})
afterAll(async () => {
await killNetwork([network.rpcPort, network.bundlerPort])
})

test("should have account addresses", async () => {
const addresses = await Promise.all([
Expand Down
15 changes: 11 additions & 4 deletions tests/instances/modules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ import {
type WalletClient,
createWalletClient
} from "viem"
import { beforeAll, describe, expect, test } from "vitest"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import {
type NexusSmartAccount,
type NexusSmartAccountConfig,
createSmartAccountClient
} from "../../src/account"
import { fundAndDeploy, getTestAccount, toTestClient } from "../test.utils"
import {
fundAndDeploy,
getTestAccount,
killNetwork,
toTestClient
} from "../test.utils"
import type { ChainConfig, MasterClient } from "../test.utils"
import { type TestFileNetworkType, toNetwork } from "../testSetup"

const NETWORK_TYPE: TestFileNetworkType = "LOCAL"

describe("modules", () => {
describe.skip("modules", () => {
let network: ChainConfig
let chain: Chain
let bundlerUrl: string
Expand All @@ -34,7 +39,6 @@ describe("modules", () => {

beforeAll(async () => {
network = await toNetwork(NETWORK_TYPE)
console.log(network.chain.rpcUrls, network.bundlerUrl)

const testConfig: Partial<NexusSmartAccountConfig> = {
factoryAddress: network.deployment.k1FactoryAddress,
Expand Down Expand Up @@ -79,6 +83,9 @@ describe("modules", () => {
recipientSmartAccountAddress = await recipientSmartAccount.getAddress()
await fundAndDeploy(testClient, [smartAccount, recipientSmartAccount])
})
afterAll(async () => {
await killNetwork([network.rpcPort, network.bundlerPort])
})

test("should have account addresses", async () => {
const addresses = await Promise.all([
Expand Down
Loading

0 comments on commit 567f5fa

Please sign in to comment.