Skip to content

Commit

Permalink
ALL-9108 Refactor and fix some existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj.bacovcin committed Oct 11, 2024
1 parent 5d070cc commit 8b23a5e
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixed

- Fixed Tatum Connector issue with process is undefined on the pure browser
- Fixed and refactored some tests

## [4.2.42] - 2024.9.4

Expand Down
10 changes: 10 additions & 0 deletions src/e2e/e2e.constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Network } from '../dto'

export const ApiKey = {
mainnet: process.env.V4_API_KEY_MAINNET || '',
testnet: process.env.V4_API_KEY_TESTNET || '',
}

export const ApiKeyV3 = {
mainnet: process.env.V3_API_KEY_MAINNET || '',
testnet: process.env.V3_API_KEY_TESTNET || '',
}

export const TestConst = {
EXISTING_SUBSCRIPTION_ETH_ADDRESS: '0xbaf6dc2e647aeb6f510f9e318856a1bcd66c5e19',
INVALID_ETH_ADDRESS: 'TLduuX5NWFucPPafLbj9eab6Znwrdm72Qv',
Expand Down
3 changes: 2 additions & 1 deletion src/e2e/ipfs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import fs from 'fs'
import { Network } from '../dto'
import { ApiKey } from './e2e.constant'
import { EvmE2eUtils } from './rpc/evm/evm.e2e.utils'

describe.skip('IPFS', () => {
it('should upload file to IPFS', async () => {
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET)
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, ApiKey.mainnet)
const fileData = fs.readFileSync('./test.txt') // Adjust the path to your file
const response = await tatum.ipfs.uploadFile({ file: fileData })
expect(response.status).toBe('SUCCESS')
Expand Down
19 changes: 10 additions & 9 deletions src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Network } from '../../../../dto'
import { Ethereum } from '../../../../service'
import { ApiKey } from '../../../e2e.constant'
import { EvmE2eUtils } from '../evm.e2e.utils'

describe('Beacon', () => {

Check failure on line 6 in src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts

View workflow job for this annotation

GitHub Actions / TEST REPORT

src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts β–Ί Beacon β€Ί v1 β€Ί ethereum-holesky β–Ί should get node version

Failed test found in: reports/jest-junit.xml Error: Error: thrown: ""
Raw output
Error: thrown: ""
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:11:7
    at /home/runner/work/tatum-js/tatum-js/node_modules/jest-each/build/bind.js:81:13
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at /home/runner/work/tatum-js/tatum-js/node_modules/jest-each/build/bind.js:47:15
    at Array.forEach (<anonymous>)
    at eachBind (/home/runner/work/tatum-js/tatum-js/node_modules/jest-each/build/bind.js:39:22)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:10:28
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:7:3
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at Object.<anonymous> (/home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:6:1)
    at Runtime._execModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:882:12)
    at jestAdapter (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:77:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runTestInternal (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 6 in src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts

View workflow job for this annotation

GitHub Actions / TEST REPORT

src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts β–Ί Beacon β€Ί v1 β€Ί ethereum-mainnet β–Ί should get node version

Failed test found in: reports/jest-junit.xml Error: Error: thrown: "{\"statusCode\":403,\"errorCode\":\"unsupported.apiKey.network.combination\",\"message\":\"Cannot use testnet apiKey with mainnet network. Please use mainnet apiKey instead, if you dont have one, please create it at https://co.tatum.io/signup\",\"dashboardLog\":\"https://dashboard.tatum.io/logs?id=670909af4e827a7c510d2b9f\"}"
Raw output
Error: thrown: "{\"statusCode\":403,\"errorCode\":\"unsupported.apiKey.network.combination\",\"message\":\"Cannot use testnet apiKey with mainnet network. Please use mainnet apiKey instead, if you dont have one, please create it at https://co.tatum.io/signup\",\"dashboardLog\":\"https://dashboard.tatum.io/logs?id=670909af4e827a7c510d2b9f\"}"
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:11:7
    at /home/runner/work/tatum-js/tatum-js/node_modules/jest-each/build/bind.js:81:13
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at /home/runner/work/tatum-js/tatum-js/node_modules/jest-each/build/bind.js:47:15
    at Array.forEach (<anonymous>)
    at eachBind (/home/runner/work/tatum-js/tatum-js/node_modules/jest-each/build/bind.js:39:22)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:10:28
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:7:3
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at Object.<anonymous> (/home/runner/work/tatum-js/tatum-js/src/e2e/rpc/evm/eth/tatum.rpc.beacon.spec.ts:6:1)
    at Runtime._execModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:882:12)
    at jestAdapter (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:77:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runTestInternal (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/testWorker.js:106:12)
Expand All @@ -8,63 +9,63 @@ describe('Beacon', () => {

describe.each(networks)('%s', (network) => {
it('should get node version', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getNodeVersion()
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get genesis', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getGenesis()
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get state root', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getStateRoot({ stateId: 'head' })
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get block headers', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getBlockHeaders({ slot: '1000' })
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get block root', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getBlockRoot({ blockId: 'head' })
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get state committees', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getStateCommittees({ stateId: 'head' })
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get state finality checkpoints', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getStateFinalityCheckpoints({ stateId: 'head' })
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get state fork', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getStateFork({ stateId: 'head' })
await tatum.destroy()
expect(data).toBeDefined()
})

it('should get state sync committees', async () => {
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, process.env.V4_API_KEY_TESTNET)
const tatum = await EvmE2eUtils.initTatum<Ethereum>(network, ApiKey.testnet)
const { data } = await tatum.rpc.beacon.v1.getStateSyncCommittees({ stateId: 'head' })
await tatum.destroy()
expect(data).toBeDefined()
Expand Down
14 changes: 7 additions & 7 deletions src/e2e/rpc/evm/eth/tatum.rpc.ethereum.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import process from 'process'
import { BaseEvm, Network, RpcNodeType, TatumSDK } from '../../../../service'
import { ApiKey } from '../../../e2e.constant'
import { EvmE2eUtils } from '../evm.e2e.utils'

describe('Ethereum', () => {
it('should get token total supply', async () => {
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET)
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, ApiKey.mainnet)
const { result } = await tatum.rpc.getTokenTotalSupply('0xdac17f958d2ee523a2206206994597c13d831ec7')
await tatum.destroy()
expect(result).toBeDefined()
expect(result?.isGreaterThan(1))
})

it('should get token cap', async () => {
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET)
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, ApiKey.mainnet)
const { result } = await tatum.rpc.getTokenCap('0x43044f861ec040DB59A7e324c40507adDb673142')
await tatum.destroy()
expect(result).toBeDefined()
expect(result?.isGreaterThan(1))
})

it('should return true if contract is a multitoken', async () => {
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET)
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, ApiKey.mainnet)
const { result } = await tatum.rpc.supportsInterfaceERC1155('0xF4Dd946D1406e215a87029db56C69e1Bcf3e1773')
await tatum.destroy()
expect(result).toBeDefined()
Expand All @@ -39,7 +39,7 @@ describe('Ethereum', () => {
],
},
apiKey: {
v4: process.env.V4_API_KEY_MAINNET,
v4: ApiKey.mainnet,
},
})
const { result } = await tatum.rpc.chainId()
Expand All @@ -48,7 +48,7 @@ describe('Ethereum', () => {
})

it('debug storage range at', async () => {
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET)
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, ApiKey.mainnet)
const { result } = await tatum.rpc.debugStorageRangeAt(
'0xc20f6b582e0c7923341cdb1299a94ea00c8a23e1ccabc532955a2a07b27121dc',
0,
Expand All @@ -61,7 +61,7 @@ describe('Ethereum', () => {
})

it('get logs', async () => {
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, process.env.V4_API_KEY_MAINNET)
const tatum = await EvmE2eUtils.initTatum(Network.ETHEREUM, ApiKey.mainnet)
const result = await tatum.rpc.getLogs({
address: '0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5',
})
Expand Down
5 changes: 3 additions & 2 deletions src/e2e/rpc/evm/evm.rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Network } from '../../../dto'
import { ApiKey, ApiKeyV3 } from '../../e2e.constant'
import { EvmE2eUtils } from './evm.e2e.utils'

const testNetworks = [
{ network: Network.CELO },
{ network: Network.CELO_ALFAJORES },
// { network: Network.ARBITRUM_ONE },
{ network: Network.ARBITRUM_NOVA, apiKey: process.env.V3_API_KEY_MAINNET },
{ network: Network.ARBITRUM_NOVA, apiKey: ApiKeyV3.mainnet },
{
network: Network.ARBITRUM_NOVA_TESTNET,
apiKey: process.env.V3_API_KEY_TESTNET,
Expand Down Expand Up @@ -56,7 +57,7 @@ const testNetworks = [
},
{
network: Network.KLAYTN_BAOBAB,
apiKey: process.env.V4_API_KEY_TESTNET,
apiKey: ApiKey.testnet,
},
{
network: Network.AVALANCHE_C,
Expand Down
4 changes: 2 additions & 2 deletions src/e2e/rpc/other/tatum.rpc.eos.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as process from 'process'
import { ApiVersion, Eos, Network, TatumSDK } from '../../../service'
import { ApiKey, ApiKeyV3 } from '../../e2e.constant'
import { e2eUtil } from '../../e2e.util'

const getEosRpc = async (testnet?: boolean) =>
await TatumSDK.init<Eos>({
network: testnet ? Network.EOS_TESTNET : Network.EOS,
apiKey: {
v4: testnet ? process.env.V3_API_KEY_TESTNET : process.env.V4_API_KEY_MAINNET,
v4: testnet ? ApiKeyV3.testnet : ApiKey.mainnet,
},
version: ApiVersion.V3,
retryCount: 1,
Expand Down
6 changes: 3 additions & 3 deletions src/e2e/rpc/other/tatum.rpc.stellar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import process from 'process'
import { ApiVersion, Network, Stellar, TatumSDK } from '../../../service'
import { ApiKey, ApiKeyV3 } from '../../e2e.constant'
import { e2eUtil } from '../../e2e.util'

const getStellarRpc = async (testnet?: boolean) =>
await TatumSDK.init<Stellar>({
network: testnet ? Network.STELLAR_TESTNET : Network.STELLAR,
verbose: e2eUtil.isVerbose,
...(testnet && { apiKey: { v3: process.env.V3_API_KEY_TESTNET } }),
...(!testnet && { apiKey: process.env.V4_API_KEY_MAINNET }),
...(testnet && { apiKey: { v3: ApiKeyV3.testnet } }),
...(!testnet && { apiKey: ApiKey.mainnet }),
version: testnet ? ApiVersion.V3 : ApiVersion.V4,
})

Expand Down
9 changes: 7 additions & 2 deletions src/e2e/rpc/other/tatum.rpc.tron.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import BigNumber from 'bignumber.js'
import * as process from 'process'
import { BlockIdentifier } from '../../../dto'
import { Network, TatumSDK, Tron } from '../../../service'
import { ApiKey, ApiKeyV3 } from '../../e2e.constant'
import { e2eUtil } from '../../e2e.util'

const getTronRpc = async (testnet?: boolean) =>
await TatumSDK.init<Tron>(e2eUtil.initConfig(testnet ? Network.TRON_SHASTA : Network.TRON, testnet ? process.env.V3_API_KEY_TESTNET : process.env.V4_API_KEY_MAINNET))
await TatumSDK.init<Tron>(
e2eUtil.initConfig(
testnet ? Network.TRON_SHASTA : Network.TRON,
testnet ? ApiKeyV3.testnet : ApiKey.mainnet,
),
)

describe.skip('RPCs', () => {
describe('TRON', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/e2e/tatum.rates.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiVersion, Ethereum, Network, TatumSDK } from '../service'
import { ApiKey } from './e2e.constant'

describe('Rates', () => {
let tatum: Ethereum
Expand All @@ -9,7 +10,7 @@ describe('Rates', () => {
retryDelay: 1000,
retryCount: 2,
version: ApiVersion.V4,
apiKey: process.env.V4_API_KEY_TESTNET,
apiKey: ApiKey.testnet,
})
})

Expand Down
61 changes: 31 additions & 30 deletions src/e2e/tatum.spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
import { Network } from '../dto'
import { Bitcoin, TatumSDK } from '../service'
import { ApiKey } from './e2e.constant'

describe('Tatum Init', () => {
describe('IP auth', () => {
it('Testnet', async () => {
const tatum = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN_TESTNET,
})
const { result } = await tatum.rpc.getBlockChainInfo()
expect(result.chain).toBe('test')
await tatum.destroy()
it('Testnet', async () => {
const tatum = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN_TESTNET,
apiKey: ApiKey.testnet,
})
const { result } = await tatum.rpc.getBlockChainInfo()
expect(result.chain).toBe('test')
await tatum.destroy()
})

it('Mainnet', async () => {
const tatum = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN,
})
const { result } = await tatum.rpc.getBlockChainInfo()
expect(result.chain).toBe('main')
await tatum.destroy()
it('Mainnet', async () => {
const tatum = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN,
apiKey: ApiKey.mainnet,
})
const { result } = await tatum.rpc.getBlockChainInfo()
expect(result.chain).toBe('main')
await tatum.destroy()
})

describe('Multiple Instances', () => {
it('IP auth', async () => {
const mainnet = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN,
})
const testnet = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN_TESTNET,
})
it('Multiple Instances', async () => {
const mainnet = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN,
apiKey: ApiKey.mainnet,
})
const testnet = await TatumSDK.init<Bitcoin>({
network: Network.BITCOIN_TESTNET,
apiKey: ApiKey.testnet,
})

const { result: resultMainnet } = await mainnet.rpc.getBlockChainInfo()
expect(resultMainnet.chain).toBe('main')
const { result: resultMainnet } = await mainnet.rpc.getBlockChainInfo()
expect(resultMainnet.chain).toBe('main')

const { result: resultTestnet } = await testnet.rpc.getBlockChainInfo()
expect(resultTestnet.chain).toBe('test')
const { result: resultTestnet } = await testnet.rpc.getBlockChainInfo()
expect(resultTestnet.chain).toBe('test')

await testnet.destroy()
await mainnet.destroy()
})
await testnet.destroy()
await mainnet.destroy()
})
})

0 comments on commit 8b23a5e

Please sign in to comment.