Skip to content

Commit

Permalink
test(ethPNT-swap): add test for ethPNT swaps and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
envin3 committed Jan 29, 2024
1 parent 6d2530f commit a05028c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/utils/__tests__/ptokens.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { pTokensNode, pTokensNodeProvider } from 'ptokens'

import { PNETWORK_NODE_V3 } from '../../constants'
import { createEthPntAsset } from '../ptokens'

describe('createEthPntAsset', () => {
test('Should create a ethPnt pTokenAsset', async () => {
const ethPnt = await createEthPntAsset()
const assetInfo = ethPnt.assetInfo

const expectedProvider = new pTokensNodeProvider(PNETWORK_NODE_V3)
const expectedNode = new pTokensNode(expectedProvider)

const expectedFees = {
networkFee: 0,
networkFeeUsd: 15,
minNodeOperatorFee: 0,
minNodeOperatorFeeUsd: 0,
basisPoints: {
nativeToHost: 10,
nativeToNative: 25,
},
}
const expectedAssetInfo = {
chainId: '0x005fe7f9',
isNative: true,
tokenAddress: '0xf4eA6B892853413bD9d9f1a5D3a620A0ba39c5b2',
tokenReference: '0xeeef86a5598a48c568cca576d9e0c15c370b50a0',
identity: '341aa660fd5c280f5a9501e3822bb4a98e816d1b',
tokenDecimals: 18,
decimals: 18,
vaultAddress: 'e396757ec7e6ac7c8e5abe7285dde47b98f22db8',
fees: expectedFees,
}
expect(assetInfo).toEqual(expectedAssetInfo)
expect(ethPnt.node).toEqual(expectedNode)
expect(ethPnt.symbol).toEqual('ethPNT')
expect(ethPnt.chainId).toEqual('0x005fe7f9')
})
})
20 changes: 20 additions & 0 deletions src/utils/__tests__/swap-valildator.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, describe, expect } from 'vitest'

import { ETHPNT_ON_ETH_MAINNET, PNT_ON_ETH_MAINNET } from '../../constants'
import migrationAssets from '../../settings/migration-assets'
import assets from '../../settings/swap-assets'
import { isValidSwap } from '../swap-valildator'
Expand Down Expand Up @@ -99,6 +100,7 @@ describe('isValidSwap', () => {

test('Should always be there at least one valid swap pair', () => {
assets
.filter((asset) => asset.id !== ETHPNT_ON_ETH_MAINNET) // exclude ethPNT which is put in PNT list
.map((_from) => assets.filter((_to) => isValidSwap(_from, _to, assets)))
.map((_pairs) => expect(_pairs.length).toBeGreaterThan(0))
})
Expand All @@ -122,4 +124,22 @@ describe('isValidSwap', () => {
test('Should return false if from or to assets are not in assets array', () => {
assets.map((_from) => assets.map((_to) => expect(isValidSwap(_from, _to, migrationAssets)).toBeFalsy()))
})

test('Should return true if from asset is ethPNT and to assets are non-native PNT', () => {
const ethPnt = assets.find((asset) => asset.id === ETHPNT_ON_ETH_MAINNET)
assets.map((_to) =>
_to.nativeSymbol === 'PNT' && !_to.isNative ? expect(isValidSwap(ethPnt, _to, assets)).toBeTruthy() : null
)
})

test('Should return false if to asset is ethPNT', () => {
const ethPnt = assets.find((asset) => asset.id === ETHPNT_ON_ETH_MAINNET)
assets.map((_from) => expect(isValidSwap(_from, ethPnt, assets)).toBeFalsy())
})

test('Should return false if trying to go from ethPNT to PNT', () => {
const ethPnt = assets.find((asset) => asset.id === ETHPNT_ON_ETH_MAINNET)
const pnt = assets.find((asset) => asset.id === PNT_ON_ETH_MAINNET)
assets.map((_from) => expect(isValidSwap(ethPnt, pnt, assets)).toBeFalsy())
})
})

0 comments on commit a05028c

Please sign in to comment.