Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions packages/networks/evm-chains/tests/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ describe('Coin', () => {
})

it('Transfer', async () => {
if (!coinTransferTestIsActive) return

const signer = await coin.transfer(
senderTestAddress,
receiverTestAddress,
Expand All @@ -83,6 +81,8 @@ describe('Coin', () => {

await checkSigner(signer)

if (!coinTransferTestIsActive) return

const beforeBalance = await coin.getBalance(receiverTestAddress)

await checkTx(await signer.send())
Expand Down Expand Up @@ -115,10 +115,6 @@ describe('Token', () => {
})

it('Transfer', async () => {
if (!tokenTransferTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await token.transfer(
senderTestAddress,
receiverTestAddress,
Expand All @@ -127,6 +123,10 @@ describe('Token', () => {

await checkSigner(signer)

if (!tokenTransferTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const beforeBalance = await token.getBalance(receiverTestAddress)

await checkTx(await signer.send())
Expand All @@ -136,10 +136,6 @@ describe('Token', () => {
})

it('Approve and Allowance', async () => {
if (!tokenApproveTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await token.approve(
senderTestAddress,
receiverTestAddress,
Expand All @@ -148,6 +144,10 @@ describe('Token', () => {

await checkSigner(signer)

if (!tokenApproveTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

await checkTx(await signer.send())

expect(await token.getAllowance(senderTestAddress, receiverTestAddress)).toBe(
Expand All @@ -156,10 +156,6 @@ describe('Token', () => {
})

it('Transfer from', async () => {
if (!tokenTransferFromTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await token.transferFrom(
receiverTestAddress,
senderTestAddress,
Expand All @@ -169,6 +165,10 @@ describe('Token', () => {

await checkSigner(signer, receiverPrivateKey)

if (!tokenTransferFromTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const beforeBalance = await token.getBalance(receiverTestAddress)

await checkTx(await signer.send())
Expand Down Expand Up @@ -204,27 +204,31 @@ describe('Nft', () => {
})

it('Transfer', async () => {
if (!nftTransactionTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await nft.transfer(senderTestAddress, receiverTestAddress, nftTransferId)

await checkSigner(signer)

if (!nftTransactionTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

await checkTx(await signer.send())

expect(await nft.getOwner(nftTransferId)).toBe(receiverTestAddress)
})

it('Approve', async () => {
if (!nftTransactionTestIsActive) return
const customOwner = nftTransactionTestIsActive ? receiverTestAddress : senderTestAddress
const customSpender = nftTransactionTestIsActive ? senderTestAddress : receiverTestAddress
const customPrivateKey = nftTransactionTestIsActive ? receiverPrivateKey : senderPrivateKey

await waitSecondsBeforeThanNewTx(5)
const signer = await nft.approve(customOwner, customSpender, nftTransferId)

const signer = await nft.approve(receiverTestAddress, senderTestAddress, nftTransferId)
await checkSigner(signer, customPrivateKey)

await checkSigner(signer, receiverPrivateKey)
if (!nftTransactionTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

await checkTx(await signer.send())

Expand Down
4 changes: 4 additions & 0 deletions packages/networks/evm-chains/tests/models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ describe('Transaction', () => {
expect(await tx.getData()).toBeTypeOf('object')
})

it('Wait', async () => {
expect(await tx.wait()).toBe(TransactionStatusEnum.CONFIRMED)
})

it('URL', async () => {
expect(tx.getUrl()).toBe(
'https://sepolia.etherscan.io/tx/0x566002399664e92f82ed654c181095bdd7ff3d3f1921d963257585891f622251'
Expand Down
85 changes: 84 additions & 1 deletion packages/networks/evm-chains/tests/services.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it, expect } from 'vitest'

import { provider } from './setup.ts'
import { Provider } from '../src/services/Provider.ts'
import networks from '../src/services/Networks.ts'
import { Provider, type EvmNetworkConfigInterface } from '../src/services/Provider.ts'
import { TransactionListener } from '../src/services/TransactionListener.ts'
import { TransactionTypeEnum } from '@multiplechain/types'
import { Coin } from '../src/assets/Coin.ts'
Expand All @@ -12,6 +13,9 @@ import { Transaction } from '../src/models/Transaction.ts'
import { TokenTransaction } from '../src/models/TokenTransaction.ts'
import { NftTransaction } from '../src/models/NftTransaction.ts'
import { NFT } from '../src/assets/NFT.ts'
import ERC20 from '../resources/erc20.json'
import type { InterfaceAbi } from 'ethers'
import { ContractFactory, WebSocketProvider } from 'ethers'

const senderPrivateKey = String(process.env.EVM_SENDER_PRIVATE_KEY)
const receiverPrivateKey = String(process.env.EVM_RECEIVER_PRIVATE_KEY)
Expand Down Expand Up @@ -52,6 +56,85 @@ describe('Provider', () => {
})
})

describe('Networks', () => {
it('Ethereum', () => {
// @ts-expect-error ethereum is defined
expect(networks.ethereum).toBeDefined()
})

it('findById', () => {
// @ts-expect-error ethereum is defined
expect(networks.findById(1)).toBe(networks.ethereum)
})

it('findByKey', () => {
// @ts-expect-error ethereum is defined
expect(networks.findByKey('ethereum')).toBe(networks.ethereum)
})

it('findByName', () => {
// @ts-expect-error classic is defined
expect(networks.findByName('Ethereum Classic')).toBe(networks.classic)
})

it('findBySymbol', () => {
// @ts-expect-error arbitrum is defined
expect(networks.findBySymbol('ETH')).toBe(networks.arbitrum)
})

it('findByHexId', () => {
// @ts-expect-error ethereum is defined
expect(networks.findByHexId('0x1')).toBe(networks.ethereum)
})

it('Mainnets', () => {
expect(networks.getMainnets()).toBeInstanceOf(Array)
})

it('Testnets', () => {
expect(networks.getTestnets()).toBeInstanceOf(Array)
})

it('All', () => {
expect(networks.getAll()).toBeInstanceOf(Array)
})

it('Add', () => {
// @ts-expect-error ethereum is defined
networks.add('test', networks.ethereum as EvmNetworkConfigInterface)
// @ts-expect-error ethereum is defined
expect(networks.findByKey('test')).toBe(networks.ethereum)
})
})

describe('Ethers', () => {
it('Connect websocket', async () => {
expect(await provider.ethers.connectWebSocket()).toBeInstanceOf(WebSocketProvider)
})

it('Websocket', async () => {
expect(provider.ethers.webSocket).toBeInstanceOf(Object)
})

it('getByteCode', async () => {
expect(await provider.ethers.getByteCode(tokenTestAddress)).toBeTypeOf('string')
})

it('getLastTransactions', async () => {
expect(await provider.ethers.getLastTransactions(senderTestAddress)).toBeInstanceOf(Array)
})

it('getLastTransaction', async () => {
expect(await provider.ethers.getLastTransaction(senderTestAddress)).toBe(null)
})

it('contractFactory', async () => {
expect(provider.ethers.contractFactory(ERC20 as InterfaceAbi, '')).toBeInstanceOf(
ContractFactory
)
})
})

describe('Transaction Listener', () => {
if (!transactionListenerTestIsActive) {
it('No test is active', () => {
Expand Down
48 changes: 26 additions & 22 deletions packages/networks/tron/tests/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ describe('Coin', () => {
})

it('Transfer', async () => {
if (!coinTransferTestIsActive) return

const signer = await coin.transfer(
senderTestAddress,
receiverTestAddress,
Expand All @@ -85,6 +83,8 @@ describe('Coin', () => {

await checkSigner(signer)

if (!coinTransferTestIsActive) return

const beforeBalance = await coin.getBalance(receiverTestAddress)

await checkTx(await signer.send())
Expand Down Expand Up @@ -117,10 +117,6 @@ describe('Token', () => {
})

it('Transfer', async () => {
if (!tokenTransferTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await token.transfer(
senderTestAddress,
receiverTestAddress,
Expand All @@ -129,6 +125,10 @@ describe('Token', () => {

await checkSigner(signer)

if (!tokenTransferTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const beforeBalance = await token.getBalance(receiverTestAddress)

await checkTx(await signer.send())
Expand All @@ -138,10 +138,6 @@ describe('Token', () => {
})

it('Approve and Allowance', async () => {
if (!tokenApproveTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await token.approve(
senderTestAddress,
receiverTestAddress,
Expand All @@ -150,6 +146,10 @@ describe('Token', () => {

await checkSigner(signer)

if (!tokenApproveTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

await checkTx(await signer.send())

expect(await token.getAllowance(senderTestAddress, receiverTestAddress)).toBe(
Expand All @@ -158,10 +158,6 @@ describe('Token', () => {
})

it('Transfer from', async () => {
if (!tokenTransferFromTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await token.transferFrom(
receiverTestAddress,
senderTestAddress,
Expand All @@ -171,6 +167,10 @@ describe('Token', () => {

await checkSigner(signer, receiverPrivateKey)

if (!tokenTransferFromTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const beforeBalance = await token.getBalance(receiverTestAddress)

await checkTx(await signer.send())
Expand Down Expand Up @@ -206,27 +206,31 @@ describe('Nft', () => {
})

it('Transfer', async () => {
if (!nftTransactionTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

const signer = await nft.transfer(senderTestAddress, receiverTestAddress, nftTransferId)

await checkSigner(signer)

if (!nftTransactionTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

await checkTx(await signer.send())

expect(await nft.getOwner(nftTransferId)).toBe(receiverTestAddress)
})

it('Approve', async () => {
if (!nftTransactionTestIsActive) return
const customOwner = nftTransactionTestIsActive ? receiverTestAddress : senderTestAddress
const customSpender = nftTransactionTestIsActive ? senderTestAddress : receiverTestAddress
const customPrivateKey = nftTransactionTestIsActive ? receiverPrivateKey : senderPrivateKey

await waitSecondsBeforeThanNewTx(5)
const signer = await nft.approve(customOwner, customSpender, nftTransferId)

const signer = await nft.approve(receiverTestAddress, senderTestAddress, nftTransferId)
await checkSigner(signer, customPrivateKey)

await checkSigner(signer, receiverPrivateKey)
if (!nftTransactionTestIsActive) return

await waitSecondsBeforeThanNewTx(5)

await checkTx(await signer.send())

Expand Down
4 changes: 4 additions & 0 deletions packages/networks/tron/tests/models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ describe('Transaction', () => {
expect(await tx.getData()).toBeTypeOf('object')
})

it('Wait', async () => {
expect(await tx.wait()).toBe(TransactionStatusEnum.CONFIRMED)
})

it('URL', async () => {
expect(tx.getUrl()).toBe(
'https://nile.tronscan.org/#/transaction/8697ad2c4e1713227c16a65a5845636458df2d3db3adf526e07e17699bc6b3c4'
Expand Down
Loading