Skip to content

Commit

Permalink
Feature/added estimation tests (#64)
Browse files Browse the repository at this point in the history
* fixed EtherspotTokenTransferTransaction test

* added estimation tests and fixed newly discovered issues

* added estimates test for onEstimated prop

* added estimation tests with error message, added second batch within batched group tests, updated changelog

* added estimated by batch group ID
  • Loading branch information
poocart authored Oct 24, 2023
1 parent f964273 commit 1c12f8e
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.6.2] - 2023-10-24

### Added Changes
- Added missing `useEtherspotTransactions` hook tests for `estimate` method
- Fixed `skip` prop to ignore batch group estimations
- Fixed batching for same chain ID SDK instance

## [0.6.1] - 2023-10-24

### Added Changes
Expand Down
57 changes: 57 additions & 0 deletions __mocks__/@etherspot/prime-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const otherAccountAddress = '0xAb4C67d8D7B248B2fA6B638C645466065fE8F1F1'

export class PrimeSdk {
sdkChainId;
userOps = [];

constructor (provider, config) {
this.sdkChainId = config.chainId;
Expand Down Expand Up @@ -177,6 +178,62 @@ export class PrimeSdk {

return { items: prices }
}

async clearUserOpsFromBatch() {
this.userOps = [];
}

async addUserOpsToBatch(userOp) {
this.userOps.push(userOp);
}

async estimate(paymaster) {
let maxFeePerGas = ethers.utils.parseUnits('1', 'gwei');
let maxPriorityFeePerGas = ethers.utils.parseUnits('1', 'gwei');
let callGasLimit = ethers.BigNumber.from('50000');

if (paymaster?.url === 'someUrl') {
maxFeePerGas = ethers.utils.parseUnits('2', 'gwei');
maxPriorityFeePerGas = ethers.utils.parseUnits('3', 'gwei');
callGasLimit = ethers.BigNumber.from('75000');
}

let finalGasLimit = ethers.BigNumber.from(callGasLimit);

if (this.sdkChainId === 420) {
throw new Error('Transaction reverted: chain too high');
}

this.userOps.forEach((userOp) => {
if (userOp.to === '0xDEADBEEF') {
throw new Error('Transaction reverted: invalid address');
}
finalGasLimit = finalGasLimit.add(callGasLimit);
if (userOp.data
&& userOp.data !== '0x0'
&& userOp.data !== '0xFFF') {
finalGasLimit = finalGasLimit.add(callGasLimit);
}
});

return {
sender: defaultAccountAddress,
nonce: ethers.BigNumber.from(1),
initCode: '0x001',
callData: '0x002',
callGasLimit: finalGasLimit,
verificationGasLimit: ethers.BigNumber.from('25000'),
preVerificationGas: ethers.BigNumber.from('75000'),
maxFeePerGas,
maxPriorityFeePerGas,
paymasterAndData: '0x003',
signature: '0x004',
}
}

totalGasEstimated({ callGasLimit, verificationGasLimit, preVerificationGas }) {
return callGasLimit.add(verificationGasLimit).add(preVerificationGas);
}
}

export const isWalletProvider = EtherspotPrime.isWalletProvider;
Expand Down
Loading

0 comments on commit 1c12f8e

Please sign in to comment.