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: index test #163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ PAYMASTER_URL=
PIMLICO_API_KEY=
TENDERLY_API_KEY=
TENDERLY_ACCOUNT_SLUG=
TENDERLY_PROJECT_SLUG=
VIRTUAL_BASE_SEPOLIA=
TENDERLY_PROJECT_SLUG=
1 change: 0 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
PIMLICO_API_KEY: ${{ secrets.PIMLICO_API_KEY }}
PAYMASTER_URL: ${{ secrets.PAYMASTER_URL }}
BUNDLER_URL: ${{ secrets.BUNDLER_URL }}
VIRTUAL_BASE_SEPOLIA: ${{ secrets.VIRTUAL_BASE_SEPOLIA }}
CHAIN_ID: 84532
ALT_CHAIN_ID: 11155420
CI: true
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.24

### Patch Changes

- Remove tenderlyUrl from env vars

## 0.0.23

### Patch Changes
Expand Down
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.23",
"version": "0.0.24",
"author": "Biconomy",
"repository": "github:bcnmy/sdk",
"main": "./dist/_cjs/index.js",
Expand Down
27 changes: 18 additions & 9 deletions src/sdk/clients/createBicoPaymasterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
parseUnits
} from "viem"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import { toNetworks } from "../../test/testSetup"
import { paymasterTruthy, toNetworks } from "../../test/testSetup"
import { killNetwork } from "../../test/testUtils"
import type { NetworkConfig } from "../../test/testUtils"
import { type NexusAccount, toNexusAccount } from "../account/toNexusAccount"
Expand All @@ -25,8 +25,7 @@
createSmartAccountClient
} from "./createSmartAccountClient"

describe.skip("bico.paymaster", async () => {
// describe.runIf(paymasterTruthy())("bico.paymaster", async () => {
describe.runIf(paymasterTruthy())("bico.paymaster", async () => {
let network: NetworkConfig

let chain: Chain
Expand All @@ -48,6 +47,8 @@
const baseSepoliaDAIAddress: Address =
"0x7683022d84f726a96c4a6611cd31dbf5409c0ac9"

const index = 5n

beforeAll(async () => {
;[network] = await toNetworks("TESTNET_FROM_ENV_VARS")

Expand Down Expand Up @@ -76,17 +77,21 @@
nexusAccount = await toNexusAccount({
signer: account,
chain,
transport: http()
transport: http(),
index
})

nexusAccountAddress = await nexusAccount.getCounterFactualAddress()

console.log("nexusAccountAddress", nexusAccountAddress)

nexusClient = await createSmartAccountClient({
signer: account,
chain,
transport: http(),
bundlerTransport: http(bundlerUrl),
paymaster
paymaster,
index
})
})
afterAll(async () => {
Expand Down Expand Up @@ -142,7 +147,8 @@
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
index
})

const initialBalance = await publicClient.getBalance({
Expand All @@ -160,7 +166,7 @@
feeTokenAddress: baseSepoliaUSDCAddress
})
const receipt = await nexusClient.waitForUserOperationReceipt({ hash })
expect(receipt.success).toBe("true")

Check failure on line 169 in src/sdk/clients/createBicoPaymasterClient.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests

src/sdk/clients/createBicoPaymasterClient.test.ts > bico.paymaster > should use token paymaster to pay for gas fees, use max approval, use sendUserOperation

AssertionError: expected 'false' to be 'true' // Object.is equality - Expected + Received - true + false ❯ src/sdk/clients/createBicoPaymasterClient.test.ts:169:29

// Get final balance
const finalBalance = await publicClient.getBalance({
Expand All @@ -184,7 +190,8 @@
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
index
})

const initialBalance = await publicClient.getBalance({
Expand Down Expand Up @@ -215,7 +222,7 @@

// Check that the balance hasn't changed
// No gas fees were paid, so the balance should have decreased only by 1n
expect(finalBalance).toBe(initialBalance - 1n)

Check failure on line 225 in src/sdk/clients/createBicoPaymasterClient.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests

src/sdk/clients/createBicoPaymasterClient.test.ts > bico.paymaster > should use token paymaster to pay for gas fees, use max approval, use sendTransaction

AssertionError: expected 9999999999999996n to be 9999999999999995n // Object.is equality - Expected + Received - 9999999999999995n + 9999999999999996n ❯ src/sdk/clients/createBicoPaymasterClient.test.ts:225:26
})

test("should use token paymaster to pay for gas fees, use custom approval with token paymaster quotes", async () => {
Expand All @@ -230,7 +237,8 @@
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
index
})

const usdcBalance = await publicClient.readContract({
Expand All @@ -242,7 +250,7 @@
args: [nexusClient.account.address]
})

expect(usdcBalance).toBeGreaterThan(0n)

Check failure on line 253 in src/sdk/clients/createBicoPaymasterClient.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests

src/sdk/clients/createBicoPaymasterClient.test.ts > bico.paymaster > should use token paymaster to pay for gas fees, use custom approval with token paymaster quotes

AssertionError: expected 0 to be greater than 0 ❯ src/sdk/clients/createBicoPaymasterClient.test.ts:253:25

const initialBalance = await publicClient.getBalance({
address: nexusClient.account.address
Expand Down Expand Up @@ -299,7 +307,8 @@
}),
paymasterContext,
transport: http(),
bundlerTransport: http(bundlerUrl)
bundlerTransport: http(bundlerUrl),
index
})

const supportedTokens = await paymaster.getSupportedTokens(nexusClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { beforeAll, describe, expect, test } from "vitest"
import { CounterAbi } from "../../../test/__contracts/abi/CounterAbi"
import { testAddresses } from "../../../test/callDatas"
import { toNetwork } from "../../../test/testSetup"
import { getTestParamsForTestnet } from "../../../test/testUtils"
import type { NetworkConfig, TestnetParams } from "../../../test/testUtils"
import type { NetworkConfig } from "../../../test/testUtils"
import { type NexusAccount, toNexusAccount } from "../../account/toNexusAccount"
import { safeMultiplier } from "../../account/utils/Utils"
import {
type NexusClient,
createSmartAccountClient
Expand Down Expand Up @@ -63,6 +63,8 @@ describe("modules.smartSessions.enable.mode.dx", async () => {

let stringifiedSessionDatum: string

const index = 2n

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

Expand All @@ -88,7 +90,7 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
})

nexusAccount = await toNexusAccount({
index: 1n,
index,
signer: eoaAccount,
chain,
transport: http()
Expand All @@ -97,7 +99,7 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
nexusAccountAddress = await nexusAccount.getCounterFactualAddress()

nexusClient = await createSmartAccountClient({
index: 1n,
index,
account: nexusAccount,
signer: eoaAccount,
chain,
Expand Down Expand Up @@ -191,7 +193,7 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
const userOperation = await nexusClient.prepareUserOperation({
verificationGasLimit: 10000000n,
callGasLimit: 10000000n,
preVerificationGas: 10000000n,
preVerificationGas: 100000000n,
calls,
signature: encodeSmartSessionSignature(sessionDetails),
nonce: await nexusClient.account.getNonce({
Expand Down Expand Up @@ -278,7 +280,7 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
// Create a new Nexus client for the session
// This client will be used to interact with the smart contract account using the session key
const smartSessionNexusClient = await createSmartAccountClient({
index: 1n,
index,
accountAddress: usersSessionData.granter,
signer: eoaAccount,
chain,
Expand All @@ -301,7 +303,7 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
const userOpHash = await useSmartSessionNexusClient.usePermission({
verificationGasLimit: 10000000n,
callGasLimit: 10000000n,
preVerificationGas: 10000000n,
preVerificationGas: 100000000n,
calls: [
{
to: testAddresses.Counter,
Expand Down
40 changes: 23 additions & 17 deletions src/test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import type { TestFileNetworkType } from "./testSetup"

config()

const BASE_SEPOLIA_RPC_URL =
"https://virtual.base-sepolia.rpc.tenderly.co/6ccdd33d-d8f4-4476-8d37-63ba0ed0ea8f"

type AnvilInstance = ReturnType<typeof anvil>
type BundlerInstance = ReturnType<typeof alto>
type BundlerDto = {
Expand Down Expand Up @@ -215,17 +218,18 @@ export const toConfiguredAnvil = async ({
chainId: rpcPort,
port: rpcPort,
codeSizeLimit: 1000000000000,
forkUrl: shouldForkBaseSepolia
? process.env.VIRTUAL_BASE_SEPOLIA
: undefined
forkUrl: shouldForkBaseSepolia ? BASE_SEPOLIA_RPC_URL : undefined
}
const instance = anvil(config)
await instance.start()
await initDeployments(rpcPort)
await initDeployments(rpcPort, shouldForkBaseSepolia)
return instance
}

export const initDeployments = async (rpcPort: number) => {
export const initDeployments = async (
rpcPort: number,
shouldForkBaseSepolia = false
) => {
// Hardhat deployment of nexus repo:
console.log(
`using hardhat to deploy nexus contracts to http://localhost:${rpcPort}`
Expand All @@ -234,19 +238,21 @@ export const initDeployments = async (rpcPort: number) => {
await hardhatExec.deploy(rpcPort)
console.log("hardhat deployment complete.")

// Hardcoded bytecode deployment of contracts using setCode:
console.log("setting bytecode with hardcoded calldata.")
const chain = getTestChainFromPort(rpcPort)
const account = getTestAccount()
const testClient = toTestClient(chain, account)

// Dynamic bytecode deployment of contracts using setCode:
console.log("setting bytecode with dynamic calldata from a testnet")
await setByteCodeHardcoded(testClient)
await setByteCodeDynamic(testClient, TEST_CONTRACTS)

console.log("bytecode deployment complete.")
console.log("")
if (!shouldForkBaseSepolia) {
// Hardcoded bytecode deployment of contracts using setCode:
console.log("setting bytecode with hardcoded calldata.")
const chain = getTestChainFromPort(rpcPort)
const account = getTestAccount()
const testClient = toTestClient(chain, account)

console.log("setting bytecode with dynamic calldata from a testnet")
await setByteCodeHardcoded(testClient)
await setByteCodeDynamic(testClient, TEST_CONTRACTS)

console.log("bytecode deployment complete.")
console.log("")
}
}

const portOptions = { exclude: [] as number[] }
Expand Down
Loading