From 19e73b07f8df0e536e2c2cf58c78145ee7d73c0e Mon Sep 17 00:00:00 2001 From: alekswaslet <1346150+alekswaslet@users.noreply.github.com> Date: Wed, 29 May 2024 13:55:09 +0200 Subject: [PATCH 1/3] Added constants for e2e testing --- tests/e2e/api/info.test.ts | 43 +++++++------ tests/e2e/api/jevm.test.ts | 25 ++++---- tests/e2e/api/jvm.test.ts | 37 +++++------ tests/e2e/api/platform.test.ts | 109 ++++++++++++++++----------------- tests/e2e/constants.ts | 7 +++ tests/e2e/wallet/cross.test.ts | 86 ++++++++++++-------------- tests/e2e/wallet/send.test.ts | 62 ++++++++----------- tests/e2e/wallet/stake.test.ts | 66 +++++++++----------- tests/e2e/wallet/wrap.test.ts | 50 +++++++-------- 9 files changed, 227 insertions(+), 258 deletions(-) create mode 100644 tests/e2e/constants.ts diff --git a/tests/e2e/api/info.test.ts b/tests/e2e/api/info.test.ts index e15f2492..359b68c6 100644 --- a/tests/e2e/api/info.test.ts +++ b/tests/e2e/api/info.test.ts @@ -1,101 +1,100 @@ -import { MCNProvider, GenesisJUNEChain, GenesisNetwork } from '../../../src' +import { GenesisJUNEChain } from '../../../src' +import { PROVIDER } from '../constants' describe('InfoAPI', () => { - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - describe('isBootstrapped', () => { test.each([{ chainID: GenesisJUNEChain.id }])('Valid: $chainID', async ({ chainID }) => { - const result = await provider.info.isBootstrapped(chainID) + const result = await PROVIDER.info.isBootstrapped(chainID) expect(result.isBootstrapped).toEqual(true) }) test.failing.each([{ chainID: 'WRONG_CHAIN_ID' }])('Invalid: $chainID', async ({ chainID }) => { - await provider.info.isBootstrapped('WRONG_CHAIN_ID') + await PROVIDER.info.isBootstrapped('WRONG_CHAIN_ID') }) }) describe('getBlockchainID', () => { test.each([{ alias: 'JUNE' }])('Valid: $alias', async ({ alias }) => { - const result = await provider.info.getBlockchainID(alias) + const result = await PROVIDER.info.getBlockchainID(alias) expect(result.blockchainID).toEqual(GenesisJUNEChain.id) }) test.failing.each([{ alias: 'WRONG_ALIAS' }])('Invalid: $alias', async ({ alias }) => { - await provider.info.getBlockchainID('alias') + await PROVIDER.info.getBlockchainID('alias') }) }) describe('getNetworkID', () => { test('Returns correct network id', async () => { - const result = await provider.info.getNetworkID() - expect(result.networkID).toEqual(provider.mcn.id.toString()) + const result = await PROVIDER.info.getNetworkID() + expect(result.networkID).toEqual(PROVIDER.mcn.id.toString()) }) }) describe('getNetworkName', () => { test('Returns correct network name', async () => { - const result = await provider.info.getNetworkName() - expect(result.networkName).toEqual(provider.mcn.hrp) + const result = await PROVIDER.info.getNetworkName() + expect(result.networkName).toEqual(PROVIDER.mcn.hrp) }) }) describe('getNodeID', () => { test('Returns node id', async () => { - const result = await provider.info.getNodeID() + const result = await PROVIDER.info.getNodeID() expect(result).toBeDefined() }) }) describe('getNodeIP', () => { test('Returns node ip', async () => { - const result = await provider.info.getNodeIP() + const result = await PROVIDER.info.getNodeIP() expect(result).toBeDefined() }) }) describe('getNodeVersion', () => { test('Returns node version', async () => { - const result = await provider.info.getNodeVersion() + const result = await PROVIDER.info.getNodeVersion() expect(result).toBeDefined() }) }) describe('getTxFee', () => { test('Returns fee config', async () => { - const result = await provider.info.getTxFee() + const result = await PROVIDER.info.getTxFee() expect(result).toBeDefined() }) test('Returns cached fee config', async () => { - const result = await provider.info.getTxFee() + const result = await PROVIDER.info.getTxFee() expect(result).toBeDefined() }) test('Returns updated fee config', async () => { - const result = await provider.info.getTxFee(true) + const result = await PROVIDER.info.getTxFee(true) expect(result).toBeDefined() }) }) describe('getVMs', () => { test('Returns installed VMs', async () => { - const result = await provider.info.getVMs() + const result = await PROVIDER.info.getVMs() expect(result).toBeDefined() }) }) describe('peers', () => { test('Returns list of peers', async () => { - const result = await provider.info.peers() + const result = await PROVIDER.info.peers() expect(result).toBeDefined() }) test.failing.each([ { nodeIDs: ['WRONG_NODE_ID', 'NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPw'] }, - { nodeIDs: ['NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPa'] } + { nodeIDs: ['NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPa'] }, ])('Invalid: $nodeIDs', async ({ nodeIDs }) => { - await provider.info.peers(nodeIDs) + await PROVIDER.info.peers(nodeIDs) }) }) describe('uptime', () => { test.failing.each([{ supernetID: 'WRONG_SUPERNET_ID' }])('Invalid: $supernetID', async ({ supernetID }) => { - await provider.info.uptime(supernetID) + await PROVIDER.info.uptime(supernetID) }) }) }) diff --git a/tests/e2e/api/jevm.test.ts b/tests/e2e/api/jevm.test.ts index a13161dd..296a5502 100644 --- a/tests/e2e/api/jevm.test.ts +++ b/tests/e2e/api/jevm.test.ts @@ -1,15 +1,14 @@ -import { MCNProvider, GenesisEUROC1Asset, GenesisJUNEChain, GenesisNetwork } from '../../../src' +import { GenesisEUROC1Asset, GenesisJUNEChain } from '../../../src' +import { PROVIDER } from '../constants' describe('JEVMAPI', () => { - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - describe('getTx', () => { test.failing.each([ { txID: '241mEKvJjtzAbVxvSsooEaAYgXkaipSDuxEoXBxBDP8mKHb8Cm' }, { txID: '0x3c529e9941b6ca0ec34948c7f797e94ff810643ef64896c409ea0df36be9e554' }, - { txID: 'INVALID_TX_ID' } + { txID: 'INVALID_TX_ID' }, ])('Invalid: $txID', async ({ txID }) => { - const result = await provider.jevmApi[GenesisJUNEChain.id].getTx(txID) + const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].getTx(txID) expect(result.tx).toBeDefined() }) }) @@ -20,42 +19,42 @@ describe('JEVMAPI', () => { description: 'Wrong address', address: '0x9b31d8C5Dd49fCdE96218895f96a6eC894529', block: '0x4BF7C5', - assetID: GenesisEUROC1Asset.assetId + assetID: GenesisEUROC1Asset.assetId, }, { description: 'Wrong block', address: '0x9b31d8C5Dd49fCdE96218895f96a6eC1ea894529', block: '2000', - assetID: GenesisEUROC1Asset.assetId + assetID: GenesisEUROC1Asset.assetId, }, { description: 'Wrong assetID', address: '0x9b31d8C5Dd49fCdE96218895f96a6eC1ea894529', block: '0x4BF7C5', - assetID: '0x0' - } + assetID: '0x0', + }, ])('$description: $address, $block, $assetID', async ({ address, block, assetID }) => { - await provider.jevmApi[GenesisJUNEChain.id].eth_getAssetBalance(address, block, assetID) + await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_getAssetBalance(address, block, assetID) }) }) describe('eth_baseFee', () => { test('Returns base fee', async () => { - const result = await provider.jevmApi[GenesisJUNEChain.id].eth_baseFee() + const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_baseFee() expect(result).toBeDefined() }) }) describe('eth_maxPriorityFeePerGas', () => { test('Returns max priority fee per gas', async () => { - const result = await provider.jevmApi[GenesisJUNEChain.id].eth_maxPriorityFeePerGas() + const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_maxPriorityFeePerGas() expect(result).toBeDefined() }) }) describe('eth_getChainConfig', () => { test('Returns chain config', async () => { - const result = await provider.jevmApi[GenesisJUNEChain.id].eth_getChainConfig() + const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_getChainConfig() expect(result).toBeDefined() }) }) diff --git a/tests/e2e/api/jvm.test.ts b/tests/e2e/api/jvm.test.ts index 680d9bf3..8428f54f 100644 --- a/tests/e2e/api/jvm.test.ts +++ b/tests/e2e/api/jvm.test.ts @@ -1,18 +1,15 @@ import { - MCNProvider, + GenesisBCH1Asset, + GenesisETH1Asset, + GenesisJUNEAsset, type GetAssetDescriptionResponse, type GetBlockResponse, type GetHeightResponse, type GetTxResponse, - GenesisNetwork, - GenesisJUNEAsset, - GenesisETH1Asset, - GenesisBCH1Asset } from '../../../src' +import { PROVIDER } from '../constants' describe('JVMAPI', () => { - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - describe('buildGenesis', () => { // TODO later }) @@ -21,20 +18,20 @@ describe('JVMAPI', () => { test.each([{ asset: GenesisJUNEAsset }, { asset: GenesisETH1Asset }, { asset: GenesisBCH1Asset }])( 'Valid: $asset.assetId ($asset.symbol)', async ({ asset }) => { - const result: GetAssetDescriptionResponse = await provider.jvmApi.getAssetDescription(asset.assetId) + const result: GetAssetDescriptionResponse = await PROVIDER.jvmApi.getAssetDescription(asset.assetId) // TODO in Socotra2 use asset name expect(result.name).toBeDefined() expect(result.symbol).toEqual(asset.symbol) expect(result.denomination).toEqual(asset.decimals.toString()) expect(result.assetID).toEqual(asset.assetId) - } + }, ) test.failing.each([ { assetId: '2RcLCZTsxSnvzeBvtrjRo8PCzLXuecHBoyr8DNp1R8ob8kHkbZ' }, - { assetId: 'INVALID_ASSET_ID' } + { assetId: 'INVALID_ASSET_ID' }, ])('Invalid: $assetId', async ({ assetId }) => { - const result: GetAssetDescriptionResponse = await provider.jvmApi.getAssetDescription(assetId) + const result: GetAssetDescriptionResponse = await PROVIDER.jvmApi.getAssetDescription(assetId) expect(result.name).toBeDefined() }) }) @@ -47,25 +44,25 @@ describe('JVMAPI', () => { test.each([{ height: 1 }, { height: 10 }, { height: 100 }, { height: null }, { height: undefined }])( 'Valid: $height', async ({ height }) => { - const result: GetBlockResponse = await provider.jvmApi.getBlockByHeight(height as any) + const result: GetBlockResponse = await PROVIDER.jvmApi.getBlockByHeight(height as any) expect(result.block).toBeDefined() expect(result.encoding).toBeDefined() - } + }, ) test.failing.each([ { description: 'Negative height', height: -1 }, { description: 'String input', height: 'aString' }, { description: 'Object input', height: {} }, - { description: 'Array input', height: [] } + { description: 'Array input', height: [] }, ])('$description: $height', async ({ height }) => { - await provider.jvmApi.getBlockByHeight(height as any) + await PROVIDER.jvmApi.getBlockByHeight(height as any) }) }) describe('getHeight', () => { test('Returns height', async () => { - const result: GetHeightResponse = await provider.jvmApi.getHeight() + const result: GetHeightResponse = await PROVIDER.jvmApi.getHeight() expect(result.height).toBeDefined() }) }) @@ -73,9 +70,9 @@ describe('JVMAPI', () => { describe('getTx', () => { test.each([ { txID: 'dGJVWGj3GHQRAvt87xqcVUwKNKcJRaB7iUwGpNP9PYSrk6rie' }, - { txID: '2FKNX3WoJwtbanNxVV44qaXsv8SgkiBtD4psHC2wdbLizXvGS' } + { txID: '2FKNX3WoJwtbanNxVV44qaXsv8SgkiBtD4psHC2wdbLizXvGS' }, ])('Valid: $txID', async ({ txID }) => { - const result: GetTxResponse = await provider.jvmApi.getTx(txID) + const result: GetTxResponse = await PROVIDER.jvmApi.getTx(txID) expect(result.encoding).toBeDefined() expect(result.tx).toBeDefined() }) @@ -86,9 +83,9 @@ describe('JVMAPI', () => { { description: 'Null input', txID: null }, { description: 'Undefined input', txID: undefined }, { description: 'Object input', txID: {} }, - { description: 'Array input', txID: [] } + { description: 'Array input', txID: [] }, ])('$description: $txID', async ({ txID }) => { - await provider.jvmApi.getTx(txID as any) + await PROVIDER.jvmApi.getTx(txID as any) }) }) diff --git a/tests/e2e/api/platform.test.ts b/tests/e2e/api/platform.test.ts index 420e6487..5cc96850 100644 --- a/tests/e2e/api/platform.test.ts +++ b/tests/e2e/api/platform.test.ts @@ -1,14 +1,13 @@ -import { MCNProvider, GenesisBCH1Chain, GenesisJUNEChain, type GetBlockResponse, GenesisNetwork } from '../../../src' +import { GenesisBCH1Chain, GenesisJUNEChain, type GetBlockResponse } from '../../../src' +import { PROVIDER } from '../constants' describe('PlatformAPI', () => { - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - describe('getBlock', () => { test.each([ { blockID: '2qbN8EiGKprtFLkQxnQMgqbXSWdui5rwVUTsQp5Z5RYFphy1oK' }, - { blockID: '2K8nAXkMwgnJRCFMAS7KiJSkBbDYKtFP6JH7ww2YiAjg6XnN69' } + { blockID: '2K8nAXkMwgnJRCFMAS7KiJSkBbDYKtFP6JH7ww2YiAjg6XnN69' }, ])('Valid blockID: $blockID', async ({ blockID }) => { - const result: GetBlockResponse = await provider.platformApi.getBlock(blockID) + const result: GetBlockResponse = await PROVIDER.platformApi.getBlock(blockID) expect(result.block).toBeDefined() expect(result.encoding).toBeDefined() }) @@ -16,9 +15,9 @@ describe('PlatformAPI', () => { test.failing.each([ { description: 'Invalid blockID', blockID: 'INVALID_BLOCK_ID' }, { description: 'Null input', blockID: null }, - { description: 'Undefined input', blockID: undefined } + { description: 'Undefined input', blockID: undefined }, ])('$description: $blockID', async ({ blockID }) => { - await provider.platformApi.getBlock(blockID as any) + await PROVIDER.platformApi.getBlock(blockID as any) }) }) @@ -34,24 +33,24 @@ describe('PlatformAPI', () => { test.each([ { blockchainID: GenesisJUNEChain.id }, { blockchainID: GenesisBCH1Chain.id }, - { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' } + { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' }, ])('Valid blockchainID: $blockchainID', async ({ blockchainID }) => { - const result = await provider.platformApi.getBlockchainStatus(blockchainID) + const result = await PROVIDER.platformApi.getBlockchainStatus(blockchainID) expect(result.status).toBeDefined() }) test.failing.each([ { description: 'Invalid blockchainID', blockchainID: 'INVALID_BLOCKCHAIN_ID' }, { description: 'Null input', blockchainID: null }, - { description: 'Undefined input', blockchainID: undefined } + { description: 'Undefined input', blockchainID: undefined }, ])('$description: $blockchainID', async ({ blockchainID }) => { - await provider.platformApi.getBlockchainStatus(blockchainID as any) + await PROVIDER.platformApi.getBlockchainStatus(blockchainID as any) }) }) describe('getCurrentSupply', () => { test('Returns current supply', async () => { - const result = await provider.platformApi.getCurrentSupply() + const result = await PROVIDER.platformApi.getCurrentSupply() expect(result.supply).toBeDefined() }) }) @@ -59,19 +58,19 @@ describe('PlatformAPI', () => { describe('getCurrentValidators', () => { test.each([ { description: 'Without arguments', supernetID: undefined, nodeIDs: undefined }, - { description: 'With supernetID', supernetID: provider.mcn.primary.id, nodeIDs: undefined }, + { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id, nodeIDs: undefined }, { description: 'With nodeIDs', supernetID: undefined, - nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'] + nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'], }, { description: 'With supernetID and nodeIDs', - supernetID: provider.mcn.primary.id, - nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'] - } + supernetID: PROVIDER.mcn.primary.id, + nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'], + }, ])('$description: $supernetID, $nodeIDs', async ({ supernetID, nodeIDs }) => { - const result = await provider.platformApi.getCurrentValidators(supernetID, nodeIDs) + const result = await PROVIDER.platformApi.getCurrentValidators(supernetID, nodeIDs) expect(result.validators).toBeDefined() }) @@ -81,16 +80,16 @@ describe('PlatformAPI', () => { { description: 'Invalid supernetID and nodeIDs', supernetID: 'INVALID_SUPERNET_ID', - nodeIDs: ['INVALID_NODE_ID'] - } + nodeIDs: ['INVALID_NODE_ID'], + }, ])('$description: $supernetID, $nodeIDs', async ({ supernetID, nodeIDs }) => { - await provider.platformApi.getCurrentValidators(supernetID as any, nodeIDs as any) + await PROVIDER.platformApi.getCurrentValidators(supernetID as any, nodeIDs as any) }) }) describe('getHeight', () => { test('Returns blockchain height', async () => { - const result = await provider.platformApi.getHeight() + const result = await PROVIDER.platformApi.getHeight() expect(result.height).toBeDefined() }) }) @@ -98,9 +97,9 @@ describe('PlatformAPI', () => { describe('getMinStake', () => { test.each([ { description: 'Without supernetID', supernetID: undefined }, - { description: 'With supernetID', supernetID: provider.mcn.primary.id } + { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id }, ])('$description: $supernetID', async ({ supernetID }) => { - const result = await provider.platformApi.getMinStake(supernetID) + const result = await PROVIDER.platformApi.getMinStake(supernetID) expect(result.minDelegatorStake).toBeDefined() expect(result.minValidatorStake).toBeDefined() }) @@ -109,27 +108,27 @@ describe('PlatformAPI', () => { { description: 'Invalid supernetID', supernetID: 'INVALID_SUPERNET_ID' }, { description: 'Permissionned supernet supernetID', - supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' - } + supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW', + }, ])('$description: $supernetID', async ({ supernetID }) => { - await provider.platformApi.getMinStake(supernetID as any) + await PROVIDER.platformApi.getMinStake(supernetID as any) }) }) describe('getStakingAssetID', () => { test.each([ { description: 'Without supernetID', supernetID: undefined }, - { description: 'With supernetID', supernetID: provider.mcn.primary.id } + { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id }, ])('$description: $supernetID', async ({ supernetID }) => { - const result = await provider.platformApi.getStakingAssetID(supernetID) + const result = await PROVIDER.platformApi.getStakingAssetID(supernetID) expect(result.assetID).toBeDefined() }) test.failing.each([{ description: 'Invalid supernetID', supernetID: 'INVALID_SUPERNET_ID' }])( '$description: $supernetID', async ({ supernetID }) => { - await provider.platformApi.getStakingAssetID(supernetID as any) - } + await PROVIDER.platformApi.getStakingAssetID(supernetID as any) + }, ) }) @@ -139,38 +138,38 @@ describe('PlatformAPI', () => { describe('getTimestamp', () => { test('Returns platform timestamp', async () => { - const result = await provider.platformApi.getTimestamp() + const result = await PROVIDER.platformApi.getTimestamp() expect(result.timestamp).toBeDefined() }) }) describe('getTotalStake', () => { - test.each([{ supernetID: provider.mcn.primary.id }])( + test.each([{ supernetID: PROVIDER.mcn.primary.id }])( 'Returns total stake of $supernetID', async ({ supernetID }) => { - const result = await provider.platformApi.getTotalStake(supernetID) + const result = await PROVIDER.platformApi.getTotalStake(supernetID) expect(result.stake).toBeDefined() expect(result.weight).toBeDefined() - } + }, ) test.failing.each([ { description: 'Invalid supernetID', supernetID: 'INVALID_SUPERNET_ID' }, { description: 'Permissionned supernet supernetID', - supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' - } + supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW', + }, ])('$description: $supernetID', async ({ supernetID }) => { - await provider.platformApi.getTotalStake(supernetID as any) + await PROVIDER.platformApi.getTotalStake(supernetID as any) }) }) describe('getTx', () => { test.each([ { txID: '2tCUnxobnWD6PgRMVaBJt6uiUxk9NcjLU6Emczbj64GF7dnkcp' }, - { txID: '27xs3BGknXSSKg86rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' } + { txID: '27xs3BGknXSSKg86rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }, ])('Valid txID: $txID', async ({ txID }) => { - const result = await provider.platformApi.getTx(txID) + const result = await PROVIDER.platformApi.getTx(txID) expect(result.encoding).toBeDefined() expect(result.tx).toBeDefined() }) @@ -178,32 +177,32 @@ describe('PlatformAPI', () => { test.failing.each([ { description: 'Invalid txID', txID: '27xs3BGknXSSKazd6rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }, { description: 'Null txID', txID: null }, - { description: 'Undefined txID', txID: undefined } + { description: 'Undefined txID', txID: undefined }, ])('$description: $txID', async ({ txID }) => { - await provider.platformApi.getTx(txID as any) + await PROVIDER.platformApi.getTx(txID as any) }) }) describe('getTxStatus', () => { test.each([ { txID: '27xs3BGknXSSKg86rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }, - { txID: '2qbN8EiGKprtFLkQxnQMgqbXSWdui5rwVUTsQp5Z5RYFphy1oK' } + { txID: '2qbN8EiGKprtFLkQxnQMgqbXSWdui5rwVUTsQp5Z5RYFphy1oK' }, ])('Valid txID: $txID', async ({ txID }) => { - const result = await provider.platformApi.getTxStatus(txID) + const result = await PROVIDER.platformApi.getTxStatus(txID) expect(result.status).toBeDefined() }) test.failing.each([{ description: 'Invalid txID', txID: '27xs3BGknXSSKazd6rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }])( '$description: $txID', async ({ txID }) => { - await provider.platformApi.getTxStatus(txID as any) - } + await PROVIDER.platformApi.getTxStatus(txID as any) + }, ) }) describe('getValidatorsAt', () => { test.each([{ height: 100 }, { height: 200 }])('Valid height: $height', async ({ height }) => { - const result = await provider.platformApi.getValidatorsAt(height) + const result = await PROVIDER.platformApi.getValidatorsAt(height) expect(result.validators).toBeDefined() }) }) @@ -214,7 +213,7 @@ describe('PlatformAPI', () => { describe('sampleValidators', () => { test.each([{ size: 10 }, { size: 20 }])('Valid size: $size', async ({ size }) => { - const result = await provider.platformApi.sampleValidators(size) + const result = await PROVIDER.platformApi.sampleValidators(size) expect(result.validators).toBeDefined() }) }) @@ -222,26 +221,26 @@ describe('PlatformAPI', () => { describe('validatedBy', () => { test.each([ { blockchainID: GenesisJUNEChain.id }, - { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' } + { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' }, ])('Valid blockchainID: $blockchainID', async ({ blockchainID }) => { - const result = await provider.platformApi.validatedBy(blockchainID) + const result = await PROVIDER.platformApi.validatedBy(blockchainID) expect(result.supernetID).toBeDefined() }) }) describe('validates', () => { test.each([ - { supernetID: provider.mcn.primary.id }, - { supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' } + { supernetID: PROVIDER.mcn.primary.id }, + { supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' }, ])('Valid supernetID: $supernetID', async ({ supernetID }) => { - const result = await provider.platformApi.validates(supernetID) + const result = await PROVIDER.platformApi.validates(supernetID) expect(result.blockchainIDs).toBeDefined() }) test.failing.each([{ description: 'Invalid supernetID', supernetID: 'INVALID_SUPERNET_ID' }])( '$description: $supernetID', async ({ supernetID }) => { - await provider.platformApi.validates(supernetID as any) - } + await PROVIDER.platformApi.validates(supernetID as any) + }, ) }) }) diff --git a/tests/e2e/constants.ts b/tests/e2e/constants.ts new file mode 100644 index 00000000..c18297ae --- /dev/null +++ b/tests/e2e/constants.ts @@ -0,0 +1,7 @@ +import * as dotenv from 'dotenv' +import { GenesisNetwork, MCNAccount, MCNProvider, MCNWallet } from '../../src' +dotenv.config() + +const WALLET = MCNWallet.recover(process.env.MNEMONIC ?? '') +export const PROVIDER: MCNProvider = new MCNProvider(GenesisNetwork) +export const ACCOUNT: MCNAccount = new MCNAccount(PROVIDER, WALLET) diff --git a/tests/e2e/wallet/cross.test.ts b/tests/e2e/wallet/cross.test.ts index 2ecb761e..ba18e906 100644 --- a/tests/e2e/wallet/cross.test.ts +++ b/tests/e2e/wallet/cross.test.ts @@ -1,26 +1,18 @@ import { AccountError, CrossOperation, - InputError, - MCNAccount, - MCNProvider, - MCNWallet, GenesisEUROC1Chain, GenesisJUNEChain, GenesisJVMChain, GenesisPlatformChain, - type ExecutableOperation, - GenesisNetwork, + InputError, NetworkOperationRange, - NetworkOperationType + NetworkOperationType, + type ExecutableOperation, } from '../../../src' -import * as dotenv from 'dotenv' -dotenv.config() +import { ACCOUNT } from '../constants' describe('Cross operations', () => { - const wallet = MCNWallet.recover(process.env.MNEMONIC ?? '') - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - const mcnAccount: MCNAccount = new MCNAccount(provider, wallet) const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') const DEFAULT_TIMEOUT: number = 180_000 const DONE_STATUS = 'Done' @@ -36,57 +28,57 @@ describe('Cross operations', () => { destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(1_000) + value: BigInt(1_000), }, { source: euroChain, destination: juneChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, - value: BigInt('10000000000000') + value: BigInt('10000000000000'), }, { source: juneChain, destination: jvmChain, assetId: juneChain.assetId, symbol: juneChain.asset.symbol, - value: BigInt('100000000000') + value: BigInt('100000000000'), }, { source: juneChain, destination: euroChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, - value: BigInt(5_000) + value: BigInt(5_000), }, { source: juneChain, destination: platformChain, assetId: '0x4400000000000000000000000000000000000000', symbol: 'UNDEFINED', - value: BigInt(6_000) + value: BigInt(6_000), }, { source: juneChain, destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: EXCESSIVE_AMOUNT + value: EXCESSIVE_AMOUNT, }, { source: juneChain, destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(0) + value: BigInt(0), }, { source: juneChain, destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(-1_000) - } + value: BigInt(-1_000), + }, ])( '$#) $value $symbol from $source.name to $destination.name', async ({ source, destination, assetId, value }) => { @@ -98,7 +90,7 @@ describe('Cross operations', () => { expect(operation.range).toEqual(NetworkOperationRange.Supernet) expect(operation.type).toEqual(NetworkOperationType.Cross) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -109,67 +101,67 @@ describe('Cross operations', () => { destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(1_000) + value: BigInt(1_000), }, { source: euroChain, destination: juneChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, - value: BigInt('10000000000000') + value: BigInt('10000000000000'), }, { source: juneChain, destination: jvmChain, assetId: juneChain.assetId, symbol: juneChain.asset.symbol, - value: BigInt('100000000000') + value: BigInt('100000000000'), }, { source: juneChain, destination: platformChain, assetId: juneChain.assetId, symbol: juneChain.asset.symbol, - value: BigInt('1000000000000') + value: BigInt('1000000000000'), }, { source: platformChain, destination: juneChain, assetId: platformChain.assetId, symbol: platformChain.asset.symbol, - value: BigInt(1_000_000) + value: BigInt(1_000_000), }, { source: platformChain, destination: jvmChain, assetId: platformChain.assetId, symbol: platformChain.asset.symbol, - value: BigInt(1_000_000) + value: BigInt(1_000_000), }, { source: jvmChain, destination: platformChain, assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, - value: BigInt(1_000_000) + value: BigInt(1_000_000), }, { source: jvmChain, destination: juneChain, assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, - value: BigInt(1_000_000) - } + value: BigInt(1_000_000), + }, ])( '$#) $value $symbol from $source.name to $destination.name', async ({ source, destination, assetId, value }) => { const operation = new CrossOperation(source, destination, assetId, value) - const summary = await mcnAccount.estimate(operation) - await mcnAccount.execute(summary) + const summary = await ACCOUNT.estimate(operation) + await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(DONE_STATUS) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -181,7 +173,7 @@ describe('Cross operations', () => { assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', value: BigInt(-1), - expectedError: InputError + expectedError: InputError, }, { source: juneChain, @@ -189,7 +181,7 @@ describe('Cross operations', () => { assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', value: EXCESSIVE_AMOUNT, - expectedError: AccountError + expectedError: AccountError, }, { source: juneChain, @@ -197,7 +189,7 @@ describe('Cross operations', () => { assetId: euroChain.assetId, symbol: euroChain.asset.symbol, value: EXCESSIVE_AMOUNT, - expectedError: AccountError + expectedError: AccountError, }, { source: juneChain, @@ -205,7 +197,7 @@ describe('Cross operations', () => { assetId: juneChain.assetId, symbol: juneChain.asset.symbol, value: BigInt(0), - expectedError: InputError + expectedError: InputError, }, { source: juneChain, @@ -213,7 +205,7 @@ describe('Cross operations', () => { assetId: juneChain.assetId, symbol: juneChain.asset.symbol, value: BigInt(0), - expectedError: InputError + expectedError: InputError, }, { source: jvmChain, @@ -221,7 +213,7 @@ describe('Cross operations', () => { assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, value: BigInt(0), - expectedError: InputError + expectedError: InputError, }, { source: jvmChain, @@ -229,7 +221,7 @@ describe('Cross operations', () => { assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, value: BigInt(0), - expectedError: InputError + expectedError: InputError, }, { source: platformChain, @@ -237,7 +229,7 @@ describe('Cross operations', () => { assetId: platformChain.assetId, symbol: platformChain.asset.symbol, value: BigInt(0), - expectedError: InputError + expectedError: InputError, }, { source: platformChain, @@ -245,16 +237,16 @@ describe('Cross operations', () => { assetId: platformChain.assetId, symbol: platformChain.asset.symbol, value: BigInt(0), - expectedError: InputError - } + expectedError: InputError, + }, ])( '$#) $value $symbol from $source.name to $destination.name', async ({ source, destination, assetId, value, expectedError }) => { const operation = new CrossOperation(source, destination, assetId, value) - const summary = await mcnAccount.estimate(operation) - await expect(mcnAccount.execute(summary)).rejects.toThrow(expectedError) + const summary = await ACCOUNT.estimate(operation) + await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) }) diff --git a/tests/e2e/wallet/send.test.ts b/tests/e2e/wallet/send.test.ts index 19adcf51..979de8ab 100644 --- a/tests/e2e/wallet/send.test.ts +++ b/tests/e2e/wallet/send.test.ts @@ -1,22 +1,14 @@ import { AccountError, - MCNAccount, - MCNProvider, - MCNWallet, - SendOperation, GenesisEUROC1Chain, GenesisJUNEChain, GenesisJVMChain, + SendOperation, type ExecutableOperation, - GenesisNetwork } from '../../../src' -import * as dotenv from 'dotenv' -dotenv.config() +import { ACCOUNT } from '../constants' describe('Send operations', () => { - const wallet = MCNWallet.recover(process.env.MNEMONIC ?? '') - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - const mcnAccount: MCNAccount = new MCNAccount(provider, wallet) const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') const DONE_STATUS = 'Done' const DEFAULT_TIMEOUT: number = 180_000 @@ -32,32 +24,32 @@ describe('Send operations', () => { assetId: juneChain.assetId, symbol: juneChain.asset.symbol, value: BigInt(1_000), - recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26' + recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', }, { chain: juneChain, assetId: '0x2d00000000000000000000000000000000000000', symbol: 'ETH.e', value: BigInt(1), - recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26' + recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', }, { chain: euroChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, value: BigInt('10000000000000'), - recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26' - } + recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', + }, ])( '$#) $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient }) => { const operation = new SendOperation(chain, assetId, value, recipient) - const summary = await mcnAccount.estimate(operation) - await mcnAccount.execute(summary) + const summary = await ACCOUNT.estimate(operation) + await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(DONE_STATUS) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -70,7 +62,7 @@ describe('Send operations', () => { symbol: juneChain.asset.symbol, value: BigInt(-1), recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - expectedError: RangeError + expectedError: RangeError, }, { description: 'Excessive amount', @@ -79,7 +71,7 @@ describe('Send operations', () => { symbol: juneChain.asset.symbol, value: EXCESSIVE_AMOUNT, recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - expectedError: AccountError + expectedError: AccountError, }, { description: 'Excessive amount and different assetId', @@ -88,16 +80,16 @@ describe('Send operations', () => { symbol: euroChain.asset.symbol, value: EXCESSIVE_AMOUNT, recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - expectedError: AccountError - } + expectedError: AccountError, + }, ])( '$#) $description $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient, expectedError }) => { const operation = new SendOperation(chain, assetId, value, recipient) - const summary = await mcnAccount.estimate(operation) - await expect(mcnAccount.execute(summary)).rejects.toThrow(expectedError) + const summary = await ACCOUNT.estimate(operation) + await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) }) @@ -110,18 +102,18 @@ describe('Send operations', () => { assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, value: BigInt(10_000_000), - recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal' - } + recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal', + }, ])( '$#) $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient }) => { const operation = new SendOperation(chain, assetId, value, recipient) - const summary = await mcnAccount.estimate(operation) - await mcnAccount.execute(summary) + const summary = await ACCOUNT.estimate(operation) + await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(DONE_STATUS) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -134,7 +126,7 @@ describe('Send operations', () => { symbol: jvmChain.asset.symbol, value: EXCESSIVE_AMOUNT, recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal', - expectedError: AccountError + expectedError: AccountError, }, { description: 'Zero value', @@ -143,16 +135,16 @@ describe('Send operations', () => { symbol: jvmChain.asset.symbol, value: BigInt(0), recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal', - expectedError: TypeError - } + expectedError: TypeError, + }, ])( '$#) $description $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient, expectedError }) => { const operation = new SendOperation(chain, assetId, value, recipient) - const summary = await mcnAccount.estimate(operation) - await expect(mcnAccount.execute(summary)).rejects.toThrow(expectedError) + const summary = await ACCOUNT.estimate(operation) + await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) }) diff --git a/tests/e2e/wallet/stake.test.ts b/tests/e2e/wallet/stake.test.ts index ba603abf..44f88a77 100644 --- a/tests/e2e/wallet/stake.test.ts +++ b/tests/e2e/wallet/stake.test.ts @@ -2,24 +2,16 @@ import { AccountError, DecodingError, DelegatePrimaryOperation, - MCNAccount, - MCNProvider, - MCNWallet, + now, type ChainAccount, type ExecutableOperation, - now, - GenesisNetwork } from '../../../src' -import * as dotenv from 'dotenv' -dotenv.config() +import { ACCOUNT, PROVIDER } from '../constants' const DEFAULT_TIMEOUT: number = 180_000 const ONE_DAY: bigint = BigInt(86_400) -const provider: MCNProvider = new MCNProvider(GenesisNetwork) -const wallet = MCNWallet.recover(process.env.MNEMONIC ?? '') -const mcnAccount: MCNAccount = new MCNAccount(provider, wallet) -const account: ChainAccount = mcnAccount.getAccount(provider.platformChain.id) +const chainAccount: ChainAccount = ACCOUNT.getAccount(PROVIDER.platformChain.id) const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') const DONE_STATUS = 'Done' // for now we take this nodeID. maybe in the future we can select the node Id with a function @@ -44,28 +36,28 @@ describe('Staking operations', (): void => { amount: BigInt(10_000_000), expectedStatus: DONE_STATUS, startTime: currentTime, - endTime: tomorrow - } + endTime: tomorrow, + }, ])( '$#) $amount tokens to delegate node id: $nodeId from $startTime to $endTime', async ({ nodeId, amount, expectedStatus, startTime, endTime }) => { const delegateOperation = new DelegatePrimaryOperation( - provider.platformChain, + PROVIDER.platformChain, nodeId, amount, startTime, endTime, - [account.address], + [chainAccount.address], + 1, + [chainAccount.address], 1, - [account.address], - 1 ) - const summary = await mcnAccount.estimate(delegateOperation) - await mcnAccount.execute(summary) + const summary = await ACCOUNT.estimate(delegateOperation) + await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(expectedStatus) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -77,25 +69,25 @@ describe('Staking operations', (): void => { amount: BigInt(10_000_000), expectedError: DecodingError, startTime: currentTime, - endTime: tomorrow - } + endTime: tomorrow, + }, ])( '$#) $description $amount tokens to delegate node id: $nodeId from $startTime to $endTime', async ({ nodeId, amount, expectedError, startTime, endTime }) => { const delegateOperation = new DelegatePrimaryOperation( - provider.platformChain, + PROVIDER.platformChain, nodeId, amount, startTime, endTime, - [account.address], + [chainAccount.address], + 1, + [chainAccount.address], 1, - [account.address], - 1 ) - await expect(mcnAccount.estimate(delegateOperation)).rejects.toThrow(expectedError) + await expect(ACCOUNT.estimate(delegateOperation)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -107,26 +99,26 @@ describe('Staking operations', (): void => { amount: EXCESSIVE_AMOUNT, expectedError: AccountError, startTime: currentTime, - endTime: tomorrow - } + endTime: tomorrow, + }, ])( '$#) $description $amount tokens to delegate node id: $nodeId from $startTime to $endTime', async ({ nodeId, amount, expectedError, startTime, endTime }) => { const delegateOperation = new DelegatePrimaryOperation( - provider.platformChain, + PROVIDER.platformChain, nodeId, amount, startTime, endTime, - [account.address], + [chainAccount.address], + 1, + [chainAccount.address], 1, - [account.address], - 1 ) - const summary = await mcnAccount.estimate(delegateOperation) - await expect(mcnAccount.execute(summary)).rejects.toThrow(expectedError) + const summary = await ACCOUNT.estimate(delegateOperation) + await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) }) diff --git a/tests/e2e/wallet/wrap.test.ts b/tests/e2e/wallet/wrap.test.ts index de016529..c14a5a3f 100644 --- a/tests/e2e/wallet/wrap.test.ts +++ b/tests/e2e/wallet/wrap.test.ts @@ -1,24 +1,16 @@ import { AccountError, - MCNAccount, - MCNProvider, - MCNWallet, GenesisJUNEChain, GenesisWJUNEAsset, + NetworkOperationRange, + NetworkOperationType, UnwrapOperation, WrapOperation, type ExecutableOperation, - NetworkOperationRange, - NetworkOperationType, - GenesisNetwork } from '../../../src' -import * as dotenv from 'dotenv' -dotenv.config() +import { ACCOUNT } from '../constants' describe('Wrapping operations', () => { - const wallet = MCNWallet.recover(process.env.MNEMONIC ?? '') - const provider: MCNProvider = new MCNProvider(GenesisNetwork) - const mcnAccount: MCNAccount = new MCNAccount(provider, wallet) const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') const DONE_STATUS = 'Done' const DEFAULT_TIMEOUT: number = 180_000 @@ -36,7 +28,7 @@ describe('Wrapping operations', () => { expect(operation.amount).toEqual(amount) expect(operation.range).toEqual(NetworkOperationRange.Chain) expect(operation.type).toEqual(NetworkOperationType.Wrap) - } + }, ) }) @@ -45,12 +37,12 @@ describe('Wrapping operations', () => { '$#) $amount $asset.name in $blockchain.name', async ({ blockchain, asset, amount, expectedStatus }) => { const operation = new WrapOperation(blockchain, asset, amount) - const summary = await mcnAccount.estimate(operation) - await mcnAccount.execute(summary) + const summary = await ACCOUNT.estimate(operation) + await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(expectedStatus) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -61,16 +53,16 @@ describe('Wrapping operations', () => { blockchain: juneChain, asset: wJuneAsset, amount: EXCESSIVE_AMOUNT, - expectedStatus: AccountError - } + expectedStatus: AccountError, + }, ])( '$#) $description $amount $asset.name in $blockchain.name', async ({ blockchain, asset, amount, expectedStatus }) => { const operation = new WrapOperation(blockchain, asset, amount) - const summary = await mcnAccount.estimate(operation) - await expect(mcnAccount.execute(summary)).rejects.toThrow(expectedStatus) + const summary = await ACCOUNT.estimate(operation) + await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedStatus) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) }) @@ -86,7 +78,7 @@ describe('Wrapping operations', () => { expect(operation.amount).toEqual(amount) expect(operation.range).toEqual(NetworkOperationRange.Chain) expect(operation.type).toEqual(NetworkOperationType.Unwrap) - } + }, ) }) @@ -95,12 +87,12 @@ describe('Wrapping operations', () => { '$#) $amount $asset.name in $blockchain.name', async ({ blockchain, asset, amount, expectedStatus }) => { const operation = new UnwrapOperation(blockchain, asset, amount) - const summary = await mcnAccount.estimate(operation) - await mcnAccount.execute(summary) + const summary = await ACCOUNT.estimate(operation) + await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(expectedStatus) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) @@ -111,16 +103,16 @@ describe('Wrapping operations', () => { blockchain: juneChain, asset: wJuneAsset, amount: EXCESSIVE_AMOUNT, - expectedError: AccountError - } + expectedError: AccountError, + }, ])( '$#) $description $amount $asset.name in $blockchain.name', async ({ blockchain, asset, amount, expectedError }) => { const operation = new UnwrapOperation(blockchain, asset, amount) - const summary = await mcnAccount.estimate(operation) - await expect(mcnAccount.execute(summary)).rejects.toThrow(expectedError) + const summary = await ACCOUNT.estimate(operation) + await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT + DEFAULT_TIMEOUT, ) }) }) From e88c81b0dbe055996cd42b171ad9e3be54575484 Mon Sep 17 00:00:00 2001 From: alekswaslet <1346150+alekswaslet@users.noreply.github.com> Date: Wed, 29 May 2024 14:04:04 +0200 Subject: [PATCH 2/3] Moved extra tests constants --- tests/e2e/api/info.test.ts | 2 +- tests/e2e/api/jevm.test.ts | 10 ++--- tests/e2e/api/jvm.test.ts | 14 +++---- tests/e2e/api/platform.test.ts | 48 +++++++++++----------- tests/e2e/constants.ts | 4 ++ tests/e2e/wallet/cross.test.ts | 69 +++++++++++++++----------------- tests/e2e/wallet/send.test.ts | 41 +++++++++---------- tests/e2e/wallet/stake.test.ts | 34 +++++++--------- tests/e2e/wallet/wrap.test.ts | 27 ++++++------- tests/unit/wallet/wallet.test.ts | 4 +- 10 files changed, 121 insertions(+), 132 deletions(-) diff --git a/tests/e2e/api/info.test.ts b/tests/e2e/api/info.test.ts index 359b68c6..5e5c3464 100644 --- a/tests/e2e/api/info.test.ts +++ b/tests/e2e/api/info.test.ts @@ -86,7 +86,7 @@ describe('InfoAPI', () => { }) test.failing.each([ { nodeIDs: ['WRONG_NODE_ID', 'NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPw'] }, - { nodeIDs: ['NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPa'] }, + { nodeIDs: ['NodeID-P1ESFUf8tutmR8hszZUWsXAJEKARZ5SPa'] } ])('Invalid: $nodeIDs', async ({ nodeIDs }) => { await PROVIDER.info.peers(nodeIDs) }) diff --git a/tests/e2e/api/jevm.test.ts b/tests/e2e/api/jevm.test.ts index 296a5502..07a7d16f 100644 --- a/tests/e2e/api/jevm.test.ts +++ b/tests/e2e/api/jevm.test.ts @@ -6,7 +6,7 @@ describe('JEVMAPI', () => { test.failing.each([ { txID: '241mEKvJjtzAbVxvSsooEaAYgXkaipSDuxEoXBxBDP8mKHb8Cm' }, { txID: '0x3c529e9941b6ca0ec34948c7f797e94ff810643ef64896c409ea0df36be9e554' }, - { txID: 'INVALID_TX_ID' }, + { txID: 'INVALID_TX_ID' } ])('Invalid: $txID', async ({ txID }) => { const result = await PROVIDER.jevmApi[GenesisJUNEChain.id].getTx(txID) expect(result.tx).toBeDefined() @@ -19,20 +19,20 @@ describe('JEVMAPI', () => { description: 'Wrong address', address: '0x9b31d8C5Dd49fCdE96218895f96a6eC894529', block: '0x4BF7C5', - assetID: GenesisEUROC1Asset.assetId, + assetID: GenesisEUROC1Asset.assetId }, { description: 'Wrong block', address: '0x9b31d8C5Dd49fCdE96218895f96a6eC1ea894529', block: '2000', - assetID: GenesisEUROC1Asset.assetId, + assetID: GenesisEUROC1Asset.assetId }, { description: 'Wrong assetID', address: '0x9b31d8C5Dd49fCdE96218895f96a6eC1ea894529', block: '0x4BF7C5', - assetID: '0x0', - }, + assetID: '0x0' + } ])('$description: $address, $block, $assetID', async ({ address, block, assetID }) => { await PROVIDER.jevmApi[GenesisJUNEChain.id].eth_getAssetBalance(address, block, assetID) }) diff --git a/tests/e2e/api/jvm.test.ts b/tests/e2e/api/jvm.test.ts index 8428f54f..f373deb6 100644 --- a/tests/e2e/api/jvm.test.ts +++ b/tests/e2e/api/jvm.test.ts @@ -5,7 +5,7 @@ import { type GetAssetDescriptionResponse, type GetBlockResponse, type GetHeightResponse, - type GetTxResponse, + type GetTxResponse } from '../../../src' import { PROVIDER } from '../constants' @@ -24,12 +24,12 @@ describe('JVMAPI', () => { expect(result.symbol).toEqual(asset.symbol) expect(result.denomination).toEqual(asset.decimals.toString()) expect(result.assetID).toEqual(asset.assetId) - }, + } ) test.failing.each([ { assetId: '2RcLCZTsxSnvzeBvtrjRo8PCzLXuecHBoyr8DNp1R8ob8kHkbZ' }, - { assetId: 'INVALID_ASSET_ID' }, + { assetId: 'INVALID_ASSET_ID' } ])('Invalid: $assetId', async ({ assetId }) => { const result: GetAssetDescriptionResponse = await PROVIDER.jvmApi.getAssetDescription(assetId) expect(result.name).toBeDefined() @@ -47,14 +47,14 @@ describe('JVMAPI', () => { const result: GetBlockResponse = await PROVIDER.jvmApi.getBlockByHeight(height as any) expect(result.block).toBeDefined() expect(result.encoding).toBeDefined() - }, + } ) test.failing.each([ { description: 'Negative height', height: -1 }, { description: 'String input', height: 'aString' }, { description: 'Object input', height: {} }, - { description: 'Array input', height: [] }, + { description: 'Array input', height: [] } ])('$description: $height', async ({ height }) => { await PROVIDER.jvmApi.getBlockByHeight(height as any) }) @@ -70,7 +70,7 @@ describe('JVMAPI', () => { describe('getTx', () => { test.each([ { txID: 'dGJVWGj3GHQRAvt87xqcVUwKNKcJRaB7iUwGpNP9PYSrk6rie' }, - { txID: '2FKNX3WoJwtbanNxVV44qaXsv8SgkiBtD4psHC2wdbLizXvGS' }, + { txID: '2FKNX3WoJwtbanNxVV44qaXsv8SgkiBtD4psHC2wdbLizXvGS' } ])('Valid: $txID', async ({ txID }) => { const result: GetTxResponse = await PROVIDER.jvmApi.getTx(txID) expect(result.encoding).toBeDefined() @@ -83,7 +83,7 @@ describe('JVMAPI', () => { { description: 'Null input', txID: null }, { description: 'Undefined input', txID: undefined }, { description: 'Object input', txID: {} }, - { description: 'Array input', txID: [] }, + { description: 'Array input', txID: [] } ])('$description: $txID', async ({ txID }) => { await PROVIDER.jvmApi.getTx(txID as any) }) diff --git a/tests/e2e/api/platform.test.ts b/tests/e2e/api/platform.test.ts index 5cc96850..1ff598e6 100644 --- a/tests/e2e/api/platform.test.ts +++ b/tests/e2e/api/platform.test.ts @@ -5,7 +5,7 @@ describe('PlatformAPI', () => { describe('getBlock', () => { test.each([ { blockID: '2qbN8EiGKprtFLkQxnQMgqbXSWdui5rwVUTsQp5Z5RYFphy1oK' }, - { blockID: '2K8nAXkMwgnJRCFMAS7KiJSkBbDYKtFP6JH7ww2YiAjg6XnN69' }, + { blockID: '2K8nAXkMwgnJRCFMAS7KiJSkBbDYKtFP6JH7ww2YiAjg6XnN69' } ])('Valid blockID: $blockID', async ({ blockID }) => { const result: GetBlockResponse = await PROVIDER.platformApi.getBlock(blockID) expect(result.block).toBeDefined() @@ -15,7 +15,7 @@ describe('PlatformAPI', () => { test.failing.each([ { description: 'Invalid blockID', blockID: 'INVALID_BLOCK_ID' }, { description: 'Null input', blockID: null }, - { description: 'Undefined input', blockID: undefined }, + { description: 'Undefined input', blockID: undefined } ])('$description: $blockID', async ({ blockID }) => { await PROVIDER.platformApi.getBlock(blockID as any) }) @@ -33,7 +33,7 @@ describe('PlatformAPI', () => { test.each([ { blockchainID: GenesisJUNEChain.id }, { blockchainID: GenesisBCH1Chain.id }, - { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' }, + { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' } ])('Valid blockchainID: $blockchainID', async ({ blockchainID }) => { const result = await PROVIDER.platformApi.getBlockchainStatus(blockchainID) expect(result.status).toBeDefined() @@ -42,7 +42,7 @@ describe('PlatformAPI', () => { test.failing.each([ { description: 'Invalid blockchainID', blockchainID: 'INVALID_BLOCKCHAIN_ID' }, { description: 'Null input', blockchainID: null }, - { description: 'Undefined input', blockchainID: undefined }, + { description: 'Undefined input', blockchainID: undefined } ])('$description: $blockchainID', async ({ blockchainID }) => { await PROVIDER.platformApi.getBlockchainStatus(blockchainID as any) }) @@ -62,13 +62,13 @@ describe('PlatformAPI', () => { { description: 'With nodeIDs', supernetID: undefined, - nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'], + nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'] }, { description: 'With supernetID and nodeIDs', supernetID: PROVIDER.mcn.primary.id, - nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'], - }, + nodeIDs: ['NodeID-B2GHMQ8GF6FyrvmPUX6miaGeuVLH9UwHr'] + } ])('$description: $supernetID, $nodeIDs', async ({ supernetID, nodeIDs }) => { const result = await PROVIDER.platformApi.getCurrentValidators(supernetID, nodeIDs) expect(result.validators).toBeDefined() @@ -80,8 +80,8 @@ describe('PlatformAPI', () => { { description: 'Invalid supernetID and nodeIDs', supernetID: 'INVALID_SUPERNET_ID', - nodeIDs: ['INVALID_NODE_ID'], - }, + nodeIDs: ['INVALID_NODE_ID'] + } ])('$description: $supernetID, $nodeIDs', async ({ supernetID, nodeIDs }) => { await PROVIDER.platformApi.getCurrentValidators(supernetID as any, nodeIDs as any) }) @@ -97,7 +97,7 @@ describe('PlatformAPI', () => { describe('getMinStake', () => { test.each([ { description: 'Without supernetID', supernetID: undefined }, - { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id }, + { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id } ])('$description: $supernetID', async ({ supernetID }) => { const result = await PROVIDER.platformApi.getMinStake(supernetID) expect(result.minDelegatorStake).toBeDefined() @@ -108,8 +108,8 @@ describe('PlatformAPI', () => { { description: 'Invalid supernetID', supernetID: 'INVALID_SUPERNET_ID' }, { description: 'Permissionned supernet supernetID', - supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW', - }, + supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' + } ])('$description: $supernetID', async ({ supernetID }) => { await PROVIDER.platformApi.getMinStake(supernetID as any) }) @@ -118,7 +118,7 @@ describe('PlatformAPI', () => { describe('getStakingAssetID', () => { test.each([ { description: 'Without supernetID', supernetID: undefined }, - { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id }, + { description: 'With supernetID', supernetID: PROVIDER.mcn.primary.id } ])('$description: $supernetID', async ({ supernetID }) => { const result = await PROVIDER.platformApi.getStakingAssetID(supernetID) expect(result.assetID).toBeDefined() @@ -128,7 +128,7 @@ describe('PlatformAPI', () => { '$description: $supernetID', async ({ supernetID }) => { await PROVIDER.platformApi.getStakingAssetID(supernetID as any) - }, + } ) }) @@ -150,15 +150,15 @@ describe('PlatformAPI', () => { const result = await PROVIDER.platformApi.getTotalStake(supernetID) expect(result.stake).toBeDefined() expect(result.weight).toBeDefined() - }, + } ) test.failing.each([ { description: 'Invalid supernetID', supernetID: 'INVALID_SUPERNET_ID' }, { description: 'Permissionned supernet supernetID', - supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW', - }, + supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' + } ])('$description: $supernetID', async ({ supernetID }) => { await PROVIDER.platformApi.getTotalStake(supernetID as any) }) @@ -167,7 +167,7 @@ describe('PlatformAPI', () => { describe('getTx', () => { test.each([ { txID: '2tCUnxobnWD6PgRMVaBJt6uiUxk9NcjLU6Emczbj64GF7dnkcp' }, - { txID: '27xs3BGknXSSKg86rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }, + { txID: '27xs3BGknXSSKg86rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' } ])('Valid txID: $txID', async ({ txID }) => { const result = await PROVIDER.platformApi.getTx(txID) expect(result.encoding).toBeDefined() @@ -177,7 +177,7 @@ describe('PlatformAPI', () => { test.failing.each([ { description: 'Invalid txID', txID: '27xs3BGknXSSKazd6rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }, { description: 'Null txID', txID: null }, - { description: 'Undefined txID', txID: undefined }, + { description: 'Undefined txID', txID: undefined } ])('$description: $txID', async ({ txID }) => { await PROVIDER.platformApi.getTx(txID as any) }) @@ -186,7 +186,7 @@ describe('PlatformAPI', () => { describe('getTxStatus', () => { test.each([ { txID: '27xs3BGknXSSKg86rczsFCHTvDLQ4dcH9BrgSwKepQcYB5VGc3' }, - { txID: '2qbN8EiGKprtFLkQxnQMgqbXSWdui5rwVUTsQp5Z5RYFphy1oK' }, + { txID: '2qbN8EiGKprtFLkQxnQMgqbXSWdui5rwVUTsQp5Z5RYFphy1oK' } ])('Valid txID: $txID', async ({ txID }) => { const result = await PROVIDER.platformApi.getTxStatus(txID) expect(result.status).toBeDefined() @@ -196,7 +196,7 @@ describe('PlatformAPI', () => { '$description: $txID', async ({ txID }) => { await PROVIDER.platformApi.getTxStatus(txID as any) - }, + } ) }) @@ -221,7 +221,7 @@ describe('PlatformAPI', () => { describe('validatedBy', () => { test.each([ { blockchainID: GenesisJUNEChain.id }, - { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' }, + { blockchainID: '2k1EyxAV5XYPxnsuPVrKyquUTLC3EMA1c5AhM7r8sRy1Kg7Zje' } ])('Valid blockchainID: $blockchainID', async ({ blockchainID }) => { const result = await PROVIDER.platformApi.validatedBy(blockchainID) expect(result.supernetID).toBeDefined() @@ -231,7 +231,7 @@ describe('PlatformAPI', () => { describe('validates', () => { test.each([ { supernetID: PROVIDER.mcn.primary.id }, - { supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' }, + { supernetID: 'ZLfejkjx2AwkaNbGC7oQxX3gE6G1YLs4FzMimQEG6Us2b7UpW' } ])('Valid supernetID: $supernetID', async ({ supernetID }) => { const result = await PROVIDER.platformApi.validates(supernetID) expect(result.blockchainIDs).toBeDefined() @@ -240,7 +240,7 @@ describe('PlatformAPI', () => { '$description: $supernetID', async ({ supernetID }) => { await PROVIDER.platformApi.validates(supernetID as any) - }, + } ) }) }) diff --git a/tests/e2e/constants.ts b/tests/e2e/constants.ts index c18297ae..4c834eba 100644 --- a/tests/e2e/constants.ts +++ b/tests/e2e/constants.ts @@ -5,3 +5,7 @@ dotenv.config() const WALLET = MCNWallet.recover(process.env.MNEMONIC ?? '') export const PROVIDER: MCNProvider = new MCNProvider(GenesisNetwork) export const ACCOUNT: MCNAccount = new MCNAccount(PROVIDER, WALLET) + +export const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') +export const DONE_STATUS = 'Done' +export const DEFAULT_TIMEOUT: number = 120_000 diff --git a/tests/e2e/wallet/cross.test.ts b/tests/e2e/wallet/cross.test.ts index ba18e906..058061d6 100644 --- a/tests/e2e/wallet/cross.test.ts +++ b/tests/e2e/wallet/cross.test.ts @@ -8,14 +8,11 @@ import { InputError, NetworkOperationRange, NetworkOperationType, - type ExecutableOperation, + type ExecutableOperation } from '../../../src' -import { ACCOUNT } from '../constants' +import { ACCOUNT, DEFAULT_TIMEOUT, DONE_STATUS, EXCESSIVE_AMOUNT } from '../constants' describe('Cross operations', () => { - const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') - const DEFAULT_TIMEOUT: number = 180_000 - const DONE_STATUS = 'Done' const juneChain = GenesisJUNEChain const euroChain = GenesisEUROC1Chain const platformChain = GenesisPlatformChain @@ -28,57 +25,57 @@ describe('Cross operations', () => { destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(1_000), + value: BigInt(1_000) }, { source: euroChain, destination: juneChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, - value: BigInt('10000000000000'), + value: BigInt('10000000000000') }, { source: juneChain, destination: jvmChain, assetId: juneChain.assetId, symbol: juneChain.asset.symbol, - value: BigInt('100000000000'), + value: BigInt('100000000000') }, { source: juneChain, destination: euroChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, - value: BigInt(5_000), + value: BigInt(5_000) }, { source: juneChain, destination: platformChain, assetId: '0x4400000000000000000000000000000000000000', symbol: 'UNDEFINED', - value: BigInt(6_000), + value: BigInt(6_000) }, { source: juneChain, destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: EXCESSIVE_AMOUNT, + value: EXCESSIVE_AMOUNT }, { source: juneChain, destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(0), + value: BigInt(0) }, { source: juneChain, destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(-1_000), - }, + value: BigInt(-1_000) + } ])( '$#) $value $symbol from $source.name to $destination.name', async ({ source, destination, assetId, value }) => { @@ -90,7 +87,7 @@ describe('Cross operations', () => { expect(operation.range).toEqual(NetworkOperationRange.Supernet) expect(operation.type).toEqual(NetworkOperationType.Cross) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -101,57 +98,57 @@ describe('Cross operations', () => { destination: euroChain, assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', - value: BigInt(1_000), + value: BigInt(1_000) }, { source: euroChain, destination: juneChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, - value: BigInt('10000000000000'), + value: BigInt('10000000000000') }, { source: juneChain, destination: jvmChain, assetId: juneChain.assetId, symbol: juneChain.asset.symbol, - value: BigInt('100000000000'), + value: BigInt('100000000000') }, { source: juneChain, destination: platformChain, assetId: juneChain.assetId, symbol: juneChain.asset.symbol, - value: BigInt('1000000000000'), + value: BigInt('1000000000000') }, { source: platformChain, destination: juneChain, assetId: platformChain.assetId, symbol: platformChain.asset.symbol, - value: BigInt(1_000_000), + value: BigInt(1_000_000) }, { source: platformChain, destination: jvmChain, assetId: platformChain.assetId, symbol: platformChain.asset.symbol, - value: BigInt(1_000_000), + value: BigInt(1_000_000) }, { source: jvmChain, destination: platformChain, assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, - value: BigInt(1_000_000), + value: BigInt(1_000_000) }, { source: jvmChain, destination: juneChain, assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, - value: BigInt(1_000_000), - }, + value: BigInt(1_000_000) + } ])( '$#) $value $symbol from $source.name to $destination.name', async ({ source, destination, assetId, value }) => { @@ -161,7 +158,7 @@ describe('Cross operations', () => { const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(DONE_STATUS) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -173,7 +170,7 @@ describe('Cross operations', () => { assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', value: BigInt(-1), - expectedError: InputError, + expectedError: InputError }, { source: juneChain, @@ -181,7 +178,7 @@ describe('Cross operations', () => { assetId: '0x3300000000000000000000000000000000000000', symbol: 'EUROC.e', value: EXCESSIVE_AMOUNT, - expectedError: AccountError, + expectedError: AccountError }, { source: juneChain, @@ -189,7 +186,7 @@ describe('Cross operations', () => { assetId: euroChain.assetId, symbol: euroChain.asset.symbol, value: EXCESSIVE_AMOUNT, - expectedError: AccountError, + expectedError: AccountError }, { source: juneChain, @@ -197,7 +194,7 @@ describe('Cross operations', () => { assetId: juneChain.assetId, symbol: juneChain.asset.symbol, value: BigInt(0), - expectedError: InputError, + expectedError: InputError }, { source: juneChain, @@ -205,7 +202,7 @@ describe('Cross operations', () => { assetId: juneChain.assetId, symbol: juneChain.asset.symbol, value: BigInt(0), - expectedError: InputError, + expectedError: InputError }, { source: jvmChain, @@ -213,7 +210,7 @@ describe('Cross operations', () => { assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, value: BigInt(0), - expectedError: InputError, + expectedError: InputError }, { source: jvmChain, @@ -221,7 +218,7 @@ describe('Cross operations', () => { assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, value: BigInt(0), - expectedError: InputError, + expectedError: InputError }, { source: platformChain, @@ -229,7 +226,7 @@ describe('Cross operations', () => { assetId: platformChain.assetId, symbol: platformChain.asset.symbol, value: BigInt(0), - expectedError: InputError, + expectedError: InputError }, { source: platformChain, @@ -237,8 +234,8 @@ describe('Cross operations', () => { assetId: platformChain.assetId, symbol: platformChain.asset.symbol, value: BigInt(0), - expectedError: InputError, - }, + expectedError: InputError + } ])( '$#) $value $symbol from $source.name to $destination.name', async ({ source, destination, assetId, value, expectedError }) => { @@ -246,7 +243,7 @@ describe('Cross operations', () => { const summary = await ACCOUNT.estimate(operation) await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) }) diff --git a/tests/e2e/wallet/send.test.ts b/tests/e2e/wallet/send.test.ts index 979de8ab..623c537b 100644 --- a/tests/e2e/wallet/send.test.ts +++ b/tests/e2e/wallet/send.test.ts @@ -4,14 +4,11 @@ import { GenesisJUNEChain, GenesisJVMChain, SendOperation, - type ExecutableOperation, + type ExecutableOperation } from '../../../src' -import { ACCOUNT } from '../constants' +import { ACCOUNT, DEFAULT_TIMEOUT, DONE_STATUS, EXCESSIVE_AMOUNT } from '../constants' describe('Send operations', () => { - const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') - const DONE_STATUS = 'Done' - const DEFAULT_TIMEOUT: number = 180_000 const juneChain = GenesisJUNEChain const euroChain = GenesisEUROC1Chain const jvmChain = GenesisJVMChain @@ -24,22 +21,22 @@ describe('Send operations', () => { assetId: juneChain.assetId, symbol: juneChain.asset.symbol, value: BigInt(1_000), - recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', + recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26' }, { chain: juneChain, assetId: '0x2d00000000000000000000000000000000000000', symbol: 'ETH.e', value: BigInt(1), - recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', + recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26' }, { chain: euroChain, assetId: euroChain.assetId, symbol: euroChain.asset.symbol, value: BigInt('10000000000000'), - recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - }, + recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26' + } ])( '$#) $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient }) => { @@ -49,7 +46,7 @@ describe('Send operations', () => { const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(DONE_STATUS) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -62,7 +59,7 @@ describe('Send operations', () => { symbol: juneChain.asset.symbol, value: BigInt(-1), recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - expectedError: RangeError, + expectedError: RangeError }, { description: 'Excessive amount', @@ -71,7 +68,7 @@ describe('Send operations', () => { symbol: juneChain.asset.symbol, value: EXCESSIVE_AMOUNT, recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - expectedError: AccountError, + expectedError: AccountError }, { description: 'Excessive amount and different assetId', @@ -80,8 +77,8 @@ describe('Send operations', () => { symbol: euroChain.asset.symbol, value: EXCESSIVE_AMOUNT, recipient: '0x3c647d88Bc92766075feA7A965CA599CAAB2FD26', - expectedError: AccountError, - }, + expectedError: AccountError + } ])( '$#) $description $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient, expectedError }) => { @@ -89,7 +86,7 @@ describe('Send operations', () => { const summary = await ACCOUNT.estimate(operation) await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) }) @@ -102,8 +99,8 @@ describe('Send operations', () => { assetId: jvmChain.assetId, symbol: jvmChain.asset.symbol, value: BigInt(10_000_000), - recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal', - }, + recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal' + } ])( '$#) $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient }) => { @@ -113,7 +110,7 @@ describe('Send operations', () => { const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(DONE_STATUS) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -126,7 +123,7 @@ describe('Send operations', () => { symbol: jvmChain.asset.symbol, value: EXCESSIVE_AMOUNT, recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal', - expectedError: AccountError, + expectedError: AccountError }, { description: 'Zero value', @@ -135,8 +132,8 @@ describe('Send operations', () => { symbol: jvmChain.asset.symbol, value: BigInt(0), recipient: 'JVM-socotra167w40pwvlrf5eg0d9t48zj6kwkaqz2xan50pal', - expectedError: TypeError, - }, + expectedError: TypeError + } ])( '$#) $description $value $symbol in $chain.name to $recipient', async ({ chain, assetId, value, recipient, expectedError }) => { @@ -144,7 +141,7 @@ describe('Send operations', () => { const summary = await ACCOUNT.estimate(operation) await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) }) diff --git a/tests/e2e/wallet/stake.test.ts b/tests/e2e/wallet/stake.test.ts index 44f88a77..3df5bb0c 100644 --- a/tests/e2e/wallet/stake.test.ts +++ b/tests/e2e/wallet/stake.test.ts @@ -4,18 +4,14 @@ import { DelegatePrimaryOperation, now, type ChainAccount, - type ExecutableOperation, + type ExecutableOperation } from '../../../src' -import { ACCOUNT, PROVIDER } from '../constants' - -const DEFAULT_TIMEOUT: number = 180_000 -const ONE_DAY: bigint = BigInt(86_400) +import { ACCOUNT, DEFAULT_TIMEOUT, DONE_STATUS, EXCESSIVE_AMOUNT, PROVIDER } from '../constants' const chainAccount: ChainAccount = ACCOUNT.getAccount(PROVIDER.platformChain.id) -const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') -const DONE_STATUS = 'Done' // for now we take this nodeID. maybe in the future we can select the node Id with a function const validNodeId = 'NodeID-P6qNB7Zk2tUirf9TvBiXxiCHxa5Hzq6sL' +const ONE_DAY: bigint = BigInt(86_400) let currentTime: bigint = now() + BigInt(30) let tomorrow: bigint = currentTime + ONE_DAY @@ -36,8 +32,8 @@ describe('Staking operations', (): void => { amount: BigInt(10_000_000), expectedStatus: DONE_STATUS, startTime: currentTime, - endTime: tomorrow, - }, + endTime: tomorrow + } ])( '$#) $amount tokens to delegate node id: $nodeId from $startTime to $endTime', async ({ nodeId, amount, expectedStatus, startTime, endTime }) => { @@ -50,14 +46,14 @@ describe('Staking operations', (): void => { [chainAccount.address], 1, [chainAccount.address], - 1, + 1 ) const summary = await ACCOUNT.estimate(delegateOperation) await ACCOUNT.execute(summary) const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(expectedStatus) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -69,8 +65,8 @@ describe('Staking operations', (): void => { amount: BigInt(10_000_000), expectedError: DecodingError, startTime: currentTime, - endTime: tomorrow, - }, + endTime: tomorrow + } ])( '$#) $description $amount tokens to delegate node id: $nodeId from $startTime to $endTime', async ({ nodeId, amount, expectedError, startTime, endTime }) => { @@ -83,11 +79,11 @@ describe('Staking operations', (): void => { [chainAccount.address], 1, [chainAccount.address], - 1, + 1 ) await expect(ACCOUNT.estimate(delegateOperation)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -99,8 +95,8 @@ describe('Staking operations', (): void => { amount: EXCESSIVE_AMOUNT, expectedError: AccountError, startTime: currentTime, - endTime: tomorrow, - }, + endTime: tomorrow + } ])( '$#) $description $amount tokens to delegate node id: $nodeId from $startTime to $endTime', async ({ nodeId, amount, expectedError, startTime, endTime }) => { @@ -113,12 +109,12 @@ describe('Staking operations', (): void => { [chainAccount.address], 1, [chainAccount.address], - 1, + 1 ) const summary = await ACCOUNT.estimate(delegateOperation) await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) }) diff --git a/tests/e2e/wallet/wrap.test.ts b/tests/e2e/wallet/wrap.test.ts index c14a5a3f..7bae92fa 100644 --- a/tests/e2e/wallet/wrap.test.ts +++ b/tests/e2e/wallet/wrap.test.ts @@ -6,14 +6,11 @@ import { NetworkOperationType, UnwrapOperation, WrapOperation, - type ExecutableOperation, + type ExecutableOperation } from '../../../src' -import { ACCOUNT } from '../constants' +import { ACCOUNT, DEFAULT_TIMEOUT, DONE_STATUS, EXCESSIVE_AMOUNT } from '../constants' describe('Wrapping operations', () => { - const EXCESSIVE_AMOUNT = BigInt('100000000000000000000000000000000000000000000000') - const DONE_STATUS = 'Done' - const DEFAULT_TIMEOUT: number = 180_000 const juneChain = GenesisJUNEChain const wJuneAsset = GenesisWJUNEAsset @@ -28,7 +25,7 @@ describe('Wrapping operations', () => { expect(operation.amount).toEqual(amount) expect(operation.range).toEqual(NetworkOperationRange.Chain) expect(operation.type).toEqual(NetworkOperationType.Wrap) - }, + } ) }) @@ -42,7 +39,7 @@ describe('Wrapping operations', () => { const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(expectedStatus) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -53,8 +50,8 @@ describe('Wrapping operations', () => { blockchain: juneChain, asset: wJuneAsset, amount: EXCESSIVE_AMOUNT, - expectedStatus: AccountError, - }, + expectedStatus: AccountError + } ])( '$#) $description $amount $asset.name in $blockchain.name', async ({ blockchain, asset, amount, expectedStatus }) => { @@ -62,7 +59,7 @@ describe('Wrapping operations', () => { const summary = await ACCOUNT.estimate(operation) await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedStatus) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) }) @@ -78,7 +75,7 @@ describe('Wrapping operations', () => { expect(operation.amount).toEqual(amount) expect(operation.range).toEqual(NetworkOperationRange.Chain) expect(operation.type).toEqual(NetworkOperationType.Unwrap) - }, + } ) }) @@ -92,7 +89,7 @@ describe('Wrapping operations', () => { const executable: ExecutableOperation = summary.getExecutable() expect(executable.status).toEqual(expectedStatus) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) @@ -103,8 +100,8 @@ describe('Wrapping operations', () => { blockchain: juneChain, asset: wJuneAsset, amount: EXCESSIVE_AMOUNT, - expectedError: AccountError, - }, + expectedError: AccountError + } ])( '$#) $description $amount $asset.name in $blockchain.name', async ({ blockchain, asset, amount, expectedError }) => { @@ -112,7 +109,7 @@ describe('Wrapping operations', () => { const summary = await ACCOUNT.estimate(operation) await expect(ACCOUNT.execute(summary)).rejects.toThrow(expectedError) }, - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT ) }) }) diff --git a/tests/unit/wallet/wallet.test.ts b/tests/unit/wallet/wallet.test.ts index b80114d5..46e0e492 100644 --- a/tests/unit/wallet/wallet.test.ts +++ b/tests/unit/wallet/wallet.test.ts @@ -1,13 +1,11 @@ -import * as dotenv from 'dotenv' import { - MCNWallet, GenesisJUNEChain, GenesisJVMChain, GenesisPlatformChain, + MCNWallet, WalletError, validatePrivateKey } from '../../../src' -dotenv.config() describe('MCNWallet', (): void => { describe('Generate', (): void => { From 74a58e8279dd2488aa987b7dacf46ca2653a4455 Mon Sep 17 00:00:00 2001 From: alekswaslet <1346150+alekswaslet@users.noreply.github.com> Date: Wed, 29 May 2024 16:41:38 +0200 Subject: [PATCH 3/3] Set Mainnet as default HRP and added HRP setter --- package.json | 2 +- src/wallet/wallet.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ec3895f5..d32b2cf9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "juneojs", - "version": "0.0.95", + "version": "0.0.96", "description": "Juneo JS Library", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/wallet/wallet.ts b/src/wallet/wallet.ts index a8b61a48..33eb7819 100644 --- a/src/wallet/wallet.ts +++ b/src/wallet/wallet.ts @@ -1,5 +1,6 @@ -import { HDNodeWallet, Mnemonic, Wallet, randomBytes } from 'ethers' -import { JEVM_ID, type Blockchain, JVM_ID, PLATFORMVM_ID, type JEVMBlockchain } from '../chain' +import { HDNodeWallet, Mnemonic, randomBytes, Wallet } from 'ethers' +import { JEVM_ID, JVM_ID, PLATFORMVM_ID, type Blockchain, type JEVMBlockchain } from '../chain' +import { MainNetwork } from '../network' import { ECKeyPair, encodeJuneoAddress, @@ -9,7 +10,6 @@ import { WalletError } from '../utils' import * as encoding from '../utils/encoding' -import { TestNetwork } from '../network' const EVMHdPath = "m/44'/60'/0'/0" const JVMHdPath = "m/44'/9000'/0'/0" @@ -41,7 +41,7 @@ export class MCNWallet { privateKey?: string chainsWallets = new Map() - private constructor (hrp: string = TestNetwork.hrp) { + private constructor (hrp: string = MainNetwork.hrp) { this.hrp = hrp } @@ -71,6 +71,11 @@ export class MCNWallet { return wallets } + setHrp (hrp: string): void { + this.hrp = hrp + this.chainsWallets.clear() + } + private setChainWallet (chain: Blockchain): void { if (chain.vmId === JEVM_ID) { this.chainsWallets.set(chain.id, this.buildJEVMWallet(chain))