Skip to content

Commit

Permalink
added send tests (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
poocart authored Oct 25, 2023
1 parent 1c12f8e commit 9be56c2
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.6.3] - 2023-10-24

### Added Changes
- Added missing `useEtherspotTransactions` hook tests for `send` method

## [0.6.2] - 2023-10-24

### Added Changes
Expand Down
29 changes: 27 additions & 2 deletions __mocks__/@etherspot/prime-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const otherAccountAddress = '0xAb4C67d8D7B248B2fA6B638C645466065fE8F1F1'
export class PrimeSdk {
sdkChainId;
userOps = [];
nonce = ethers.BigNumber.from(1);

constructor (provider, config) {
this.sdkChainId = config.chainId;
Expand Down Expand Up @@ -191,13 +192,18 @@ export class PrimeSdk {
let maxFeePerGas = ethers.utils.parseUnits('1', 'gwei');
let maxPriorityFeePerGas = ethers.utils.parseUnits('1', 'gwei');
let callGasLimit = ethers.BigNumber.from('50000');
let signature = '0x004';

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

if (paymaster?.url === 'someUnstableUrl') {
signature = '0x0';
}

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

if (this.sdkChainId === 420) {
Expand All @@ -218,7 +224,7 @@ export class PrimeSdk {

return {
sender: defaultAccountAddress,
nonce: ethers.BigNumber.from(1),
nonce: this.nonce,
initCode: '0x001',
callData: '0x002',
callGasLimit: finalGasLimit,
Expand All @@ -227,13 +233,32 @@ export class PrimeSdk {
maxFeePerGas,
maxPriorityFeePerGas,
paymasterAndData: '0x003',
signature: '0x004',
signature,
}
}

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

async send(userOp) {
if (this.sdkChainId === 696969) {
throw new Error('Transaction reverted: chain too hot');
}

if (userOp.signature === '0x0') {
throw new Error('Transaction reverted: invalid signature');
}

/**
* provide fake userOp hash by increasing nonce on each send
* and add SDK chain ID to make it more unique per userOp
*/
const userOpHash = this.nonce.add(this.sdkChainId).toHexString();
this.nonce = this.nonce.add(1);

return userOpHash;
}
}

export const isWalletProvider = EtherspotPrime.isWalletProvider;
Expand Down
Loading

0 comments on commit 9be56c2

Please sign in to comment.