Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: addresses check #160

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @biconomy/sdk

## 0.0.23

### Patch Changes

- Remove isTesting helper from testing framework

## 0.0.22

### Patch Changes
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/sdk",
"version": "0.0.22",
"version": "0.0.23",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
4 changes: 2 additions & 2 deletions scripts/send:userOp.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { privateKeyToAccount } from "viem/accounts"
import { toNexusAccount } from "../src/sdk/account/toNexusAccount"
import { getChain } from "../src/sdk/account/utils/getChain"
import { createBicoBundlerClient } from "../src/sdk/clients/createBicoBundlerClient"
import { biconomyPaymasterContext } from "../src/sdk/clients/createBicoPaymasterClient"
import { biconomySponsoredPaymasterContext } from "../src/sdk/clients/createBicoPaymasterClient"

config()

@@ -60,7 +60,7 @@ const main = async () => {
paymaster: createPaymasterClient({
transport: http(paymasterUrl)
}),
paymasterContext: biconomyPaymasterContext
paymasterContext: biconomySponsoredPaymasterContext
}
: undefined),
userOperation: {
129 changes: 129 additions & 0 deletions src/sdk/account/toNexusAccount.addresses.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {
http,
type Address,
type Chain,
type LocalAccount,
type PublicClient,
type WalletClient,
createWalletClient
} from "viem"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import { toNetwork } from "../../test/testSetup"
import {
fundAndDeployClients,
getTestAccount,
killNetwork,
toTestClient
} from "../../test/testUtils"
import type { MasterClient, NetworkConfig } from "../../test/testUtils"
import {
type NexusClient,
createSmartAccountClient
} from "../clients/createSmartAccountClient"
import {
RHINESTONE_ATTESTER_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../constants"
import type { NexusAccount } from "./toNexusAccount"
import { getCounterFactualAddress } from "./utils"

describe("nexus.account.addresses", async () => {
let network: NetworkConfig
let chain: Chain
let bundlerUrl: string

// Test utils
let testClient: MasterClient
let eoaAccount: LocalAccount
let userTwo: LocalAccount
let nexusAccountAddress: Address
let nexusClient: NexusClient
let nexusAccount: NexusAccount
let walletClient: WalletClient

beforeAll(async () => {
network = await toNetwork()

chain = network.chain
bundlerUrl = network.bundlerUrl
eoaAccount = getTestAccount(0)
userTwo = getTestAccount(1)
testClient = toTestClient(chain, getTestAccount(5))

walletClient = createWalletClient({
account: eoaAccount,
chain,
transport: http()
})

nexusClient = await createSmartAccountClient({
signer: eoaAccount,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})

nexusAccount = nexusClient.account
})
afterAll(async () => {
await killNetwork([network?.rpcPort, network?.bundlerPort])
})

test("should check account address", async () => {
nexusAccountAddress = await nexusClient.account.getCounterFactualAddress()
const counterfactualAddressFromHelper = await getCounterFactualAddress(
testClient as unknown as PublicClient,
eoaAccount.address,
true,
0n,
[RHINESTONE_ATTESTER_ADDRESS],
1,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
)
const gottenAddress = await nexusClient.account.getAddress()
expect(counterfactualAddressFromHelper).toBe(nexusAccountAddress)
expect(nexusAccount.address).toBe(nexusAccountAddress)
expect(nexusAccount.address).toBe(counterfactualAddressFromHelper)
expect(gottenAddress).toBe(nexusAccountAddress)
})

test("should check addresses after fund and deploy", async () => {
await fundAndDeployClients(testClient, [nexusClient])
const counterfactualAddressFromHelper = await getCounterFactualAddress(
testClient as unknown as PublicClient,
eoaAccount.address,
true,
0n,
[RHINESTONE_ATTESTER_ADDRESS],
1,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
)
const gottenAddress = await nexusClient.account.getAddress()
expect(counterfactualAddressFromHelper).toBe(nexusAccountAddress)
expect(nexusAccount.address).toBe(nexusAccountAddress)
expect(nexusAccount.address).toBe(counterfactualAddressFromHelper)
expect(gottenAddress).toBe(nexusAccountAddress)
})

test("should override account address", async () => {
const someoneElsesNexusAddress =
"0xf0479e036343bC66dc49dd374aFAF98402D0Ae5f"
const newNexusClient = await createSmartAccountClient({
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
accountAddress: someoneElsesNexusAddress,
signer: eoaAccount
})
const accountAddress = await newNexusClient.account.getAddress()
const someoneElseCounterfactualAddress =
await newNexusClient.account.getCounterFactualAddress()
expect(newNexusClient.account.address).toBe(
someoneElseCounterfactualAddress
)
expect(accountAddress).toBe(someoneElsesNexusAddress)
})
})
21 changes: 6 additions & 15 deletions src/sdk/account/toNexusAccount.test.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,8 @@ import {
import {
BICONOMY_ATTESTER_ADDRESS,
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
k1ValidatorAddress
TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../constants"
import type { NexusAccount } from "./toNexusAccount"
import {
@@ -95,7 +96,9 @@ describe("nexus.account", async () => {
signer: eoaAccount,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})

nexusAccount = nexusClient.account
@@ -106,18 +109,6 @@ describe("nexus.account", async () => {
await killNetwork([network?.rpcPort, network?.bundlerPort])
})

test("should override account address", async () => {
const newNexusClient = await createSmartAccountClient({
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
accountAddress: "0xf0479e036343bC66dc49dd374aFAF98402D0Ae5f",
signer: eoaAccount
})
const accountAddress = await newNexusClient.account.getAddress()
expect(accountAddress).toBe("0xf0479e036343bC66dc49dd374aFAF98402D0Ae5f")
})

test("should check isValidSignature PersonalSign is valid", async () => {
const meta = await getAccountMeta(testClient, nexusAccountAddress)

@@ -357,7 +348,7 @@ describe("nexus.account", async () => {

const finalSignature = encodePacked(
["address", "bytes"],
[k1ValidatorAddress, signatureData]
[TEST_ADDRESS_K1_VALIDATOR_ADDRESS, signatureData]
)

const contractResponse = await testClient.readContract({
10 changes: 5 additions & 5 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
@@ -46,10 +46,10 @@ import {

import {
ENTRY_POINT_ADDRESS,
MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
MOCK_ATTESTER_ADDRESS,
RHINESTONE_ATTESTER_ADDRESS,
k1ValidatorAddress as k1ValidatorAddress_,
k1ValidatorFactoryAddress
RHINESTONE_ATTESTER_ADDRESS
} from "../constants"
// Constants
import { EntrypointAbi } from "../constants/abi"
@@ -179,8 +179,8 @@ export const toNexusAccount = async (
signer: _signer,
index = 0n,
module: module_,
factoryAddress = k1ValidatorFactoryAddress,
k1ValidatorAddress = k1ValidatorAddress_,
factoryAddress = MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
k1ValidatorAddress = MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
key = "nexus account",
name = "Nexus Account",
attesters: attesters_ = [RHINESTONE_ATTESTER_ADDRESS],
8 changes: 0 additions & 8 deletions src/sdk/account/utils/Utils.ts
Original file line number Diff line number Diff line change
@@ -367,14 +367,6 @@ export const playgroundTrue = () => {
}
}

export const isTesting = () => {
try {
return process?.env?.TEST === "true"
} catch (e) {
return false
}
}

type TenderlyDetails = {
accountSlug: string
projectSlug: string
6 changes: 3 additions & 3 deletions src/sdk/account/utils/getCounterFactualAddress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Address } from "viem"
import type { PublicClient } from "viem"
import {
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
MOCK_ATTESTER_ADDRESS,
RHINESTONE_ATTESTER_ADDRESS,
k1ValidatorFactoryAddress
RHINESTONE_ATTESTER_ADDRESS
} from "../../constants"

/**
@@ -30,7 +30,7 @@ export const getCounterFactualAddress = async (
index = 0n,
attesters = [RHINESTONE_ATTESTER_ADDRESS],
threshold = 1,
factoryAddress = k1ValidatorFactoryAddress
factoryAddress = MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
) => {
if (isTestnet) {
attesters.push(MOCK_ATTESTER_ADDRESS)
10 changes: 8 additions & 2 deletions src/sdk/clients/createBicoBundlerClient.test.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,11 @@ import {
} from "../../test/testUtils"
import type { MasterClient, NetworkConfig } from "../../test/testUtils"
import { type NexusAccount, toNexusAccount } from "../account/toNexusAccount"
import { ENTRY_POINT_ADDRESS } from "../constants"
import {
ENTRY_POINT_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../constants"
import {
type BicoBundlerClient,
createBicoBundlerClient
@@ -38,7 +42,9 @@ describe("bico.bundler", async () => {
nexusAccount = await toNexusAccount({
signer: eoaAccount,
chain,
transport: http()
transport: http(),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})

bicoBundler = createBicoBundlerClient({ bundlerUrl, account: nexusAccount })
28 changes: 9 additions & 19 deletions src/sdk/clients/createBicoPaymasterClient.test.ts
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ import {
parseUnits
} from "viem"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import { paymasterTruthy, toNetworks } from "../../test/testSetup"
import { getTestParamsForTestnet, killNetwork } from "../../test/testUtils"
import type { NetworkConfig, TestnetParams } from "../../test/testUtils"
import { toNetworks } from "../../test/testSetup"
import { killNetwork } from "../../test/testUtils"
import type { NetworkConfig } from "../../test/testUtils"
import { type NexusAccount, toNexusAccount } from "../account/toNexusAccount"
import {
type BicoPaymasterClient,
@@ -28,8 +28,6 @@ import {
describe.skip("bico.paymaster", async () => {
// describe.runIf(paymasterTruthy())("bico.paymaster", async () => {
let network: NetworkConfig
// Required for "TESTNET_FROM_ENV_VARS" networks
let testnetParams: TestnetParams

let chain: Chain
let bundlerUrl: string
@@ -71,17 +69,14 @@ describe.skip("bico.paymaster", async () => {
transport: http()
})

testnetParams = getTestParamsForTestnet(publicClient)

paymaster = createBicoPaymasterClient({
transport: http(paymasterUrl)
})

nexusAccount = await toNexusAccount({
signer: account,
chain,
transport: http(),
...testnetParams
transport: http()
})

nexusAccountAddress = await nexusAccount.getCounterFactualAddress()
@@ -91,8 +86,7 @@ describe.skip("bico.paymaster", async () => {
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
paymaster,
...testnetParams
paymaster
})
})
afterAll(async () => {
@@ -148,8 +142,7 @@ describe.skip("bico.paymaster", async () => {
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl),
...testnetParams
bundlerTransport: http(bundlerUrl)
})

const initialBalance = await publicClient.getBalance({
@@ -191,8 +184,7 @@ describe.skip("bico.paymaster", async () => {
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl),
...testnetParams
bundlerTransport: http(bundlerUrl)
})

const initialBalance = await publicClient.getBalance({
@@ -238,8 +230,7 @@ describe.skip("bico.paymaster", async () => {
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl),
...testnetParams
bundlerTransport: http(bundlerUrl)
})

const usdcBalance = await publicClient.readContract({
@@ -308,8 +299,7 @@ describe.skip("bico.paymaster", async () => {
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl),
...testnetParams
bundlerTransport: http(bundlerUrl)
})

const supportedTokens = await paymaster.getSupportedTokens(nexusClient)
Loading
Loading