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

Modified validation message for transaction fund test case #21

Merged
merged 1 commit into from
Oct 30, 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
218 changes: 0 additions & 218 deletions test/specs/mainnet-api/skandha/mumbai.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { PrimeSdk } from '@etherspot/prime-sdk';
import { ethers } from 'ethers';
import { assert } from 'chai';
// import Helper from '../../../utils/Helper.js';
import data from '../../../data/api_testData.json' assert { type: 'json' };
import * as dotenv from 'dotenv';
dotenv.config(); // init dotenv

let mumbaiTestNetSdk;

/* eslint-disable prettier/prettier */
describe('Performance testing of Skandha Endpoints with Mumbai Network', () => {
it('SMOKE: Validate the skandha_getGasPrice method of the skandha with valid details on Mumbai Network', async () => {
Expand Down Expand Up @@ -285,217 +280,4 @@ describe('Performance testing of Skandha Endpoints with Mumbai Network', () => {
assert.fail('Getting an error');
}
});

it('SMOKE: Perform the transfer native token with valid details on the Mumbai network', async () => {
const startTime = performance.now();

// validate the eth_sendUserOperation method of skandha
try {
const response = await fetch('https://mumbai-bundler.etherspot.io/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
method: 'eth_sendUserOperation',
params: [
{
jsonrpc: '2.0',
id: 1,
method: 'eth_sendUserOperation',
params: [
{
sender, // address
nonce, // uint256
initCode, // bytes
callData, // bytes
callGasLimit, // uint256
verificationGasLimit, // uint256
preVerificationGas, // uint256
maxFeePerGas, // uint256
maxPriorityFeePerGas, // uint256
paymasterAndData, // bytes
signature, // bytes
},
entryPoint, // address
],
},
],
id: 46,
jsonrpc: '2.0',
}),
});
if (!response.ok) {
console.error('Response status:', response.status);
const errorResponse = await response.text();
console.error('Error response:', errorResponse);
assert.fail('Getting an error');
} else {
console.log('Response status:', response.status);
const ttfb_ms = performance.now() - startTime; // Calculate TTFB in milliseconds
const ttfb_s = (ttfb_ms / 1000).toFixed(2);
console.log('Time to First Byte (TTFB):', ttfb_s + ' second');

const returnedValue = await response.json();
console.log('Value returned:', returnedValue);

try {
assert.isNotEmpty(
returnedValue.result,
'The result value is empty in the skandha_getGasPrice response.',
);
} catch (e) {
console.error(e);
assert.fail('Not getting correct response.');
}
}
} catch (error) {
console.error('Fetch error:', error);
assert.fail('Getting an error');
}
});

it('SMOKE: Perform the transfer native token with valid details on the Mumbai network', async () => {
const startTime = performance.now();

// initializating sdk
try {
mumbaiTestNetSdk = new PrimeSdk(
{ privateKey: process.env.PRIVATE_KEY },
{
chainId: Number(process.env.POLYGON_CHAINID_TESTNET),
projectKey: process.env.PROJECT_KEY,
},
);

try {
assert.strictEqual(
mumbaiTestNetSdk.state.walletAddress,
data.eoaAddress,
'The EOA Address is not calculated correctly.',
);
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
assert.fail('The SDK is not initialled successfully.');
}

// get EtherspotWallet address
try {
await mumbaiTestNetSdk.getCounterFactualAddress();
} catch (e) {
console.error(e);
assert.fail(
'The Etherspot Wallet Address is not displayed successfully.',
);
}

// clear the transaction batch
try {
await mumbaiTestNetSdk.clearUserOpsFromBatch();
} catch (e) {
console.error(e);
assert.fail('The transaction of the batch is not clear correctly.');
}

// add transactions to the batch
try {
await mumbaiTestNetSdk.addUserOpsToBatch({
to: data.recipient,
value: ethers.utils.parseEther('0.000001'),
});
} catch (e) {
console.error(e);
assert.fail('The addition of transaction in the batch is not performed.');
}

// get balance of the account address
try {
await mumbaiTestNetSdk.getNativeBalance();
} catch (e) {
console.error(e);
assert.fail('The balance of the native token is not displayed.');
}

// estimate transactions added to the batch and get the fee data for the UserOp
let op;
try {
op = await mumbaiTestNetSdk.estimate();
} catch (e) {
console.error(e);
assert.fail(
'The estimate transactions added to the batch and get the fee data for the UserOp is not performed.',
);
}

// sign the UserOp and sending to the bundler
let uoHash;
try {
uoHash = await mumbaiTestNetSdk.send(op);
} catch (e) {
console.error(e);
assert.fail(
'The sign the UserOp and sending to the bundler action is not performed.',
);
}

// validate the eth_sendUserOperation method of skandha
try {
const response = await fetch('https://mumbai-bundler.etherspot.io/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
method: 'eth_estimateUserOperationGas',
params: [uoHash],
id: 46,
jsonrpc: '2.0',
}),
});
if (!response.ok) {
console.error('Response status:', response.status);
const errorResponse = await response.text();
console.error('Error response:', errorResponse);
assert.fail('Getting an error');
} else {
console.log('Response status:', response.status);
const ttfb_ms = performance.now() - startTime; // Calculate TTFB in milliseconds
const ttfb_s = (ttfb_ms / 1000).toFixed(2);
console.log('Time to First Byte (TTFB):', ttfb_s + ' second');

const returnedValue = await response.json();
console.log('Value returned:', returnedValue);

try {
assert.isNotEmpty(
returnedValue.result,
'The result value is empty in the skandha_getGasPrice response.',
);
} catch (e) {
console.error(e);
assert.fail('Not getting correct response.');
}
}
} catch (error) {
console.error('Fetch error:', error);
assert.fail('Getting an error');
}

// // get transaction hash
// let userOpsReceipt = null;
// try {
// console.log('Waiting for transaction...');
// const timeout = Date.now() + 60000; // 1 minute timeout
// while (userOpsReceipt == null && Date.now() < timeout) {
// await Helper.wait(2000);
// userOpsReceipt = await mumbaiTestNetSdk.getUserOpReceipt(uoHash);
// }
// } catch (e) {
// console.error(e);
// assert.fail('The get transaction hash action is not performed.');
// }
});
});
6 changes: 3 additions & 3 deletions test/specs/mainnet/01_TransferringFunds/Arbitrum.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2049,7 +2049,7 @@ describe('The PrimeSDK, when transfer a token with arbitrum network on the MainN
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -3662,7 +3662,7 @@ describe('The PrimeSDK, when transfer a token with arbitrum network on the MainN
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -4049,7 +4049,7 @@ describe('The PrimeSDK, when transfer a token with arbitrum network on the MainN
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down
12 changes: 6 additions & 6 deletions test/specs/mainnet/01_TransferringFunds/Matic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ describe('The PrimeSDK, when transfer a token with matic network on the MainNet'
}
});

it('REGRESSION: Perform the transfer native token without adding transaction to the batch while estimate the added transactions to the batch on the matic network', async function () {
it.only('REGRESSION: Perform the transfer native token without adding transaction to the batch while estimate the added transactions to the batch on the matic network', async function () {
var test = this;
if (runTest) {
await customRetryAsync(async function () {
Expand Down Expand Up @@ -2049,7 +2049,7 @@ describe('The PrimeSDK, when transfer a token with matic network on the MainNet'
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -3584,7 +3584,7 @@ describe('The PrimeSDK, when transfer a token with matic network on the MainNet'
}
});

it('REGRESSION: Perform the transfer ERC20 token without adding transaction to the batch while estimate the added transactions to the batch on the matic network', async function () {
it.only('REGRESSION: Perform the transfer ERC20 token without adding transaction to the batch while estimate the added transactions to the batch on the matic network', async function () {
var test = this;
if (runTest) {
await customRetryAsync(async function () {
Expand Down Expand Up @@ -3662,7 +3662,7 @@ describe('The PrimeSDK, when transfer a token with matic network on the MainNet'
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -4000,7 +4000,7 @@ describe('The PrimeSDK, when transfer a token with matic network on the MainNet'
}
});

it('REGRESSION: Perform the transfer ERC721 NFT Token without adding transaction to the batch while estimate the added transactions to the batch on the matic network', async function () {
it.only('REGRESSION: Perform the transfer ERC721 NFT Token without adding transaction to the batch while estimate the added transactions to the batch on the matic network', async function () {
var test = this;
if (runTest) {
await customRetryAsync(async function () {
Expand Down Expand Up @@ -4049,7 +4049,7 @@ describe('The PrimeSDK, when transfer a token with matic network on the MainNet'
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down
6 changes: 3 additions & 3 deletions test/specs/mainnet/01_TransferringFunds/Optimism.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ describe('The PrimeSDK, when transfer a token with optimism network on the MainN
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -4076,7 +4076,7 @@ describe('The PrimeSDK, when transfer a token with optimism network on the MainN
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -4908,7 +4908,7 @@ describe('The PrimeSDK, when transfer a token with optimism network on the MainN
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down
13 changes: 6 additions & 7 deletions test/specs/mainnet/01_TransferringFunds/Xdai.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ describe('The PrimeSDK, when transfer a token with xdai network on the MainNet',
}
});

it('REGRESSION: Perform the transfer native token without adding transaction to the batch while estimate the added transactions to the batch on the xdai network', async function () {
it.only('REGRESSION: Perform the transfer native token without adding transaction to the batch while estimate the added transactions to the batch on the xdai network', async function () {
var test = this;
if (runTest) {
await customRetryAsync(async function () {
Expand Down Expand Up @@ -2049,8 +2049,7 @@ describe('The PrimeSDK, when transfer a token with xdai network on the MainNet',
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
console.log('error::::::::', e);
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -3585,7 +3584,7 @@ describe('The PrimeSDK, when transfer a token with xdai network on the MainNet',
}
});

it('REGRESSION: Perform the transfer ERC20 token without adding transaction to the batch while estimate the added transactions to the batch on the xdai network', async function () {
it.only('REGRESSION: Perform the transfer ERC20 token without adding transaction to the batch while estimate the added transactions to the batch on the xdai network', async function () {
var test = this;
if (runTest) {
await customRetryAsync(async function () {
Expand Down Expand Up @@ -3663,7 +3662,7 @@ describe('The PrimeSDK, when transfer a token with xdai network on the MainNet',
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down Expand Up @@ -4001,7 +4000,7 @@ describe('The PrimeSDK, when transfer a token with xdai network on the MainNet',
}
});

it('REGRESSION: Perform the transfer ERC721 NFT Token without adding transaction to the batch while estimate the added transactions to the batch on the xdai network', async function () {
it.only('REGRESSION: Perform the transfer ERC721 NFT Token without adding transaction to the batch while estimate the added transactions to the batch on the xdai network', async function () {
var test = this;
if (runTest) {
await customRetryAsync(async function () {
Expand Down Expand Up @@ -4050,7 +4049,7 @@ describe('The PrimeSDK, when transfer a token with xdai network on the MainNet',
'The expected validation is not displayed when not added the transaction to the batch while adding the estimate transactions to the batch.',
);
} catch (e) {
if (e.message === 'cannot sign empty transaction batch') {
if (e.message === 'cannot sign empty transaction') {
console.log(
'The validation for transaction batch is displayed as expected while adding the estimate transactions to the batch.',
);
Expand Down