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

Feature/added sending tests #65

Merged
merged 11 commits into from
Oct 25, 2023
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
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