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

feat: simulate user op tests + ts doc #503

Merged
merged 7 commits into from
May 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/account/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,8 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
/**
* Builds a user operation
*
* This method will also simulate the validation and execution of the user operation, telling the user if the user operation will be successful or not.
*
* - Docs: https://docs.biconomy.io/Account/transactions/userpaid#build-useroperation
*
* @param transactions Array of {@link Transaction} to be sent.
Expand Down
72 changes: 72 additions & 0 deletions tests/account/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,4 +807,76 @@ describe("Account:Read", () => {

expect(isVerified).toBeTruthy()
})

test.concurrent(
"should simulate a user operation execution, expecting to fail",
async () => {
const smartAccount = await createSmartAccountClient({
signer: walletClient,
bundlerUrl
})

console.log(smartAccountAddress, "smartAccountAdderss")

const balances = await smartAccount.getBalances()
expect(balances[0].amount).toBeGreaterThan(0n)

const encodedCall = encodeFunctionData({
abi: parseAbi(["function deposit()"]),
functionName: "deposit"
})

const amoyTestContract = "0x59Dbe91FBa486CA10E4ad589688Fe547a48bd62A"

// fail if value is not bigger than 1
// the contract call requires a deposit of at least 1 wei
const tx1 = {
to: amoyTestContract as Hex,
data: encodedCall,
value: 0
}
const tx2 = {
to: amoyTestContract as Hex,
data: encodedCall,
value: 2
}

await expect(smartAccount.buildUserOp([tx1, tx2])).rejects.toThrow()
}
)

test.concurrent(
"should simulate a user operation execution, expecting to pass execution",
async () => {
const smartAccount = await createSmartAccountClient({
signer: walletClient,
bundlerUrl
})

const balances = await smartAccount.getBalances()
expect(balances[0].amount).toBeGreaterThan(0n)

const encodedCall = encodeFunctionData({
abi: parseAbi(["function deposit()"]),
functionName: "deposit"
})

const amoyTestContract = "0x59Dbe91FBa486CA10E4ad589688Fe547a48bd62A"

// fail if value is not bigger than 1
// the contract call requires a deposit of at least 1 wei
const tx1 = {
to: amoyTestContract as Hex,
data: encodedCall,
value: 2
}
const tx2 = {
to: amoyTestContract as Hex,
data: encodedCall,
value: 2
}

await expect(smartAccount.buildUserOp([tx1, tx2])).resolves.toBeTruthy()
}
)
})
Loading
Loading