Skip to content

Commit

Permalink
Added new test cases for xdai network and added api test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jineshdarjee committed Oct 19, 2023
1 parent f52ecd7 commit 55732ee
Show file tree
Hide file tree
Showing 19 changed files with 7,689 additions and 1,351 deletions.
6 changes: 5 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ INVALID_ARBITRUM_CHAINID="42511"
OPTIMISM_CHAINID="10"
INVALID_OPTIMISM_CHAINID="09"
POLYGON_CHAINID="137"
POLYGON_CHAINID_TESTNET="80001"
INVALID_POLYGON_CHAINID="189"
XDAI_CHAINID="100"
INVALID_XDAI_CHAINID="105"
PRIVATE_KEY=_private_key_
PROJECT_KEY=_project_key_
PROJECT_KEY=_project_key_
API_KEY=_api_key_
190 changes: 110 additions & 80 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
"main": "index.js",
"type": "module",
"scripts": {
"test": "mocha --timeout 600000",
"test": "mocha --timeout 600000 --spec test/specs/mainnet-api/arka/mumbai.spec.js",
"test-mainnet": "mocha --timeout 600000 --spec test/specs/mainnet/*/Arbitrum.spec.js --spec test/specs/mainnet/*/Matic.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transfertoken-arbitrum": "mocha --timeout 600000 --spec test/specs/mainnet/01_TransferringFunds/Arbitrum.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transfertoken-matic": "mocha --timeout 600000 --spec test/specs/mainnet/01_TransferringFunds/Matic.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transfertoken-optimism": "mocha --timeout 600000 --spec test/specs/mainnet/01_TransferringFunds/Optimism.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transfertoken-xdai": "mocha --timeout 600000 --spec test/specs/mainnet/01_TransferringFunds/Xdai.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transfertoken": "mocha --timeout 600000 --spec test/specs/mainnet/01_TransferringFunds/*.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transactionhistory-arbitrum": "mocha --timeout 600000 --spec test/specs/mainnet/02_TransactionHistory/Arbitrum.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transactionhistory-matic": "mocha --timeout 600000 --spec test/specs/mainnet/02_TransactionHistory/Matic.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transactionhistory-optimism": "mocha --timeout 600000 --spec test/specs/mainnet/02_TransactionHistory/Optimism.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transactionhistory-xdai": "mocha --timeout 600000 --spec test/specs/mainnet/02_TransactionHistory/Xdai.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-transactionhistory": "mocha --timeout 600000 --spec test/specs/mainnet/02_TransactionHistory/*.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-swap-arbitrum": "mocha --timeout 600000 --spec test/specs/mainnet/03_Swap/Arbitrum.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-swap-matic": "mocha --timeout 600000 --spec test/specs/mainnet/03_Swap/Matic.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-swap-optimism": "mocha --timeout 600000 --spec test/specs/mainnet/03_Swap/Optimism.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-swap": "mocha --timeout 600000 --spec test/specs/mainnet/03_Swap/*.spec.js --reporter mochawesome --reporter-options charts=true,code=false"
"test-mainnet-swap-xdai": "mocha --timeout 600000 --spec test/specs/mainnet/03_Swap/Xdai.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test-mainnet-swap": "mocha --timeout 600000 --spec test/specs/mainnet/03_Swap/*.spec.js --reporter mochawesome --reporter-options charts=true,code=false",
"test_arka": "mocha --timeout 600000 --spec test/specs/mainnet-api/arka/mumbai.spec.js",
"test_skandha": "mocha --timeout 600000 --spec test/specs/mainnet-api/skandha/mumbai.spec.js"
},
"author": "",
"license": "ISC",
Expand All @@ -38,11 +43,12 @@
"eslint-plugin-prettier": "^5.0.0",
"ethers": "5.7.0",
"mocha": "^10.2.0",
"mochawesome": "^7.1.3",
"mochawesome-report-generator": "^6.2.0",
"prettier": "^3.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"ws": "^8.13.0",
"mochawesome": "^7.1.3",
"mochawesome-report-generator": "^6.2.0"
"ws": "^8.13.0"
},
"devDependencies": {
"eslint": "^8.45.0"
Expand Down
19 changes: 19 additions & 0 deletions test/data/api_testData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"eoaAddress": "0xa5494Ed2eB09F37b4b0526a8e4789565c226C84f",
"sender": "0x684E10D67dc4159B813Db70a1DAeB5FcC98bd034",
"recipient": "0x71Bec2309cC6BDD5F1D73474688A6154c28Db4B5",
"amount": 0.000001,
"arbitrum_chainid_mainnet": 42161,
"matic_chainid_mainnet": 137,
"optimism_chainid_mainnet": 10,
"xdai_chainid_mainnet": 100,
"mumbai_chainid_testnet": 80001,
"xdai_chainid_testnet": 5,
"arka_deposit": "https://arka.etherspot.io/deposit",
"arka_whitelist": "https://arka.etherspot.io/whitelist",
"arka_checkwhitelist": "https://arka.etherspot.io/checkWhitelist",
"arka_pimlico": "https://arka.etherspot.io/pimlicoAddress",
"address": "0x684E10D67dc4159B813Db70a1DAeB5FcC98bd034",
"entryPointAddress": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"usdc_token": "USDC"
}
22 changes: 9 additions & 13 deletions test/data/testData.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,22 @@
"providerNetwork_optimism": "https://optimism-bundler.etherspot.io",
"invalidProviderNetwork_optimism": "http://optimism-bundler.etherspot.io",
"otherProviderNetwork_optimism": "https://polygon-bundler.etherspot.io",
"tokenAddress_xdaiUSDC": "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83",
"incorrectTokenAddress_xdaiUSDC": "0xD2AAbb505a5214D7b30b1f830fcfc89B60fb7783",
"invalidTokenAddress_xdaiUSDC": "0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A8",
"providerNetwork_xdai": "https://gnosis-bundler.etherspot.io",
"invalidProviderNetwork_xdai": "http://gnosis-bundler.etherspot.io",
"otherProviderNetwork_xdai": "https://xdai-bundler.etherspot.io",
"incorrect_hash": "0x3df9fe91b29f4b2bf1b148baf2f9E207e98137F8318ccf39eDc930d1ceA551df",
"invalid_hash": "0x3df9fe91b29f4b2bf1b148baf2f9E207e98137F8z18ccf39eDc930d1ceA551df",
"arbitrum_chainid": 42161,
"matic_chainid": 137,
"optimism_chainid": 10,
"xdai_chainid": 100,
"invalid_arbitrum_chainid": 42656,
"invalid_matic_chainid": 19,
"invalid_optimism_chainid": 158,
"invalid_xdai_chainid": 105,
"minimum_token_balance": 0.0001,
"minimum_native_balance": 0.0001,
"arbitrumUsdcAddress": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"invalid_arbitrumUsdcAddress": "0xFe970C61A04b1cA11834A43f5dE4433eBDDB5CC8",
"arbitrumUsdtAddress": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
"invalid_arbitrumUsdtAddress": "0xFD006bC7CDcC481DCC9Cc5ebE478A110b69Ffbb9",
"maticUsdcAddress": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"invalid_maticUsdcAddress": "0x28a1Bca1f22e4661Ee88A30C9997a9449Aa84474",
"maticUsdtAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
"invalid_maticUsdtAddress": "0xcE112D05D31cd14a87Cc611C10788AEb04458e8F",
"optimismUsdcAddress": "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
"invalid_optimismUsdcAddress": "0x7755764cBc1cf9669B88b37ca14a0cCa17c33607",
"optimismUsdtAddress": "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58",
"invalid_optimismUsdtAddress": "0x99b000aA00579c4307B0EF2cc99aD98a8cc58e58"
"minimum_native_balance": 0.0001
}
275 changes: 275 additions & 0 deletions test/specs/mainnet-api/arka/mumbai.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
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 Arka Endpoints with Mumbai Network', () => {
it('SMOKE: Validate the Deposit endpoint of Arka on Mumbai Network', async () => {
const startTime = performance.now();

try {
const response = await fetch(data.arka_deposit, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
params: [
data.amount,
data.mumbai_chainid_testnet,
process.env.API_KEY,
],
}),
});
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);
}
} catch (error) {
console.error('Fetch error:', error);
assert.fail('Getting an error');
}
});

it('SMOKE: Validate the Whitelist endpoint of Arka on Mumbai Network', async () => {
const addresses = [data.address];
const startTime = performance.now();

try {
const response = await fetch(data.arka_whitelist, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
params: [addresses, data.mumbai_chainid_testnet, process.env.API_KEY],
}),
});
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);
}
} catch (error) {
console.error('Fetch error:', error);
assert.fail('Getting an error');
}
});

it('SMOKE: Validate the Check an Address is Whitelist endpoint of Arka on Mumbai Network', async () => {
const sponsorAddress = data.address;
const addresses = '0xE05FB316eB8C4ba7288D43c1bd87BE8a8d16761C';
const startTime = performance.now();

try {
const response = await fetch(data.arka_checkwhitelist, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
params: [
sponsorAddress,
addresses,
data.mumbai_chainid_testnet,
process.env.API_KEY,
],
}),
});
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);
}
} catch (error) {
console.error('Fetch error:', error);
assert.fail('Getting an error');
}
});

it('SMOKE: Validate the Pimlico Paymaster endpoint of Arka on Mumbai Network', async () => {
const context = { token: data.usdc_token };
const startTime = performance.now();

try {
const response = await fetch(data.arka_pimlico, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
params: [
entryPointAddress,
context,
data.mumbai_chainid_testnet,
process.env.API_KEY,
],
}),
});
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);
}
} catch (error) {
console.error('Fetch error:', error);
assert.fail('Getting an error');
}
});

it('SMOKE: Perform the Sponsor a Transaction with Arka and PrimeSDK 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({
url: 'https://arka.etherspot.io/',
api_key: process.env.API_KEY,
context: { mode: 'sponsor' },
});
} 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.',
);
}

// 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.');
}

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');
});
});
Loading

0 comments on commit 55732ee

Please sign in to comment.