Skip to content

Commit

Permalink
chore: devEx test
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Jan 15, 2025
2 parents 061709c + 24bded1 commit 74a7e09
Show file tree
Hide file tree
Showing 24 changed files with 1,396 additions and 474 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Patch Changes

- Added Mee Client
- Upgrade smart session and rhinestone sdk version

## 0.0.24

Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"viem": "2.21.6",
"vitest": "^1.3.1",
"yargs": "^17.7.2",
"@rhinestone/module-sdk": "0.1.28"
"@rhinestone/module-sdk": ">=0.1.0 <=0.2.3"
},
"peerDependencies": {
"typescript": "^5",
"viem": "^2.20.0",
"@rhinestone/module-sdk": "0.1.28"
"@rhinestone/module-sdk": ">=0.1.0 <=0.2.3"
},
"exports": {
".": {
Expand Down
1 change: 0 additions & 1 deletion src/sdk/account/decorators/queryBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ describe("mee:queryBridge", () => {

expect(payload?.amount).toBeGreaterThan(0n)
expect(payload?.receivedAtDestination).toBeGreaterThan(0n)
expect(payload?.plugin).toBe(toAcrossPlugin())
})
})
2 changes: 1 addition & 1 deletion src/sdk/account/toNexusAccount.addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("nexus.account.addresses", async () => {
const testnetAddress = await testnetClient.account.getAddress()
const mainnetAddress = await mainnetClient.account.getAddress()

expect(testnetAddress).not.toBe(mainnetAddress)
expect(testnetAddress).toBe(mainnetAddress)
})

test("should test a mee account", async () => {
Expand Down
3 changes: 3 additions & 0 deletions src/sdk/clients/createBicoPaymasterClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ describe("bico.paymaster", async () => {
bundlerTransport: http(bundlerUrl)
})

console.log(nexusClient.account.address, "nexusClient.account.address")

const initialBalance = await publicClient.getBalance({
address: nexusAccountAddress
})
Expand All @@ -160,6 +162,7 @@ describe("bico.paymaster", async () => {
feeTokenAddress: baseSepoliaUSDCAddress
})
const receipt = await nexusClient.waitForUserOperationReceipt({ hash })

expect(receipt.success).toBe("true")

// Get final balance
Expand Down
32 changes: 21 additions & 11 deletions src/sdk/clients/createMeeClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,49 +165,59 @@ describe("mee.createMeeClient", async () => {
})

test.runIf(runPaidTests)(
"should execute a quote with a single call, and wait for the receipt",
"should demo the devEx for getting a quote with preconfigured instructions, then signing and executing it",
async () => {
console.time("execute:hashTimer")
// Start performance timing for tracking how long the transaction hash and receipt take
console.time("execute:hashTimer")
console.time("execute:receiptTimer")

// Create an array of instructions that will be executed as a single transaction
const instructions = [
// First instruction: Bridge USDC tokens
mcNexus.buildInstructions({
action: {
type: "BRIDGE",
parameters: {
amount: BigInt(1000),
mcToken: mcUSDC,
chain: base
amount: BigInt(1000), // Amount of tokens to bridge (in smallest unit, e.g., wei)
mcToken: mcUSDC, // The multichain USDC token being bridged
chain: base // Destination chain (Base network)
}
}
}),
// Second instruction: Execute a simple call on the Base network
mcNexus.buildInstructions({
action: {
type: "DEFAULT",
parameters: [
{
calls: [
{
to: "0x0000000000000000000000000000000000000000",
gasLimit: 50000n,
value: 0n
to: "0x0000000000000000000000000000000000000000", // Target contract (zero address in this test)
gasLimit: 50000n, // Maximum gas allowed for this call
value: 0n // No ETH being sent with the call
}
],
chainId: base.id
chainId: base.id // Execute this call on the Base network
}
]
}
})
]

const { hash } = await meeClient.execute({
// Get a quote for executing all instructions
// This will calculate the total cost in the specified payment token
const quote = await meeClient.getQuote({
instructions,
feeToken: {
address: paymentToken,
chainId: paymentChain.id
address: paymentToken, // Token used to pay for the transaction
chainId: paymentChain.id // Chain where the payment will be processed
}
})

// Execute the quote and get back a transaction hash
// This sends the transaction to the network
const { hash } = await meeClient.executeQuote({ quote })
expect(hash).toBeDefined()
console.timeEnd("execute:hashTimer")
const receipt = await meeClient.waitForSupertransactionReceipt({ hash })
Expand Down
26 changes: 16 additions & 10 deletions src/sdk/clients/createNexusSessionClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isSessionEnabled } from "@rhinestone/module-sdk"
import { http, type Address, type Chain, type Hex } from "viem"
import type { LocalAccount, PublicClient } from "viem"
import { encodeFunctionData } from "viem"
Expand All @@ -13,11 +14,7 @@ import {
} from "../../test/testUtils"
import type { MasterClient, NetworkConfig } from "../../test/testUtils"
import { SMART_SESSIONS_ADDRESS, SmartSessionMode } from "../constants"
import {
isPermissionEnabled,
parse,
stringify
} from "../modules/smartSessionsValidator/Helpers"
import { parse, stringify } from "../modules/smartSessionsValidator/Helpers"
import type {
CreateSessionDataParams,
SessionData
Expand Down Expand Up @@ -121,7 +118,8 @@ describe("nexus.session.client", async () => {
actionPoliciesInfo: [
{
contractAddress: testAddresses.Counter, // counter address
functionSelector: "0x273ea3e3" as Hex // function selector for increment count
functionSelector: "0x273ea3e3" as Hex, // function selector for increment count,
sudo: true
}
]
}
Expand Down Expand Up @@ -157,9 +155,13 @@ describe("nexus.session.client", async () => {

expect(receipt.success).toBe(true)

const isEnabled = await isPermissionEnabled({
const isEnabled = await isSessionEnabled({
client: nexusClient.account.client as PublicClient,
accountAddress: nexusClient.account.address,
account: {
type: "nexus",
address: nexusClient.account.address,
deployedOnChains: [chain.id]
},
permissionId: createSessionsResponse.permissionIds[0]
})
expect(isEnabled).toBe(true)
Expand Down Expand Up @@ -243,9 +245,13 @@ describe("nexus.session.client", async () => {
smartSessionUseActions(usePermissionsModule)
)

const isEnabled = await isPermissionEnabled({
const isEnabled = await isSessionEnabled({
client: testClient as unknown as PublicClient,
accountAddress: nexusClient.account.address,
account: {
type: "nexus",
address: nexusClient.account.address,
deployedOnChains: [chain.id]
},
permissionId: sessionData.moduleData.permissionIds[0]
})
expect(isEnabled).toBe(true)
Expand Down
Loading

0 comments on commit 74a7e09

Please sign in to comment.