Skip to content

Commit

Permalink
chore: remove isTesting() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Jan 6, 2025
1 parent 48c62c3 commit 2276b71
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 113 deletions.
4 changes: 2 additions & 2 deletions scripts/send:userOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -60,7 +60,7 @@ const main = async () => {
paymaster: createPaymasterClient({
transport: http(paymasterUrl)
}),
paymasterContext: biconomyPaymasterContext
paymasterContext: biconomySponsoredPaymasterContext
}
: undefined),
userOperation: {
Expand Down
21 changes: 18 additions & 3 deletions src/sdk/account/toNexusAccount.addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import {
} from "../clients/createSmartAccountClient"
import type { NexusAccount } from "./toNexusAccount"
import { getCounterFactualAddress } from "./utils"
import {
RHINESTONE_ATTESTER_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../constants"

describe("nexus.account.addresses", async () => {
let network: NetworkConfig
Expand Down Expand Up @@ -56,7 +61,9 @@ describe("nexus.account.addresses", 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
Expand All @@ -70,7 +77,11 @@ describe("nexus.account.addresses", async () => {
const counterfactualAddressFromHelper = await getCounterFactualAddress(
testClient as unknown as PublicClient,
eoaAccount.address,
true
true,
0n,
[RHINESTONE_ATTESTER_ADDRESS],
1,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
)
const gottenAddress = await nexusClient.account.getAddress()
expect(counterfactualAddressFromHelper).toBe(nexusAccountAddress)
Expand All @@ -84,7 +95,11 @@ describe("nexus.account.addresses", async () => {
const counterfactualAddressFromHelper = await getCounterFactualAddress(
testClient as unknown as PublicClient,
eoaAccount.address,
true
true,
0n,
[RHINESTONE_ATTESTER_ADDRESS],
1,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
)
const gottenAddress = await nexusClient.account.getAddress()
expect(counterfactualAddressFromHelper).toBe(nexusAccountAddress)
Expand Down
9 changes: 6 additions & 3 deletions src/sdk/account/toNexusAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -345,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({
Expand Down
10 changes: 5 additions & 5 deletions src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 0 additions & 8 deletions src/sdk/account/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/account/utils/getCounterFactualAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PublicClient } from "viem"
import {
MOCK_ATTESTER_ADDRESS,
RHINESTONE_ATTESTER_ADDRESS,
k1ValidatorFactoryAddress
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../../constants"

/**
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/sdk/clients/createBicoBundlerClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
Expand Down
28 changes: 9 additions & 19 deletions src/sdk/clients/createBicoPaymasterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -91,8 +86,7 @@ describe.skip("bico.paymaster", async () => {
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
paymaster,
...testnetParams
paymaster
})
})
afterAll(async () => {
Expand Down Expand Up @@ -148,8 +142,7 @@ describe.skip("bico.paymaster", async () => {
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl),
...testnetParams
bundlerTransport: http(bundlerUrl)
})

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

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

const usdcBalance = await publicClient.readContract({
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 17 additions & 6 deletions src/sdk/clients/createSmartAccountClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import {
makeInstallDataAndHash
} from "../account/utils/Utils"
import { getChain } from "../account/utils/getChain"
import { k1ValidatorAddress } from "../constants"
import {
TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../constants"
import {
type NexusClient,
createSmartAccountClient
Expand Down Expand Up @@ -69,7 +72,9 @@ describe("nexus.client", async () => {
signer: account,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})
nexusAccountAddress = await nexusClient.account.getCounterFactualAddress()
})
Expand Down Expand Up @@ -234,7 +239,7 @@ describe("nexus.client", async () => {
nexusClient.isModuleInstalled({
module: {
type: "validator",
address: k1ValidatorAddress,
address: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
initData: "0x"
}
}),
Expand Down Expand Up @@ -270,14 +275,18 @@ describe("nexus.client", async () => {
signer: viemSigner,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})

const ethersNexusClient = await createSmartAccountClient({
signer: wallet as EthersWallet,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})

const sig1 = await viemNexusClient.signMessage({ message: "123" })
Expand All @@ -292,7 +301,9 @@ describe("nexus.client", async () => {
signer: ethersWallet as EthersWallet,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
k1ValidatorAddress: TEST_ADDRESS_K1_VALIDATOR_ADDRESS,
factoryAddress: TEST_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
})

const hash = await ethersNexusClient.sendUserOperation({
Expand Down
8 changes: 4 additions & 4 deletions src/sdk/clients/createSmartAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
import type { EthersWallet } from "../account/utils/Utils"
import type { EthereumProvider } from "../account/utils/toSigner"
import {
k1ValidatorAddress as k1ValidatorAddress_,
k1ValidatorFactoryAddress
MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS
} from "../constants"
import type {
AnyData,
Expand Down Expand Up @@ -205,8 +205,8 @@ export async function createSmartAccountClient(
key = "nexus client",
name = "Nexus Client",
module,
factoryAddress = k1ValidatorFactoryAddress,
k1ValidatorAddress = k1ValidatorAddress_,
factoryAddress = MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS,
k1ValidatorAddress = MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
bundlerTransport,
transport,
accountAddress,
Expand Down
11 changes: 7 additions & 4 deletions src/sdk/clients/decorators/bundler/getGasFeeValues.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Account, Chain, Client, Hex, Transport } from "viem"
import { isTesting } from "../../../account/utils/Utils"

export type BicoRpcSchema = [
{
Expand Down Expand Up @@ -66,10 +65,14 @@ export const getGasFeeValues = async (
BicoRpcSchema
>
): Promise<GetGasFeeValuesReturnType> => {
const isABiconomyBundler = client.transport.url
.toLowerCase()
.includes("biconomy")

const gasPrice = await client.request({
method: isTesting()
? "pimlico_getUserOperationGasPrice"
: "biconomy_getGasFeeValues",
method: isABiconomyBundler
? "biconomy_getGasFeeValues"
: "pimlico_getUserOperationGasPrice",
params: []
})

Expand Down
Loading

0 comments on commit 2276b71

Please sign in to comment.