Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
test: update topos messaging tests
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Nov 10, 2023
1 parent ebe9c83 commit 0075d54
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 deletions test/topos-core/ToposMessaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deployContractConstant } from '../../scripts/const-addr-deployer'
import { ethers, network } from 'hardhat'
import { expect } from 'chai'
import { getReceiptMptProof } from './shared/utils/mpt_proof'
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'
import { loadFixture, takeSnapshot } from '@nomicfoundation/hardhat-network-helpers'
import { JsonRpcProvider } from '@ethersproject/providers'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'

Expand Down Expand Up @@ -500,16 +500,37 @@ describe('ToposMessaging', () => {
})

it('reverts if the token is not deployed yet', async () => {
const { toposCore, erc20Messaging } = await loadFixture(
const {
admin,
receiver,
defaultToken,
ERC20,
toposCore,
erc20Messaging,
}
= await loadFixture(
deployERC20MessagingFixture
)

let snapshot = await takeSnapshot()

Check failure on line 515 in test/topos-core/ToposMessaging.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'snapshot' is never reassigned. Use 'const' instead

const { proofBlob, receiptsRoot } = await deployDefaultToken(
admin,
receiver,
ERC20,
defaultToken,
erc20Messaging
)

await snapshot.restore()

await toposCore.setNetworkSubnetId(cc.SOURCE_SUBNET_ID_2)
const certificate = testUtils.encodeCertParam(
cc.PREV_CERT_ID_0,
cc.SOURCE_SUBNET_ID_1,
cc.STATE_ROOT_MAX,
cc.TX_ROOT_MAX,
txc.UNKNOWN_TOKEN_TRANSACTION.receiptRoot,
receiptsRoot,
[cc.SOURCE_SUBNET_ID_2],
cc.VERIFIER,
cc.CERT_ID_1,
Expand All @@ -519,25 +540,51 @@ describe('ToposMessaging', () => {
await toposCore.pushCertificate(certificate, cc.CERT_POS_1)
await expect(
erc20Messaging.execute(
[tc.TOKEN_SENT_INDEX_0],
txc.UNKNOWN_TOKEN_TRANSACTION.proofBlob,
txc.UNKNOWN_TOKEN_TRANSACTION.receiptRoot
[tc.TOKEN_SENT_INDEX_2],
proofBlob,
receiptsRoot
)
).to.be.revertedWithCustomError(erc20Messaging, 'TokenDoesNotExist')
})

it('reverts if the daily mint limit is exceeded', async () => {
const { defaultToken, toposCore, erc20Messaging } = await loadFixture(
deployERC20MessagingFixture
)
const { admin, receiver, ERC20, toposCore, erc20Messaging } =
await loadFixture(deployERC20MessagingFixture)
await toposCore.setNetworkSubnetId(cc.SOURCE_SUBNET_ID_2)
await erc20Messaging.deployToken(defaultToken)
const token = testUtils.encodeTokenParam(
tc.TOKEN_NAME,
tc.TOKEN_SYMBOL_X,
tc.MINT_CAP_100_000_000,
ethers.constants.AddressZero,
1,
tc.INITIAL_SUPPLY_10_000_000
)
const tx = await erc20Messaging.deployToken(token)
const txReceipt = await tx.wait()
const logs = txReceipt.events?.find((e) => e.event === 'TokenDeployed')
const tokenAddress = logs?.args?.tokenAddress
const erc20 = ERC20.attach(tokenAddress)
await erc20.approve(erc20Messaging.address, tc.SEND_AMOUNT_50)

const sendToken = await sendTokenTx(
erc20Messaging,
ethers.provider,
receiver.address,
admin,
cc.SOURCE_SUBNET_ID_2,
tokenAddress
)

const { proofBlob, receiptsRoot } = await getReceiptMptProof(
sendToken,
ethers.provider
)
const certificate = testUtils.encodeCertParam(
cc.PREV_CERT_ID_0,
cc.SOURCE_SUBNET_ID_1,
cc.STATE_ROOT_MAX,
cc.TX_ROOT_MAX,
txc.MINT_EXCEED_TRANSACTION.receiptRoot,
receiptsRoot,
[cc.SOURCE_SUBNET_ID_2],
cc.VERIFIER,
cc.CERT_ID_1,
Expand All @@ -548,8 +595,8 @@ describe('ToposMessaging', () => {
await expect(
erc20Messaging.execute(
[tc.TOKEN_SENT_INDEX_2],
txc.MINT_EXCEED_TRANSACTION.proofBlob,
txc.MINT_EXCEED_TRANSACTION.receiptRoot
proofBlob,
receiptsRoot
)
).to.be.revertedWithCustomError(erc20Messaging, 'ExceedDailyMintLimit')
})
Expand Down

0 comments on commit 0075d54

Please sign in to comment.