diff --git a/.claude/scheduled_tasks.lock b/.claude/scheduled_tasks.lock new file mode 100644 index 0000000000..47d27c1587 --- /dev/null +++ b/.claude/scheduled_tasks.lock @@ -0,0 +1 @@ +{"sessionId":"996f4d40-c459-4d03-9332-e542939dda5e","pid":80414,"acquiredAt":1775073709302} \ No newline at end of file diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index eda8217b08..0000000000 --- a/.mocharc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extension": ["ts"], - "package": "./package.json", - "require": "ts-node/register" -} diff --git a/package.json b/package.json index a004bde599..6312626a7f 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,6 @@ "@nomiclabs/hardhat-ethers": "^2.0.4", "@offchainlabs/l1-l3-teleport-contracts": "1.0.1", "@typechain/ethers-v5": "9.0.0", - "@types/chai": "^4.2.11", - "@types/mocha": "^9.0.0", "@types/prompts": "^2.0.14", "@types/yargs": "^17.0.9", "@typescript-eslint/eslint-plugin": "^5.14.0", @@ -30,17 +28,13 @@ "@typescript-eslint/parser": "^5.14.0", "audit-ci": "^6.6.1", "axios": "^1.13.5", - "chai": "^4.2.0", "chalk": "^4.1.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", - "eslint-plugin-mocha": "^9.0.0", "eslint-plugin-prettier": "^4.0.0", "ethers": "^5.0.0", "hardhat": "^2.24.0", - "mocha": "^9.2.1", - "nyc": "^15.1.0", "prettier": "^2.3.2", "prettier-plugin-solidity": "^1.0.0-beta.17", "prompts": "^2.4.2", @@ -69,13 +63,10 @@ "**/patch-package/cross-spawn": "6.0.6", "**/eslint/cross-spawn": "7.0.5", "**/foreground-child/cross-spawn": "7.0.5", - "**/istanbul-lib-processinfo/cross-spawn": "7.0.5", - "**/istanbul-lib-instrument/@babel/core/@babel/helpers": "7.26.10", "**/hardhat/undici": "5.29.0", "**/chokidar/braces": "3.0.3", "**/sol2uml/axios": "0.30.2", "**/brace-expansion": "1.1.12", - "**/mocha/minimatch/brace-expansion": "2.0.2", "**/convert-svg-core/glob/minimatch/brace-expansion": "2.0.2", "**/eslint/js-yaml": "3.14.2", "**/eslint/@eslint/eslintrc/js-yaml": "3.14.2", diff --git a/packages/ethers-viem-compat/tests/compatibility.test.ts b/packages/ethers-viem-compat/tests/compatibility.test.ts index 0386e93268..7d51738f29 100644 --- a/packages/ethers-viem-compat/tests/compatibility.test.ts +++ b/packages/ethers-viem-compat/tests/compatibility.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { BigNumber, providers } from 'ethers' import { createPublicClient, defineChain, http, TransactionReceipt } from 'viem' import { arbitrumSepolia, mainnet } from 'viem/chains' @@ -30,10 +30,10 @@ describe('viem compatibility', () => { }) const provider = publicClientToProvider(publicClient) - expect(provider).to.be.instanceOf(providers.StaticJsonRpcProvider) - expect(provider.network.chainId).to.equal(testChain.id) - expect(provider.network.name).to.equal(testChain.name) - expect(provider.connection.url).to.equal('https://example.com') + expect(provider).toBeInstanceOf(providers.StaticJsonRpcProvider) + expect(provider.network.chainId).toBe(testChain.id) + expect(provider.network.name).toBe(testChain.name) + expect(provider.connection.url).toBe('https://example.com') }) it('successfully converts PublicClient to Provider', () => { @@ -44,9 +44,9 @@ describe('viem compatibility', () => { const provider = publicClientToProvider(publicClient) - expect(provider.network.chainId).to.equal(publicClient.chain!.id) - expect(provider.network.name).to.equal(publicClient.chain!.name) - expect(provider.connection.url).to.equal( + expect(provider.network.chainId).toBe(publicClient.chain!.id) + expect(provider.network.name).toBe(publicClient.chain!.name) + expect(provider.connection.url).toBe( 'https://sepolia-rollup.arbitrum.io/rpc' ) }) @@ -59,9 +59,9 @@ describe('viem compatibility', () => { const provider = publicClientToProvider(publicClient) - expect(provider.network.chainId).to.equal(publicClient.chain!.id) - expect(provider.network.name).to.equal(publicClient.chain!.name) - expect(provider.connection.url).to.equal( + expect(provider.network.chainId).toBe(publicClient.chain!.id) + expect(provider.network.name).toBe(publicClient.chain!.name) + expect(provider.connection.url).toBe( 'https://arbitrum-sepolia.gateway.tenderly.co' ) }) @@ -73,7 +73,7 @@ describe('viem compatibility', () => { transport, }) - expect(() => publicClientToProvider(publicClient)).to.throw( + expect(() => publicClientToProvider(publicClient)).toThrow( '[publicClientToProvider] "chain" is undefined' ) }) @@ -113,15 +113,15 @@ describe('viem compatibility', () => { const ethersReceipt = viemTransactionReceiptToEthersTransactionReceipt(viemReceipt) - expect(ethersReceipt.to).to.equal('0x1234') - expect(ethersReceipt.from).to.equal('0x5678') - expect(ethersReceipt.contractAddress).to.equal('0xabcd') - expect(ethersReceipt.transactionIndex).to.equal(1) - expect(ethersReceipt.gasUsed.eq(BigNumber.from(21000))).to.equal(true) - expect(ethersReceipt.blockNumber).to.equal(123) - expect(ethersReceipt.status).to.equal(1) - expect(ethersReceipt.logs[0].address).to.equal('0xcontract') - expect(ethersReceipt.byzantium).to.equal(true) + expect(ethersReceipt.to).toBe('0x1234') + expect(ethersReceipt.from).toBe('0x5678') + expect(ethersReceipt.contractAddress).toBe('0xabcd') + expect(ethersReceipt.transactionIndex).toBe(1) + expect(ethersReceipt.gasUsed.eq(BigNumber.from(21000))).toBe(true) + expect(ethersReceipt.blockNumber).toBe(123) + expect(ethersReceipt.status).toBe(1) + expect(ethersReceipt.logs[0].address).toBe('0xcontract') + expect(ethersReceipt.byzantium).toBe(true) }) it('handles failed transaction status', () => { @@ -144,7 +144,7 @@ describe('viem compatibility', () => { const ethersReceipt = viemTransactionReceiptToEthersTransactionReceipt(viemReceipt) - expect(ethersReceipt.status).to.equal(0) + expect(ethersReceipt.status).toBe(0) }) }) }) diff --git a/packages/sdk/package.json b/packages/sdk/package.json index be10f25792..20ad9fb32c 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -32,12 +32,10 @@ "prebuild": "yarn gen:abi", "build": "rm -rf dist && tsc -p tsconfig.json", "watch": "tsc --watch", - "test": "mocha", - "test:coverage": "nyc mocha", + "test": "vitest run --config ../../vitest.config.ts", "test:fork": "SHOULD_FORK=1 hardhat test tests/fork/*.test.ts", - "test:integration": "mocha tests/integration/ --timeout 30000000 --bail", + "test:integration": "vitest run --config ../../vitest.config.ts tests/integration --test-timeout 30000000 --bail 1 --fileParallelism=false", "test:unit": "vitest run --config ../../vitest.config.ts tests/unit", - "test:ci": "nyc --reporter=lcovonly mocha --reporter xunit", "lint": "eslint .", "format": "prettier './**/*.{js,json,md,ts,yml}' '!./src/lib/abi' --write && yarn run lint --fix", "clean:compile": "ts-node scripts/cleanCompileContracts.ts", diff --git a/packages/sdk/tests/fork/inbox.test.ts b/packages/sdk/tests/fork/inbox.test.ts index fd3df901be..7991f287a3 100644 --- a/packages/sdk/tests/fork/inbox.test.ts +++ b/packages/sdk/tests/fork/inbox.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect, beforeAll, beforeEach } from 'vitest' import { BigNumber } from '@ethersproject/bignumber' import { Logger, LogLevel } from '@ethersproject/logger' @@ -90,7 +90,7 @@ describe('Inbox tools', () => { let forkBlockNumber: number let forkProviderUrl: string - before(async () => { + beforeAll(async () => { const { l1Provider } = await setup() forkBlockNumber = await l1Provider.getBlockNumber() forkProviderUrl = 'http://localhost:8545' @@ -132,12 +132,12 @@ describe('Inbox tools', () => { const forceInclusionTx = await inboxTools.forceInclude() - expect(forceInclusionTx, 'Null force inclusion').to.not.be.null + expect(forceInclusionTx, 'Null force inclusion').not.toBeNull() await forceInclusionTx!.wait() const messagesReadAfter = await sequencerInbox.totalDelayedMessagesRead() - expect(messagesReadAfter.toNumber(), 'Message not read').to.eq( + expect(messagesReadAfter.toNumber(), 'Message not read').toBe( startInboxLength.add(1).toNumber() ) }) @@ -178,11 +178,11 @@ describe('Inbox tools', () => { const inboxTools = new InboxTools(l1Signer, l2Network) const forceInclusionTx = await inboxTools.forceInclude() - expect(forceInclusionTx, 'Null force inclusion').to.not.be.null + expect(forceInclusionTx, 'Null force inclusion').not.toBeNull() await forceInclusionTx!.wait() const messagesReadAfter = await sequencerInbox.totalDelayedMessagesRead() - expect(messagesReadAfter.toNumber(), 'Message not read').to.eq( + expect(messagesReadAfter.toNumber(), 'Message not read').toBe( startInboxLength.add(2).toNumber() ) }) @@ -229,7 +229,7 @@ describe('Inbox tools', () => { await mineBlocks(6600, block.timestamp) const event = await inboxTools.getForceIncludableEvent() - expect(event?.event.messageDataHash, 'Invalid message hash.').to.eq( + expect(event?.event.messageDataHash, 'Invalid message hash.').toBe( messageDataHash ) }) @@ -239,7 +239,7 @@ describe('Inbox tools', () => { const inboxTools = new InboxTools(l1Signer, l2Network) const event = await inboxTools.getForceIncludableEvent() - expect(event, 'Event not null').to.be.null + expect(event, 'Event not null').toBeNull() }) const mineBlocks = async ( diff --git a/packages/sdk/tests/integration/childTransactionReceipt.test.ts b/packages/sdk/tests/integration/childTransactionReceipt.test.ts index 6651b0dc3e..d765497086 100644 --- a/packages/sdk/tests/integration/childTransactionReceipt.test.ts +++ b/packages/sdk/tests/integration/childTransactionReceipt.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, beforeEach, expect } from 'vitest' import { fundParentSigner, @@ -60,7 +60,7 @@ async function waitForL1BatchConfirmations( } describe('ArbProvider', () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -109,7 +109,7 @@ describe('ArbProvider', () => { 60_000 ) - expect(l1BatchConfirmations, 'missing confirmations').to.be.gt(0) + expect(l1BatchConfirmations, 'missing confirmations').toBeGreaterThan(0) if (l1BatchConfirmations > 8) { break diff --git a/packages/sdk/tests/integration/custom-fee-token/customFeeTokenEthBridger.test.ts b/packages/sdk/tests/integration/custom-fee-token/customFeeTokenEthBridger.test.ts index 7e20f3cbe8..a2b1ba391e 100644 --- a/packages/sdk/tests/integration/custom-fee-token/customFeeTokenEthBridger.test.ts +++ b/packages/sdk/tests/integration/custom-fee-token/customFeeTokenEthBridger.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { it, expect, beforeEach } from 'vitest' import { ethers, constants, Wallet } from 'ethers' import { loadEnv } from '../../../src/lib/utils/env' @@ -46,7 +46,7 @@ describeOnlyWhenCustomGasToken( approveParentCustomFeeToken, } = await import('./customFeeTokenTestHelpers') - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -78,9 +78,8 @@ describeOnlyWhenCustomGasToken( ethBridger.childNetwork.ethBridge.inbox ) - expect(allowance.toString()).to.equal( - amount.toString(), - 'allowance incorrect' + expect(allowance.toString(), 'allowance incorrect').toBe( + amount.toString() ) }) @@ -102,9 +101,8 @@ describeOnlyWhenCustomGasToken( ethBridger.childNetwork.ethBridge.inbox ) - expect(allowance.toString()).to.equal( - constants.MaxUint256.toString(), - 'allowance incorrect' + expect(allowance.toString(), 'allowance incorrect').toBe( + constants.MaxUint256.toString() ) }) @@ -113,11 +111,20 @@ describeOnlyWhenCustomGasToken( ethBridger, nativeTokenContract, parentSigner, + parentProvider, childSigner, childProvider, + childChain, } = await testSetup() const bridge = ethBridger.childNetwork.ethBridge.bridge - const amount = parseEther('2') + const decimals = await getNativeTokenDecimals({ + parentProvider, + childNetwork: childChain, + }) + // Use native token decimals for the deposit (depositERC20 takes raw token units) + const amount = parseUnits('2', decimals) + // On child chain, values are always in 18-decimal format + const amountIn18Decimals = parseEther('2') await fundParentSignerEther(parentSigner) await fundParentCustomFeeToken(parentSigner) @@ -132,15 +139,15 @@ describeOnlyWhenCustomGasToken( parentSigner, }) const depositTxReceipt = await depositTx.wait() - expect(depositTxReceipt.status).to.equal(1, 'deposit tx failed') + expect(depositTxReceipt.status, 'deposit tx failed').toBe(1) expect( // balance in the bridge after the deposit - (await nativeTokenContract.balanceOf(bridge)).toString() - ).to.equal( - // balance in the bridge after the deposit should equal to the initial balance in the bridge + the amount deposited - initialBalanceBridge.add(amount).toString(), + (await nativeTokenContract.balanceOf(bridge)).toString(), 'incorrect balance in bridge after deposit' + ).toBe( + // balance in the bridge after the deposit should equal to the initial balance in the bridge + the amount deposited + initialBalanceBridge.add(amount).toString() ) // wait for minting on L2 @@ -150,21 +157,21 @@ describeOnlyWhenCustomGasToken( const depositMessages = await depositTxReceipt.getEthDeposits( childProvider ) - expect(depositMessages.length).to.equal( - 1, - 'failed to find deposit message' - ) + expect(depositMessages.length, 'failed to find deposit message').toBe(1) const [depositMessage] = depositMessages - expect(depositMessage.value.toString()).to.equal(amount.toString()) - expect(depositMessage.to).to.equal(await childSigner.getAddress()) + // deposit message value is in 18-decimal format on child chain + expect(depositMessage.value.toString()).toBe( + amountIn18Decimals.toString() + ) + expect(depositMessage.to).toBe(await childSigner.getAddress()) expect( // balance in the depositor account after the deposit - (await childSigner.getBalance()).toString() - ).to.equal( - // balance in the depositor account after the deposit should equal to the initial balance in the depositor account + the amount deposited - initialBalanceDepositor.add(amount).toString(), + (await childSigner.getBalance()).toString(), 'incorrect balance in depositor account after deposit' + ).toBe( + // child chain balance is in 18-decimal format + initialBalanceDepositor.add(amountIn18Decimals).toString() ) }) @@ -184,7 +191,10 @@ describeOnlyWhenCustomGasToken( }) const bridge = ethBridger.childNetwork.ethBridge.bridge - const amount = parseUnits('0.2', decimals) + // Child-chain balances are always 18-decimal formatted, even when the + // parent/native token uses a different decimal count. + const amount = parseEther('0.2') + const amountInNativeDecimals = parseUnits('0.2', decimals) await fundParentSignerEther(parentSigner) await fundChildCustomFeeToken(childSigner) @@ -215,18 +225,17 @@ describeOnlyWhenCustomGasToken( }) const withdrawalTxReceipt = await withdrawalTx.wait() - expect(withdrawalTxReceipt.status).to.equal( - 1, - 'initiate withdrawal tx failed' + expect(withdrawalTxReceipt.status, 'initiate withdrawal tx failed').toBe( + 1 ) const messages = await withdrawalTxReceipt.getChildToParentMessages( parentSigner ) - expect(messages.length).to.equal( - 1, + expect( + messages.length, 'custom fee token withdraw getWithdrawalsInL2Transaction query came back empty' - ) + ).toBe(1) const withdrawalEvents = await ChildToParentMessage.getChildToParentEvents( @@ -236,17 +245,17 @@ describeOnlyWhenCustomGasToken( destinationAddress ) - expect(withdrawalEvents.length).to.equal( - 1, + expect( + withdrawalEvents.length, 'custom fee token withdraw getL2ToL1EventData failed' - ) + ).toBe(1) const [message] = messages const messageStatus = await message.status(childProvider) expect( messageStatus, `custom fee token withdraw status returned ${messageStatus}` - ).to.be.eq(ChildToParentMessageStatus.UNCONFIRMED) + ).toBe(ChildToParentMessageStatus.UNCONFIRMED) // run a miner whilst withdrawing const miner1 = Wallet.createRandom().connect(parentProvider) @@ -263,7 +272,7 @@ describeOnlyWhenCustomGasToken( expect(await message.status(childProvider), 'confirmed status') // - .to.eq(ChildToParentMessageStatus.CONFIRMED) + .toBe(ChildToParentMessageStatus.CONFIRMED) const execTx = await message.execute(childProvider) const execTxReceipt = await execTx.wait() @@ -271,28 +280,28 @@ describeOnlyWhenCustomGasToken( expect( execTxReceipt.gasUsed.toNumber(), 'gas used greater than estimate' - ).to.be.lessThan(l1GasEstimate.toNumber()) + ).toBeLessThan(l1GasEstimate.toNumber()) expect(await message.status(childProvider), 'executed status') // - .to.eq(ChildToParentMessageStatus.EXECUTED) + .toBe(ChildToParentMessageStatus.EXECUTED) expect( // balance in the bridge after the withdrawal - (await nativeTokenContract.balanceOf(bridge)).toString() - ).to.equal( - // balance in the bridge after the withdrawal should equal to the initial balance in the bridge - the amount withdrawn - initialBalanceBridge.sub(amount).toString(), + (await nativeTokenContract.balanceOf(bridge)).toString(), 'incorrect balance in bridge after withdrawal' + ).toBe( + // balance in the bridge after the withdrawal should equal to the initial balance in the bridge - the amount withdrawn + initialBalanceBridge.sub(amountInNativeDecimals).toString() ) expect( // balance in the destination after the withdrawal - (await nativeTokenContract.balanceOf(destinationAddress)).toString() - ).to.equal( - // balance in the destination after the withdrawal should equal to the initial balance in the destination + the amount withdrawn - initialBalanceDestination.add(amount).toString(), + (await nativeTokenContract.balanceOf(destinationAddress)).toString(), 'incorrect balance in destination after withdrawal' + ).toBe( + // balance in the destination after the withdrawal should equal to the initial balance in the destination + the amount withdrawn + initialBalanceDestination.add(amountInNativeDecimals).toString() ) }) } diff --git a/packages/sdk/tests/integration/custom-fee-token/customFeeTokenTestHelpers.ts b/packages/sdk/tests/integration/custom-fee-token/customFeeTokenTestHelpers.ts index b84a8289b5..458cbbc9e4 100644 --- a/packages/sdk/tests/integration/custom-fee-token/customFeeTokenTestHelpers.ts +++ b/packages/sdk/tests/integration/custom-fee-token/customFeeTokenTestHelpers.ts @@ -100,7 +100,7 @@ export async function fundChildCustomFeeToken(childSigner: Signer) { const decimals = await getNativeTokenDecimals({ parentProvider: ethProvider(), - childNetwork: localNetworks().l2Network, + childNetwork: localNetworks().l3Network ?? localNetworks().l2Network, }) const tx = await deployerWallet.sendTransaction({ diff --git a/packages/sdk/tests/integration/custom-fee-token/mochaExtensions.ts b/packages/sdk/tests/integration/custom-fee-token/mochaExtensions.ts index a2b8ba2ad2..97590e0bda 100644 --- a/packages/sdk/tests/integration/custom-fee-token/mochaExtensions.ts +++ b/packages/sdk/tests/integration/custom-fee-token/mochaExtensions.ts @@ -1,3 +1,4 @@ +import { describe, it } from 'vitest' import { isArbitrumNetworkWithCustomFeeToken } from './customFeeTokenTestHelpers' const customGasTokenEnvironment = isArbitrumNetworkWithCustomFeeToken() diff --git a/packages/sdk/tests/integration/customerc20.test.ts b/packages/sdk/tests/integration/customerc20.test.ts index 8376b83ece..28b7b9d4f9 100644 --- a/packages/sdk/tests/integration/customerc20.test.ts +++ b/packages/sdk/tests/integration/customerc20.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect, beforeAll, beforeEach } from 'vitest' import { Signer, Wallet, constants, utils } from 'ethers' import { BigNumber } from '@ethersproject/bignumber' import { Logger, LogLevel } from '@ethersproject/logger' @@ -52,7 +52,7 @@ const depositAmount = BigNumber.from(100) const withdrawalAmount = BigNumber.from(10) describe('Custom ERC20', () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -65,7 +65,7 @@ describe('Custom ERC20', () => { parentCustomToken: TestCustomTokenL1 | TestOrbitCustomTokenL1 } - before('init', async () => { + beforeAll(async () => { testState = { ...(await testSetup()), parentCustomToken: {} as any, @@ -162,16 +162,6 @@ const registerCustomToken = async ( ) await parentCustomToken.deployed() - adminErc20Bridger - .isRegistered({ - erc20ParentAddress: parentCustomToken.address, - parentProvider: parentSigner.provider!, - childProvider: childSigner.provider!, - }) - .then(isRegistered => { - expect(isRegistered, 'expected token not to be registered').to.be.false - }) - const childCustomTokenFac = new TestArbCustomToken__factory(childSigner) const childCustomToken = await childCustomTokenFac.deploy( childChain.tokenBridge.childCustomGateway, @@ -198,28 +188,28 @@ const registerCustomToken = async ( expect( startParentGatewayAddress, 'Start parentGatewayAddress not equal empty address' - ).to.eq(constants.AddressZero) + ).toBe(constants.AddressZero) const startChildGatewayAddress = await childGatewayRouter.l1TokenToGateway( childCustomToken.address ) expect( startChildGatewayAddress, 'Start childGatewayAddress not equal empty address' - ).to.eq(constants.AddressZero) + ).toBe(constants.AddressZero) const startParentErc20Address = await parentCustomGateway.l1ToL2Token( parentCustomToken.address ) expect( startParentErc20Address, 'Start parentErc20Address not equal empty address' - ).to.eq(constants.AddressZero) + ).toBe(constants.AddressZero) const startChildErc20Address = await childCustomGateway.l1ToL2Token( parentCustomToken.address ) expect( startChildErc20Address, 'Start childErc20Address not equal empty address' - ).to.eq(constants.AddressZero) + ).toBe(constants.AddressZero) // it should fail without the approval if (isArbitrumNetworkWithCustomFeeToken()) { @@ -233,7 +223,7 @@ const registerCustomToken = async ( await regTx.wait() throw new Error('Child custom token is not approved but got deployed') } catch (err) { - expect((err as Error).message).to.contain('Insufficient allowance') + expect((err as Error).message).toContain('Insufficient allowance') } } @@ -257,15 +247,15 @@ const registerCustomToken = async ( const parentToChildMessages = await regRec.getParentToChildMessages( childSigner.provider! ) - expect(parentToChildMessages.length, 'Should be 2 messages.').to.eq(2) + expect(parentToChildMessages.length, 'Should be 2 messages.').toBe(2) const setTokenTx = await parentToChildMessages[0].waitForStatus() - expect(setTokenTx.status, 'Set token not redeemed.').to.eq( + expect(setTokenTx.status, 'Set token not redeemed.').toBe( ParentToChildMessageStatus.REDEEMED ) const setGateways = await parentToChildMessages[1].waitForStatus() - expect(setGateways.status, 'Set gateways not redeemed.').to.eq( + expect(setGateways.status, 'Set gateways not redeemed.').toBe( ParentToChildMessageStatus.REDEEMED ) @@ -276,7 +266,7 @@ const registerCustomToken = async ( expect( endParentGatewayAddress, 'End parentGatewayAddress not equal to parent custom gateway' - ).to.eq(childChain.tokenBridge.parentCustomGateway) + ).toBe(childChain.tokenBridge.parentCustomGateway) const endChildGatewayAddress = await childGatewayRouter.l1TokenToGateway( parentCustomToken.address @@ -284,7 +274,7 @@ const registerCustomToken = async ( expect( endChildGatewayAddress, 'End childGatewayAddress not equal to child custom gateway' - ).to.eq(childChain.tokenBridge.childCustomGateway) + ).toBe(childChain.tokenBridge.childCustomGateway) const endParentErc20Address = await parentCustomGateway.l1ToL2Token( parentCustomToken.address @@ -292,7 +282,7 @@ const registerCustomToken = async ( expect( endParentErc20Address, 'End parentErc20Address not equal parentCustomToken address' - ).to.eq(childCustomToken.address) + ).toBe(childCustomToken.address) const endChildErc20Address = await childCustomGateway.l1ToL2Token( parentCustomToken.address @@ -300,7 +290,7 @@ const registerCustomToken = async ( expect( endChildErc20Address, 'End childErc20Address not equal childCustomToken address' - ).to.eq(childCustomToken.address) + ).toBe(childCustomToken.address) adminErc20Bridger .isRegistered({ @@ -309,7 +299,7 @@ const registerCustomToken = async ( childProvider: childSigner.provider!, }) .then(isRegistered => { - expect(isRegistered, 'expected token to be registered').to.be.true + expect(isRegistered, 'expected token to be registered').toBe(true) }) return { diff --git a/packages/sdk/tests/integration/eth.test.ts b/packages/sdk/tests/integration/eth.test.ts index 63ed9d0fac..dc2699eb11 100644 --- a/packages/sdk/tests/integration/eth.test.ts +++ b/packages/sdk/tests/integration/eth.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, beforeEach, expect } from 'vitest' import { loadEnv } from '../../src/lib/utils/env' import { Wallet } from '@ethersproject/wallet' import { parseEther } from '@ethersproject/units' @@ -46,7 +46,7 @@ import { parseUnits } from 'ethers/lib/utils' loadEnv() describe('Ether', async () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -76,10 +76,10 @@ describe('Ether', async () => { const randomBalanceAfter = await childSigner.provider!.getBalance( randomAddress ) - expect(randomBalanceAfter.toString(), 'random address balance after').to.eq( + expect(randomBalanceAfter.toString(), 'random address balance after').toBe( amountToSend.toString() ) - expect(balanceAfter.toString(), 'l2 balance after').to.eq( + expect(balanceAfter.toString(), 'l2 balance after').toBe( balanceBefore .sub(rec.gasUsed.mul(rec.effectiveGasPrice)) .sub(amountToSend) @@ -96,7 +96,7 @@ describe('Ether', async () => { await ethBridger.approveGasToken({ parentSigner }) expect.fail(`"EthBridger.approveGasToken" should have thrown`) } catch (error: any) { - expect(error.message).to.equal('chain uses ETH as its native/gas token') + expect(error.message).toBe('chain uses ETH as its native/gas token') } } ) @@ -128,7 +128,7 @@ describe('Ether', async () => { }) const rec = await res.wait() - expect(rec.status).to.equal(1, 'eth deposit parent txn failed') + expect(rec.status, 'eth deposit parent txn failed').toBe(1) const finalInboxBalance = await parentSigner.provider!.getBalance( inboxAddress ) @@ -148,25 +148,24 @@ describe('Ether', async () => { ) const parentToChildMessage = parentToChildMessages[0] - expect(parentToChildMessages.length).to.eq( - 1, + expect( + parentToChildMessages.length, 'failed to find 1 parent-to-child message' - ) - expect(parentToChildMessage.to).to.eq( - walletAddress, - 'message inputs value error' + ).toBe(1) + expect(parentToChildMessage.to, 'message inputs value error').toBe( + walletAddress ) expect( parentToChildMessage.value.toString(), 'message inputs value error' - ).to.eq(parseEther(amount).toString()) + ).toBe(parseEther(amount).toString()) - expect(waitResult.complete).to.eq(true, 'eth deposit not complete') - expect(waitResult.childTxReceipt).to.exist - expect(waitResult.childTxReceipt).to.not.be.null + expect(waitResult.complete, 'eth deposit not complete').toBe(true) + expect(waitResult.childTxReceipt).toBeTruthy() + expect(waitResult.childTxReceipt).not.toBeNull() const testWalletChildEthBalance = await childSigner.getBalance() - expect(testWalletChildEthBalance.toString(), 'final balance').to.eq( + expect(testWalletChildEthBalance.toString(), 'final balance').toBe( parseEther(amount).toString() ) }) @@ -201,7 +200,7 @@ describe('Ether', async () => { }) const rec = await res.wait() - expect(rec.status).to.equal(1, 'eth deposit L1 txn failed') + expect(rec.status, 'eth deposit L1 txn failed').toBe(1) const finalInboxBalance = await parentSigner.provider!.getBalance( inboxAddress ) @@ -213,50 +212,46 @@ describe('Ether', async () => { const parentToChildMessages = await rec.getParentToChildMessages( childSigner.provider! ) - expect(parentToChildMessages.length).to.eq( - 1, + expect( + parentToChildMessages.length, 'failed to find 1 parent-to-child message' - ) + ).toBe(1) const parentToChildMessage = parentToChildMessages[0] - expect(parentToChildMessage.messageData.destAddress).to.eq( - destWallet.address, + expect( + parentToChildMessage.messageData.destAddress, 'message inputs value error' - ) + ).toBe(destWallet.address) expect( parentToChildMessage.messageData.l2CallValue.toString(), 'message inputs value error' - ).to.eq(parseEther(amount).toString()) + ).toBe(parseEther(amount).toString()) const retryableTicketResult = await parentToChildMessage.waitForStatus() - expect(retryableTicketResult.status).to.eq( - ParentToChildMessageStatus.REDEEMED, - 'Retryable ticket not redeemed' + expect(retryableTicketResult.status, 'Retryable ticket not redeemed').toBe( + ParentToChildMessageStatus.REDEEMED ) const retryableTxReceipt = await childSigner.provider!.getTransactionReceipt( parentToChildMessage.retryableCreationId ) - expect(retryableTxReceipt).to.exist - expect(retryableTxReceipt).to.not.be.null + expect(retryableTxReceipt).toBeTruthy() + expect(retryableTxReceipt).not.toBeNull() const childRetryableTxReceipt = new ChildTransactionReceipt( retryableTxReceipt ) const ticketRedeemEvents = childRetryableTxReceipt.getRedeemScheduledEvents() - expect(ticketRedeemEvents.length).to.eq( - 1, - 'failed finding the redeem event' - ) - expect(ticketRedeemEvents[0].retryTxHash).to.exist - expect(ticketRedeemEvents[0].retryTxHash).to.not.be.null + expect(ticketRedeemEvents.length, 'failed finding the redeem event').toBe(1) + expect(ticketRedeemEvents[0].retryTxHash).toBeTruthy() + expect(ticketRedeemEvents[0].retryTxHash).not.toBeNull() const testWalletChildEthBalance = await childSigner.provider!.getBalance( destWallet.address ) - expect(testWalletChildEthBalance.toString(), 'final balance').to.eq( + expect(testWalletChildEthBalance.toString(), 'final balance').toBe( parseEther(amount).toString() ) }) @@ -295,19 +290,19 @@ describe('Ether', async () => { const parentToChildMessages = await rec.getParentToChildMessages( childSigner.provider! ) - expect(parentToChildMessages.length).to.eq( - 1, + expect( + parentToChildMessages.length, 'failed to find 1 parent-to-child message' - ) + ).toBe(1) const parentToChildMessageReader = parentToChildMessages[0] const retryableTicketResult = await parentToChildMessageReader.waitForStatus() - expect(retryableTicketResult.status).to.eq( - ParentToChildMessageStatus.FUNDS_DEPOSITED_ON_CHILD, + expect( + retryableTicketResult.status, 'unexpected status, expected auto-redeem to fail' - ) + ).toBe(ParentToChildMessageStatus.FUNDS_DEPOSITED_ON_CHILD) let testWalletChildEthBalance = await childSigner.provider!.getBalance( destWallet.address @@ -316,7 +311,7 @@ describe('Ether', async () => { expect( testWalletChildEthBalance.eq(constants.Zero), 'balance before auto-redeem' - ).to.be.true + ).toBe(true) await fundChildSigner(childSigner) @@ -338,7 +333,7 @@ describe('Ether', async () => { expect( testWalletChildEthBalance.toString(), 'balance after manual redeem' - ).to.eq(parseEther(amount).toString()) + ).toBe(parseEther(amount).toString()) }) it('withdraw Ether transaction succeeds', async () => { @@ -374,10 +369,7 @@ describe('Ether', async () => { const withdrawEthRec = await withdrawEthRes.wait() - expect(withdrawEthRec.status).to.equal( - 1, - 'initiate eth withdraw txn failed' - ) + expect(withdrawEthRec.status, 'initiate eth withdraw txn failed').toBe(1) const withdrawMessage = ( await withdrawEthRec.getChildToParentMessages(parentSigner) @@ -385,7 +377,7 @@ describe('Ether', async () => { expect( withdrawMessage, 'eth withdraw getWithdrawalsInL2Transaction query came back empty' - ).to.exist + ).toBeTruthy() const withdrawEvents = await ChildToParentMessage.getChildToParentEvents( childSigner.provider!, @@ -394,16 +386,15 @@ describe('Ether', async () => { randomAddress ) - expect(withdrawEvents.length).to.equal( - 1, + expect( + withdrawEvents.length, 'eth withdraw getL2ToL1EventData failed' - ) + ).toBe(1) const messageStatus = await withdrawMessage.status(childSigner.provider!) - expect( - messageStatus, - `eth withdraw status returned ${messageStatus}` - ).to.be.eq(ChildToParentMessageStatus.UNCONFIRMED) + expect(messageStatus, `eth withdraw status returned ${messageStatus}`).toBe( + ChildToParentMessageStatus.UNCONFIRMED + ) // CHRIS: TODO: comment this back in when fixed in nitro // const actualFinalBalance = await childSigner.getBalance() @@ -430,7 +421,7 @@ describe('Ether', async () => { expect( await withdrawMessage.status(childSigner.provider!), 'confirmed status' - ).to.eq(ChildToParentMessageStatus.CONFIRMED) + ).toBe(ChildToParentMessageStatus.CONFIRMED) const execTx = await withdrawMessage.execute(childSigner.provider!) const execRec = await execTx.wait() @@ -438,12 +429,12 @@ describe('Ether', async () => { expect( execRec.gasUsed.toNumber(), 'Gas used greater than estimate' - ).to.be.lessThan(l1GasEstimate.toNumber()) + ).toBeLessThan(l1GasEstimate.toNumber()) expect( await withdrawMessage.status(childSigner.provider!), 'executed status' - ).to.eq(ChildToParentMessageStatus.EXECUTED) + ).toBe(ChildToParentMessageStatus.EXECUTED) const decimals = await getNativeTokenDecimals({ parentProvider, @@ -456,7 +447,7 @@ describe('Ether', async () => { parentSigner.provider! ).balanceOf(randomAddress) : await parentSigner.provider!.getBalance(randomAddress) - expect(finalRandomBalance.toString(), 'L1 final balance').to.eq( + expect(finalRandomBalance.toString(), 'L1 final balance').toBe( scaleFrom18DecimalsToNativeTokenDecimals({ amount: ethToWithdraw, decimals, diff --git a/packages/sdk/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts b/packages/sdk/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts index bf4a79bb68..374ab3dbef 100644 --- a/packages/sdk/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts +++ b/packages/sdk/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts @@ -1,6 +1,6 @@ import { JsonRpcProvider } from '@ethersproject/providers' import { constants } from 'ethers' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { loadEnv } from '../../src/lib/utils/env' import { @@ -23,26 +23,26 @@ describe('getArbitrumNetworkInformationFromRollup', () => { ethProvider ) - expect(parentChainId, 'parentChainId is not correct').to.eq( + expect(parentChainId, 'parentChainId is not correct').toBe( arb1.parentChainId ) - expect(confirmPeriodBlocks, 'confirmPeriodBlocks is not correct').to.eq( + expect(confirmPeriodBlocks, 'confirmPeriodBlocks is not correct').toBe( arb1.confirmPeriodBlocks ) const { bridge, inbox, sequencerInbox, outbox, rollup } = ethBridge const arb1EthBridge = arb1.ethBridge - expect(bridge, 'Bridge contract is not correct').to.eq(arb1EthBridge.bridge) - expect(inbox, 'Inbox contract is not correct').to.eq(arb1EthBridge.inbox) - expect(sequencerInbox, 'SequencerInbox contract is not correct').to.eq( + expect(bridge, 'Bridge contract is not correct').toBe(arb1EthBridge.bridge) + expect(inbox, 'Inbox contract is not correct').toBe(arb1EthBridge.inbox) + expect(sequencerInbox, 'SequencerInbox contract is not correct').toBe( arb1EthBridge.sequencerInbox ) - expect(outbox, 'Outbox contract is not correct').to.eq(arb1EthBridge.outbox) - expect(rollup, 'Rollup contract is not correct').to.eq(arb1EthBridge.rollup) + expect(outbox, 'Outbox contract is not correct').toBe(arb1EthBridge.outbox) + expect(rollup, 'Rollup contract is not correct').toBe(arb1EthBridge.rollup) - expect(nativeToken, 'Native token is not correct').to.eq( + expect(nativeToken, 'Native token is not correct').toBe( constants.AddressZero ) }) @@ -54,31 +54,31 @@ describe('getArbitrumNetworkInformationFromRollup', () => { new JsonRpcProvider('https://arb1.arbitrum.io/rpc') ) - expect(parentChainId, 'parentChainId is not correct').to.eq(42161) + expect(parentChainId, 'parentChainId is not correct').toBe(42161) - expect(confirmPeriodBlocks, 'confirmPeriodBlocks is not correct').to.eq( + expect(confirmPeriodBlocks, 'confirmPeriodBlocks is not correct').toBe( 45818 ) const { bridge, inbox, sequencerInbox, outbox, rollup } = ethBridge - expect(bridge, 'Bridge contract is not correct').to.eq( + expect(bridge, 'Bridge contract is not correct').toBe( '0x7dd8A76bdAeBE3BBBaCD7Aa87f1D4FDa1E60f94f' ) - expect(inbox, 'Inbox contract is not correct').to.eq( + expect(inbox, 'Inbox contract is not correct').toBe( '0xaE21fDA3de92dE2FDAF606233b2863782Ba046F9' ) - expect(sequencerInbox, 'SequencerInbox contract is not correct').to.eq( + expect(sequencerInbox, 'SequencerInbox contract is not correct').toBe( '0x995a9d3ca121D48d21087eDE20bc8acb2398c8B1' ) - expect(outbox, 'Outbox contract is not correct').to.eq( + expect(outbox, 'Outbox contract is not correct').toBe( '0x1E400568AD4840dbE50FB32f306B842e9ddeF726' ) - expect(rollup, 'Rollup contract is not correct').to.eq( + expect(rollup, 'Rollup contract is not correct').toBe( '0xC47DacFbAa80Bd9D8112F4e8069482c2A3221336' ) - expect(nativeToken, 'Native token is not correct').to.eq( + expect(nativeToken, 'Native token is not correct').toBe( '0x4Cb9a7AE498CEDcBb5EAe9f25736aE7d428C9D66' ) }) diff --git a/packages/sdk/tests/integration/l1l3Bridger.test.ts b/packages/sdk/tests/integration/l1l3Bridger.test.ts index e08bd18784..93d88a6266 100644 --- a/packages/sdk/tests/integration/l1l3Bridger.test.ts +++ b/packages/sdk/tests/integration/l1l3Bridger.test.ts @@ -18,7 +18,7 @@ import { EthL1L3Bridger, Erc20L1L3DepositRequestParams, } from '../../src/lib/assetBridger/l1l3Bridger' -import { assert, expect } from 'chai' +import { describe, it, expect, beforeAll } from 'vitest' import { isArbitrumNetworkWithCustomFeeToken } from './custom-fee-token/customFeeTokenTestHelpers' import { ERC20__factory } from '../../src/lib/abi/factories/ERC20__factory' import { Deferrable } from 'ethers/lib/utils' @@ -210,7 +210,7 @@ describe('L1 to L3 Bridging', () => { } // setup for all test cases - before(async function () { + beforeAll(async function () { await skipIfMainnet(this) const setup = await testSetup() @@ -305,7 +305,7 @@ describe('L1 to L3 Bridging', () => { itOnlyWhenCustomGasToken( 'should fail construction if l3 uses a custom fee token', async () => { - expect(() => new EthL1L3Bridger(l3Network)).to.throw( + expect(() => new EthL1L3Bridger(l3Network)).toThrow( `L3 network ${l3Network.name} uses a custom fee token` ) } @@ -342,10 +342,10 @@ describe('L1 to L3 Bridging', () => { // check eth balances const l3Balance = await l3Provider.getBalance(l3Recipient) - assert(l3Balance.gt(ethers.utils.parseEther('0.1'))) + expect(l3Balance.gt(ethers.utils.parseEther('0.1'))).toBe(true) const l2Balance = await l2Signer.provider!.getBalance(l2RefundAddress) - assert(l2Balance.gt(ethers.utils.parseEther('0'))) + expect(l2Balance.gt(ethers.utils.parseEther('0'))).toBe(true) }) }) @@ -355,7 +355,7 @@ describe('L1 to L3 Bridging', () => { let l1l3Bridger: Erc20L1L3Bridger // deploy teleporter contracts and mock token - before(async function () { + beforeAll(async function () { const { l2ContractsDeployer, l1Teleporter } = await deployTeleportContracts(l1Signer, l2Signer) @@ -377,21 +377,21 @@ describe('L1 to L3 Bridging', () => { itOnlyWhenCustomGasToken( 'should properly get l2 and l1 fee token addresses', - async function () { + async function (context) { const decimals = await getNativeTokenDecimals({ parentProvider: l1Signer.provider!, childNetwork: l3Network, }) if (decimals !== 18) { - this.skip() + context.skip() } if (l1l3Bridger.l2GasTokenAddress === undefined) { throw new Error('L2 fee token address is undefined') } // make sure l2 token equals l3 native token - expect(l1l3Bridger.l2GasTokenAddress).to.eq(l3Network.nativeToken) + expect(l1l3Bridger.l2GasTokenAddress).toBe(l3Network.nativeToken) // make sure l1 token maps to l2 token expect( await new Erc20Bridger(l2Network).getChildErc20Address( @@ -401,20 +401,20 @@ describe('L1 to L3 Bridging', () => { ))!, l1Signer.provider! ) - ).to.eq(l1l3Bridger.l2GasTokenAddress) + ).toBe(l1l3Bridger.l2GasTokenAddress) } ) itOnlyWhenCustomGasToken( 'should throw getting l1 gas token address when it is unavailable', - async function () { + async function (context) { const decimals = await getNativeTokenDecimals({ parentProvider: l1Signer.provider!, childNetwork: l3Network, }) if (decimals !== 18) { - this.skip() + context.skip() } const networkCopy = JSON.parse( @@ -435,14 +435,14 @@ describe('L1 to L3 Bridging', () => { itOnlyWhenCustomGasToken( 'should throw when the fee token does not use 18 decimals on L1 or L2', - async function () { + async function (context) { const decimals = await getNativeTokenDecimals({ parentProvider: l1Signer.provider!, childNetwork: l3Network, }) if (decimals !== 18) { - this.skip() + context.skip() } const hackedL1Provider = new ethers.providers.JsonRpcProvider( @@ -498,7 +498,7 @@ describe('L1 to L3 Bridging', () => { itOnlyWhenEth('should not have l1 and l2 fee token addresses', async () => { // make sure l2 is undefined and l1 is also undefined - expect(l1l3Bridger.l2GasTokenAddress).to.be.undefined + expect(l1l3Bridger.l2GasTokenAddress).toBeUndefined() await expectPromiseToReject( l1l3Bridger.getGasTokenOnL1(l1Signer.provider!, l2Signer.provider!), 'L3 uses ETH for gas' @@ -514,7 +514,7 @@ describe('L1 to L3 Bridging', () => { parentWeth, l1Signer.provider! ) - expect(ans).to.eq(childWeth) + expect(ans).toBe(childWeth) }) it('getL1L2GatewayAddress', async () => { @@ -528,7 +528,7 @@ describe('L1 to L3 Bridging', () => { l1Signer.provider! ) - expect(wethAns).to.eq(l1l2WethGateway) + expect(wethAns).toBe(l1l2WethGateway) // test default gateway const l1l2Gateway = l2Network.tokenBridge.parentErc20Gateway @@ -536,7 +536,7 @@ describe('L1 to L3 Bridging', () => { l1Token.address, l1Signer.provider! ) - expect(defaultAns).to.eq(l1l2Gateway) + expect(defaultAns).toBe(l1l2Gateway) }) itOnlyWhenEth('getL3Erc20Address', async () => { @@ -551,7 +551,7 @@ describe('L1 to L3 Bridging', () => { l1Signer.provider!, l2Signer.provider! ) - expect(ans).to.eq(l3Weth) + expect(ans).toBe(l3Weth) }) itOnlyWhenEth('getL2L3GatewayAddress', async () => { @@ -568,7 +568,7 @@ describe('L1 to L3 Bridging', () => { l2Signer.provider! ) - expect(wethAns).to.eq(l2l3WethGateway) + expect(wethAns).toBe(l2l3WethGateway) // test default gateway const l2l3Gateway = l3Network.tokenBridge.parentErc20Gateway @@ -577,7 +577,7 @@ describe('L1 to L3 Bridging', () => { l1Signer.provider!, l2Signer.provider! ) - expect(defaultAns).to.eq(l2l3Gateway) + expect(defaultAns).toBe(l2l3Gateway) }) it('approves', async () => { @@ -589,14 +589,14 @@ describe('L1 to L3 Bridging', () => { }) ).wait() - assert( + expect( ( await l1Token.allowance( await l1Signer.getAddress(), l1l3Bridger.teleporter.l1Teleporter ) ).eq(ethers.constants.MaxUint256) - ) + ).toBe(true) }) it('functions should be guarded by check*Network', async () => { @@ -813,7 +813,7 @@ describe('L1 to L3 Bridging', () => { l1Signer, }) - assert(depositTxRequest.gasTokenAmount.eq(0)) + expect(depositTxRequest.gasTokenAmount.eq(0)).toBe(true) const depositTx = await l1l3Bridger.deposit({ l1Signer, @@ -866,7 +866,7 @@ describe('L1 to L3 Bridging', () => { const l3Balance = await l3Token.balanceOf(l3Recipient) - assert(l3Balance.eq(amount)) + expect(l3Balance.eq(amount)).toBe(true) }) async function testHappyPathNonFeeOrStandard( @@ -878,7 +878,7 @@ describe('L1 to L3 Bridging', () => { }) if (isArbitrumNetworkWithCustomFeeToken()) { - assert(depositTxRequest.gasTokenAmount.gt('0')) + expect(depositTxRequest.gasTokenAmount.gt('0')).toBe(true) // approve fee token await ( await l1l3Bridger.approveGasToken({ @@ -888,7 +888,7 @@ describe('L1 to L3 Bridging', () => { }) ).wait() } else { - assert(depositTxRequest.gasTokenAmount.eq('0')) + expect(depositTxRequest.gasTokenAmount.eq('0')).toBe(true) } const depositTx = await l1l3Bridger.deposit({ @@ -921,25 +921,25 @@ describe('L1 to L3 Bridging', () => { depositParams.destinationAddress || (await l1Signer.getAddress()) ) - assert( + expect( ( await l3Provider.getBalance( depositParams.destinationAddress || (await l1Signer.getAddress()) ) ).gt('0') - ) + ).toBe(true) - assert(l3Balance.eq(amount)) + expect(l3Balance.eq(amount)).toBe(true) } - it('happy path non fee token or standard', async function () { + it('happy path non fee token or standard', async function (context) { const decimals = await getNativeTokenDecimals({ parentProvider: l1Signer.provider!, childNetwork: l3Network, }) if (decimals !== 18) { - this.skip() + context.skip() } const l3Recipient = ethers.utils.hexlify(ethers.utils.randomBytes(20)) @@ -955,14 +955,14 @@ describe('L1 to L3 Bridging', () => { await testHappyPathNonFeeOrStandard(depositParams) }) - it('happy path weth', async function () { + it('happy path weth', async function (context) { const decimals = await getNativeTokenDecimals({ parentProvider: l1Signer.provider!, childNetwork: l3Network, }) if (decimals !== 18) { - this.skip() + context.skip() } const l3Recipient = ethers.utils.hexlify(ethers.utils.randomBytes(20)) @@ -994,59 +994,62 @@ describe('L1 to L3 Bridging', () => { await testHappyPathNonFeeOrStandard(depositParams) }) - itOnlyWhenCustomGasToken('happy path OnlyCustomFee', async function () { - const decimals = await getNativeTokenDecimals({ - parentProvider: l1Signer.provider!, - childNetwork: l3Network, - }) + itOnlyWhenCustomGasToken( + 'happy path OnlyCustomFee', + async function (context) { + const decimals = await getNativeTokenDecimals({ + parentProvider: l1Signer.provider!, + childNetwork: l3Network, + }) - if (decimals !== 18) { - this.skip() - } + if (decimals !== 18) { + context.skip() + } - const l3Recipient = ethers.utils.hexlify(ethers.utils.randomBytes(20)) - const l1FeeToken = (await l1l3Bridger.getGasTokenOnL1( - l1Signer.provider!, - l2Signer.provider! - ))! + const l3Recipient = ethers.utils.hexlify(ethers.utils.randomBytes(20)) + const l1FeeToken = (await l1l3Bridger.getGasTokenOnL1( + l1Signer.provider!, + l2Signer.provider! + ))! - const depositParams: Erc20L1L3DepositRequestParams = { - erc20L1Address: l1FeeToken, - destinationAddress: l3Recipient, - amount: ethers.utils.parseEther('0.1'), - l2Provider: l2Signer.provider!, - l3Provider, - } + const depositParams: Erc20L1L3DepositRequestParams = { + erc20L1Address: l1FeeToken, + destinationAddress: l3Recipient, + amount: ethers.utils.parseEther('0.1'), + l2Provider: l2Signer.provider!, + l3Provider, + } - const depositTxRequest = await l1l3Bridger.getDepositRequest({ - ...depositParams, - l1Signer, - }) + const depositTxRequest = await l1l3Bridger.getDepositRequest({ + ...depositParams, + l1Signer, + }) - await ( - await l1l3Bridger.approveToken({ ...depositParams, l1Signer }) - ).wait() + await ( + await l1l3Bridger.approveToken({ ...depositParams, l1Signer }) + ).wait() - const depositTx = await l1l3Bridger.deposit({ - l1Signer, - txRequest: depositTxRequest.txRequest, - }) + const depositTx = await l1l3Bridger.deposit({ + l1Signer, + txRequest: depositTxRequest.txRequest, + }) - const depositReceipt = await depositTx.wait() + const depositReceipt = await depositTx.wait() - // poll status - await poll(async () => { - const status = await l1l3Bridger.getDepositStatus({ - txHash: depositReceipt.transactionHash, - l1Provider: l1Signer.provider!, - l2Provider: l2Signer.provider!, - l3Provider, - }) - return status.completed - }, 1000) + // poll status + await poll(async () => { + const status = await l1l3Bridger.getDepositStatus({ + txHash: depositReceipt.transactionHash, + l1Provider: l1Signer.provider!, + l2Provider: l2Signer.provider!, + l3Provider, + }) + return status.completed + }, 1000) - // todo make this check better - assert((await l3Provider.getBalance(l3Recipient)).gt('0')) - }) + // todo make this check better + expect((await l3Provider.getBalance(l3Recipient)).gt('0')).toBe(true) + } + ) }) }) diff --git a/packages/sdk/tests/integration/parentToChildMessageCreator.test.ts b/packages/sdk/tests/integration/parentToChildMessageCreator.test.ts index 086e0e7403..95d3601c04 100644 --- a/packages/sdk/tests/integration/parentToChildMessageCreator.test.ts +++ b/packages/sdk/tests/integration/parentToChildMessageCreator.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect, beforeEach } from 'vitest' import { providers, utils } from 'ethers' import { fundParentSigner, skipIfMainnet } from './testHelpers' import { testSetup } from '../testSetup' @@ -30,7 +30,7 @@ import { } from './custom-fee-token/customFeeTokenTestHelpers' describe('ParentToChildMessageCreator', () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -78,12 +78,12 @@ describe('ParentToChildMessageCreator', () => { // Getting the ParentToChildMessage const parentToChildMessages = await parentSubmissionTxReceipt.getParentToChildMessages(arbProvider) - expect(parentToChildMessages.length).to.eq(1) + expect(parentToChildMessages.length).toBe(1) const parentToChildMessage = parentToChildMessages[0] // And waiting for it to be redeemed const retryableTicketResult = await parentToChildMessage.waitForStatus() - expect(retryableTicketResult.status).to.eq( + expect(retryableTicketResult.status).toBe( ParentToChildMessageStatus.REDEEMED ) @@ -95,7 +95,7 @@ describe('ParentToChildMessageCreator', () => { expect( initialChildChainBalance.add(testAmount).lt(finalChildChainBalance), 'Child chain balance not updated' - ).to.be.true + ).toBe(true) }) it('allows the creation of Retryable Tickets sending a request', async () => { @@ -147,12 +147,12 @@ describe('ParentToChildMessageCreator', () => { // Getting the ParentToChildMessage const parentToChildMessages = await parentSubmissionTxReceipt.getParentToChildMessages(arbProvider) - expect(parentToChildMessages.length).to.eq(1) + expect(parentToChildMessages.length).toBe(1) const parentToChildMessage = parentToChildMessages[0] // And waiting for it to be redeemed const retryableTicketResult = await parentToChildMessage.waitForStatus() - expect(retryableTicketResult.status).to.eq( + expect(retryableTicketResult.status).toBe( ParentToChildMessageStatus.REDEEMED ) @@ -164,6 +164,6 @@ describe('ParentToChildMessageCreator', () => { expect( initialChildChainBalance.add(testAmount).lt(finalChildChainBalance), 'Child chain balance not updated' - ).to.be.true + ).toBe(true) }) }) diff --git a/packages/sdk/tests/integration/parentToChildMessageGasEstimator.test.ts b/packages/sdk/tests/integration/parentToChildMessageGasEstimator.test.ts index 1d60a1d9bd..c982544374 100644 --- a/packages/sdk/tests/integration/parentToChildMessageGasEstimator.test.ts +++ b/packages/sdk/tests/integration/parentToChildMessageGasEstimator.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, expect, beforeEach } from 'vitest' import { BigNumber } from 'ethers' import { skipIfMainnet } from './testHelpers' @@ -28,7 +28,7 @@ import { } from './custom-fee-token/mochaExtensions' describe('ParentToChildMessageGasEstimator', () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -45,7 +45,7 @@ describe('ParentToChildMessageGasEstimator', () => { 123456 ) - expect(submissionFee.toString()).to.not.eq(BigNumber.from(0).toString()) + expect(submissionFee.toString()).not.toBe(BigNumber.from(0).toString()) } ) @@ -62,7 +62,7 @@ describe('ParentToChildMessageGasEstimator', () => { 123456 ) - expect(submissionFee.toString()).to.eq(BigNumber.from(0).toString()) + expect(submissionFee.toString()).toBe(BigNumber.from(0).toString()) } ) }) diff --git a/packages/sdk/tests/integration/retryableData.test.ts b/packages/sdk/tests/integration/retryableData.test.ts index 6d527428ac..eebb328cb6 100644 --- a/packages/sdk/tests/integration/retryableData.test.ts +++ b/packages/sdk/tests/integration/retryableData.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { assert, expect } from 'chai' +import { describe, it, expect, beforeEach } from 'vitest' import { BigNumber } from '@ethersproject/bignumber' import { hexlify } from '@ethersproject/bytes' import { TestERC20__factory } from '../../src/lib/abi/factories/TestERC20__factory' @@ -36,7 +36,7 @@ import { } from '../../src/lib/utils/lib' describe('RevertData', () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -122,31 +122,31 @@ describe('RevertData', () => { ) } - assert.fail(`Expected ${func} to fail`) + expect.fail(`Expected ${func} to fail`) } catch (err) { const typedErr = err as Error const parsed = RetryableDataTools.tryParseError(typedErr) if (!parsed) throw err - expect(parsed.callValueRefundAddress, 'callValueRefundAddress').to.eq( + expect(parsed.callValueRefundAddress, 'callValueRefundAddress').toBe( callValueRefundAddress ) - expect(parsed.data, 'data').to.eq(data) - expect(parsed.deposit.toString(), 'deposit').to.eq(value.toString()) - expect(parsed.excessFeeRefundAddress, 'excessFeeRefundAddress').to.eq( + expect(parsed.data, 'data').toBe(data) + expect(parsed.deposit.toString(), 'deposit').toBe(value.toString()) + expect(parsed.excessFeeRefundAddress, 'excessFeeRefundAddress').toBe( excessFeeRefundAddress ) - expect(parsed.from, 'from').to.eq(await parentSigner.getAddress()) - expect(parsed.gasLimit.toString(), 'gasLimit').to.eq(gasLimit.toString()) - expect(parsed.l2CallValue.toString(), 'l2CallValue').to.eq( + expect(parsed.from, 'from').toBe(await parentSigner.getAddress()) + expect(parsed.gasLimit.toString(), 'gasLimit').toBe(gasLimit.toString()) + expect(parsed.l2CallValue.toString(), 'l2CallValue').toBe( l2CallValue.toString() ) - expect(parsed.maxFeePerGas.toString(), 'maxFeePerGas').to.eq( + expect(parsed.maxFeePerGas.toString(), 'maxFeePerGas').toBe( maxFeePerGas.toString() ) - expect(parsed.maxSubmissionCost.toString(), 'maxSubmissionCost').to.eq( + expect(parsed.maxSubmissionCost.toString(), 'maxSubmissionCost').toBe( maxSubmissionCost.toString() ) - expect(parsed.to, 'to').to.eq(to) + expect(parsed.to, 'to').toBe(to) } } @@ -219,39 +219,39 @@ describe('RevertData', () => { parentSigner, childProvider: childSigner.provider!, }) - assert.fail('Expected estimateGas to fail') + expect.fail('Expected estimateGas to fail') } catch (err) { const typedErr = err as Error const parsed = RetryableDataTools.tryParseError(typedErr) if (!parsed) throw err - expect(parsed.callValueRefundAddress, 'callValueRefundAddress').to.eq( + expect(parsed.callValueRefundAddress, 'callValueRefundAddress').toBe( depositParams.retryableData.callValueRefundAddress ) - expect(parsed.data, 'data').to.eq(depositParams.retryableData.data) - expect(parsed.deposit.toString(), 'deposit').to.eq( + expect(parsed.data, 'data').toBe(depositParams.retryableData.data) + expect(parsed.deposit.toString(), 'deposit').toBe( isArbitrumNetworkWithCustomFeeToken() ? depositParams.retryableData.deposit.toString() : depositParams.txRequest.value.toString() ) - expect(parsed.excessFeeRefundAddress, 'excessFeeRefundAddress').to.eq( + expect(parsed.excessFeeRefundAddress, 'excessFeeRefundAddress').toBe( depositParams.retryableData.excessFeeRefundAddress ) - expect(parsed.from, 'from').to.eq(depositParams.retryableData.from) - expect(parsed.gasLimit.toString(), 'gasLimit').to.eq( + expect(parsed.from, 'from').toBe(depositParams.retryableData.from) + expect(parsed.gasLimit.toString(), 'gasLimit').toBe( depositParams.retryableData.gasLimit.toString() ) - expect(parsed.l2CallValue.toString(), 'l2CallValue').to.eq( + expect(parsed.l2CallValue.toString(), 'l2CallValue').toBe( depositParams.retryableData.l2CallValue.toString() ) - expect(parsed.maxFeePerGas.toString(), 'maxFeePerGas').to.eq( + expect(parsed.maxFeePerGas.toString(), 'maxFeePerGas').toBe( depositParams.retryableData.maxFeePerGas.toString() ) - expect(parsed.maxSubmissionCost.toString(), 'maxSubmissionCost').to.eq( + expect(parsed.maxSubmissionCost.toString(), 'maxSubmissionCost').toBe( depositParams.retryableData.maxSubmissionCost.toString() ) - expect(parsed.to).to.eq(depositParams.retryableData.to) + expect(parsed.to).toBe(depositParams.retryableData.to) } }) }) diff --git a/packages/sdk/tests/integration/sanity.test.ts b/packages/sdk/tests/integration/sanity.test.ts index df08e5c15d..898c2519b5 100644 --- a/packages/sdk/tests/integration/sanity.test.ts +++ b/packages/sdk/tests/integration/sanity.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { AeWETH__factory } from '../../src/lib/abi/factories/AeWETH__factory' import { L2GatewayRouter__factory } from '../../src/lib/abi/factories/L2GatewayRouter__factory' @@ -32,7 +32,7 @@ import { randomBytes, hexlify } from 'ethers/lib/utils' import { itOnlyWhenEth } from './custom-fee-token/mochaExtensions' const expectIgnoreCase = (expected: string, actual: string) => { - expect(expected.toLocaleLowerCase()).to.equal(actual.toLocaleLowerCase()) + expect(expected.toLocaleLowerCase()).toBe(actual.toLocaleLowerCase()) } describe('sanity checks (read-only)', async () => { @@ -49,27 +49,25 @@ describe('sanity checks (read-only)', async () => { const l1ClonableProxyHash = await l1Gateway.cloneableProxyHash() const l2ClonableProxyHash = await l2Gateway.cloneableProxyHash() - expect(l1ClonableProxyHash).to.equal(l2ClonableProxyHash) + expect(l1ClonableProxyHash).toBe(l2ClonableProxyHash) const l1BeaconProxyHash = await l1Gateway.l2BeaconProxyFactory() const l2BeaconProxyHash = await l2Gateway.beaconProxyFactory() - expect(l1BeaconProxyHash).to.equal(l2BeaconProxyHash) + expect(l1BeaconProxyHash).toBe(l2BeaconProxyHash) const l1GatewayCounterParty = await l1Gateway.counterpartGateway() - expect(l1GatewayCounterParty).to.equal( - childChain.tokenBridge.childErc20Gateway - ) + expect(l1GatewayCounterParty).toBe(childChain.tokenBridge.childErc20Gateway) const l2GatewayCounterParty = await l2Gateway.counterpartGateway() - expect(l2GatewayCounterParty).to.equal( + expect(l2GatewayCounterParty).toBe( childChain.tokenBridge.parentErc20Gateway ) const l1Router = await l1Gateway.router() - expect(l1Router).to.equal(childChain.tokenBridge.parentGatewayRouter) + expect(l1Router).toBe(childChain.tokenBridge.parentGatewayRouter) const l2Router = await l2Gateway.router() - expect(l2Router).to.equal(childChain.tokenBridge.childGatewayRouter) + expect(l2Router).toBe(childChain.tokenBridge.childGatewayRouter) }) it('custom gateways public storage vars properly set', async () => { @@ -83,20 +81,20 @@ describe('sanity checks (read-only)', async () => { childSigner ) const l1GatewayCounterParty = await l1Gateway.counterpartGateway() - expect(l1GatewayCounterParty).to.equal( + expect(l1GatewayCounterParty).toBe( childChain.tokenBridge.childCustomGateway ) const l2GatewayCounterParty = await l2Gateway.counterpartGateway() - expect(l2GatewayCounterParty).to.equal( + expect(l2GatewayCounterParty).toBe( childChain.tokenBridge.parentCustomGateway ) const l1Router = await l1Gateway.router() - expect(l1Router).to.equal(childChain.tokenBridge.parentGatewayRouter) + expect(l1Router).toBe(childChain.tokenBridge.parentGatewayRouter) const l2Router = await l2Gateway.router() - expect(l2Router).to.equal(childChain.tokenBridge.childGatewayRouter) + expect(l2Router).toBe(childChain.tokenBridge.childGatewayRouter) }) itOnlyWhenEth( @@ -162,7 +160,7 @@ describe('sanity checks (read-only)', async () => { parentSigner.provider! ) - expect(gateway).to.equal(childChain.tokenBridge.parentWethGateway) + expect(gateway).toBe(childChain.tokenBridge.parentWethGateway) }) it('parent and child chain implementations of calculateL2ERC20Address match', async () => { @@ -180,6 +178,6 @@ describe('sanity checks (read-only)', async () => { const erc20ChildAddressAsPerChild = await childGatewayRouter.calculateL2TokenAddress(address) - expect(erc20ChildAddressAsPerChild).to.equal(erc20ChildAddressAsPerParent) + expect(erc20ChildAddressAsPerChild).toBe(erc20ChildAddressAsPerParent) }) }) diff --git a/packages/sdk/tests/integration/sendChildmsg.test.ts b/packages/sdk/tests/integration/sendChildmsg.test.ts index 7504bd62f3..6be824481b 100644 --- a/packages/sdk/tests/integration/sendChildmsg.test.ts +++ b/packages/sdk/tests/integration/sendChildmsg.test.ts @@ -25,7 +25,7 @@ import { } from '../../src/lib/dataEntities/networks' import { testSetup } from '../testSetup' import { greeter } from './helper/greeter' -import { expect } from 'chai' +import { describe, it, beforeAll, expect } from 'vitest' import { AdminErc20Bridger } from '../../src/lib/assetBridger/erc20Bridger' const sendSignedTx = async (testState: any, info?: any) => { @@ -54,7 +54,7 @@ describe('Send signedTx to child chain using inbox', async () => { childChain: ArbitrumNetwork } - before('init', async () => { + beforeAll(async () => { testState = await testSetup() }) @@ -74,21 +74,21 @@ describe('Send signedTx to child chain using inbox', async () => { contractCreationData ) const parentStatus = parentTransactionReceipt?.status - expect(parentStatus).to.equal(1, 'parent txn failed') + expect(parentStatus, 'parent txn failed').toBe(1) const childTx = ethers.utils.parseTransaction(signedMsg) const childTxhash = childTx.hash! const childTxReceipt = await childDeployer.provider!.waitForTransaction( childTxhash ) const childStatus = childTxReceipt.status - expect(childStatus).to.equal(1, 'child txn failed') + expect(childStatus, 'child txn failed').toBe(1) const contractAddress = ethers.ContractFactory.getContractAddress({ from: childTx.from!, nonce: childTx.nonce, }) const greeterImp = Greeter.attach(contractAddress) const greetResult = await greeterImp.greet() - expect(greetResult).to.equal('hello world', 'contract returns not expected') + expect(greetResult, 'contract returns not expected').toBe('hello world') }) it('should confirm the same tx on child chain', async () => { @@ -100,13 +100,13 @@ describe('Send signedTx to child chain using inbox', async () => { const { signedMsg, parentTransactionReceipt: parentTransactionReceipt } = await sendSignedTx(testState, info) const parentStatus = parentTransactionReceipt?.status - expect(parentStatus).to.equal(1) + expect(parentStatus).toBe(1) const childTxhash = ethers.utils.parseTransaction(signedMsg).hash! const childTxReceipt = await childDeployer.provider!.waitForTransaction( childTxhash ) const childStatus = childTxReceipt.status - expect(childStatus).to.equal(1) + expect(childStatus).toBe(1) }) it('send two tx share the same nonce but with different gas price, should confirm the one which gas price higher than child base price', async () => { @@ -122,7 +122,7 @@ describe('Send signedTx to child chain using inbox', async () => { } const lowFeeTx = await sendSignedTx(testState, lowFeeInfo) const lowFeeParentStatus = lowFeeTx.parentTransactionReceipt?.status - expect(lowFeeParentStatus).to.equal(1) + expect(lowFeeParentStatus).toBe(1) const info = { data: '0x12', to: await childDeployer.getAddress(), @@ -130,7 +130,7 @@ describe('Send signedTx to child chain using inbox', async () => { } const enoughFeeTx = await sendSignedTx(testState, info) const enoughFeeParentStatus = enoughFeeTx.parentTransactionReceipt?.status - expect(enoughFeeParentStatus).to.equal(1) + expect(enoughFeeParentStatus).toBe(1) const childLowFeeTxhash = ethers.utils.parseTransaction(lowFeeTx.signedMsg) .hash! const childEnoughFeeTxhash = ethers.utils.parseTransaction( @@ -140,10 +140,10 @@ describe('Send signedTx to child chain using inbox', async () => { const childTEnoughFeeReceipt = await childDeployer.provider!.waitForTransaction(childEnoughFeeTxhash) const childStatus = childTEnoughFeeReceipt.status - expect(childStatus).to.equal(1) + expect(childStatus).toBe(1) const res = await childDeployer.provider?.getTransactionReceipt( childLowFeeTxhash ) - expect(res).to.be.null + expect(res).toBeNull() }) }) diff --git a/packages/sdk/tests/integration/standarderc20.test.ts b/packages/sdk/tests/integration/standarderc20.test.ts index 67d85f0d82..f65cc6fb17 100644 --- a/packages/sdk/tests/integration/standarderc20.test.ts +++ b/packages/sdk/tests/integration/standarderc20.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect, beforeAll, beforeEach } from 'vitest' import { Wallet, utils, constants } from 'ethers' import { BigNumber } from '@ethersproject/bignumber' import { TestERC20__factory } from '../../src/lib/abi/factories/TestERC20__factory' @@ -54,7 +54,7 @@ const depositAmount = BigNumber.from(100) const withdrawalAmount = BigNumber.from(10) describe('standard ERC20', () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -63,7 +63,7 @@ describe('standard ERC20', () => { parentToken: TestERC20 } - before('init', async () => { + beforeAll(async () => { const setup = await testSetup() await fundParentSigner(setup.parentSigner) await fundChildSigner(setup.childSigner) @@ -91,10 +91,10 @@ describe('standard ERC20', () => { gatewayAddress ) - expect(initialAllowance.toString()).to.eq( - constants.Zero.toString(), + expect( + initialAllowance.toString(), 'initial allowance is not empty' - ) + ).toBe(constants.Zero.toString()) const tx = await erc20Bridger.approveGasToken({ parentSigner, @@ -107,9 +107,8 @@ describe('standard ERC20', () => { gatewayAddress ) - expect(finalAllowance.toString()).to.eq( - constants.MaxUint256.toString(), - 'initial allowance is not empty' + expect(finalAllowance.toString(), 'initial allowance is not empty').toBe( + constants.MaxUint256.toString() ) } ) @@ -143,12 +142,12 @@ describe('standard ERC20', () => { const redeemRec = await manualRedeem.wait() const blockHash = redeemRec.blockHash - expect(retryRec.blockHash, 'redeemed in same block').to.eq(blockHash) - expect(retryRec.to, 'redeemed in same block').to.eq( + expect(retryRec.blockHash, 'redeemed in same block').toBe(blockHash) + expect(retryRec.to, 'redeemed in same block').toBe( testState.childChain.tokenBridge.childErc20Gateway ) - expect(retryRec.status, 'tx didnt fail').to.eq(expectedStatus) - expect(await message.status(), 'message status').to.eq( + expect(retryRec.status, 'tx didnt fail').toBe(expectedStatus) + expect(await message.status(), 'message status').toBe( expectedStatus === 0 ? ParentToChildMessageStatus.FUNDS_DEPOSITED_ON_CHILD : ParentToChildMessageStatus.REDEEMED @@ -214,12 +213,12 @@ describe('standard ERC20', () => { throw new Error('Missing retryable creation.') const l2Receipt = new ChildTransactionReceipt(retryableCreation) const redeemsScheduled = l2Receipt.getRedeemScheduledEvents() - expect(redeemsScheduled.length, 'Unexpected redeem length').to.eq(1) + expect(redeemsScheduled.length, 'Unexpected redeem length').toBe(1) const retryReceipt = await testState.childSigner.provider!.getTransactionReceipt( redeemsScheduled[0].retryTxHash ) - expect(isDefined(retryReceipt), 'Retry should not exist').to.be.false + expect(isDefined(retryReceipt), 'Retry should not exist').toBe(false) // manual redeem succeeds await redeemAndTest(waitRes.message, 1) @@ -275,7 +274,7 @@ describe('standard ERC20', () => { const l2BalanceStart = await l2Token.balanceOf( await testState.childSigner.getAddress() ) - expect(l2BalanceStart.toString(), 'l2 balance start').to.eq( + expect(l2BalanceStart.toString(), 'l2 balance start').toBe( l2BalanceStart.toString() ) diff --git a/packages/sdk/tests/integration/testHelpers.ts b/packages/sdk/tests/integration/testHelpers.ts index 124b850ddd..34b3069257 100644 --- a/packages/sdk/tests/integration/testHelpers.ts +++ b/packages/sdk/tests/integration/testHelpers.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { expect } from 'vitest' import chalk from 'chalk' import { BigNumber } from '@ethersproject/bignumber' @@ -104,15 +104,15 @@ export const withdrawToken = async (params: WithdrawalParams) => { childSigner: params.childSigner, }) const withdrawRec = await withdrawRes.wait() - expect(withdrawRec.status).to.equal(1, 'initiate token withdraw txn failed') + expect(withdrawRec.status, 'initiate token withdraw txn failed').toBe(1) const message = ( await withdrawRec.getChildToParentMessages(params.parentSigner) )[0] - expect(message, 'withdraw message not found').to.exist + expect(message, 'withdraw message not found').toBeTruthy() const messageStatus = await message.status(params.childSigner.provider!) - expect(messageStatus, `invalid withdraw status`).to.eq( + expect(messageStatus, `invalid withdraw status`).toBe( ChildToParentMessageStatus.UNCONFIRMED ) @@ -130,7 +130,7 @@ export const withdrawToken = async (params: WithdrawalParams) => { expect( testWalletChildBalance.toNumber(), 'token withdraw balance not deducted' - ).to.eq(params.startBalance.sub(params.amount).toNumber()) + ).toBe(params.startBalance.sub(params.amount).toNumber()) const walletAddress = await params.parentSigner.getAddress() const gatewayAddress = await params.erc20Bridger.getChildGatewayAddress( @@ -142,7 +142,7 @@ export const withdrawToken = async (params: WithdrawalParams) => { params.gatewayType, params.erc20Bridger.childNetwork ) - expect(gatewayAddress, 'Gateway is not custom gateway').to.eq( + expect(gatewayAddress, 'Gateway is not custom gateway').toBe( expectedL2Gateway ) @@ -153,7 +153,7 @@ export const withdrawToken = async (params: WithdrawalParams) => { params.parentToken.address, walletAddress ) - expect(gatewayWithdrawEvents.length).to.equal(1, 'token query failed') + expect(gatewayWithdrawEvents.length, 'token query failed').toBe(1) const balBefore = await params.parentToken.balanceOf( await params.parentSigner.getAddress() @@ -175,7 +175,7 @@ export const withdrawToken = async (params: WithdrawalParams) => { expect( await message.status(params.childSigner.provider!), 'confirmed status' - ).to.eq(ChildToParentMessageStatus.CONFIRMED) + ).toBe(ChildToParentMessageStatus.CONFIRMED) const execTx = await message.execute(params.childSigner.provider!) const execRec = await execTx.wait() @@ -183,17 +183,17 @@ export const withdrawToken = async (params: WithdrawalParams) => { expect( execRec.gasUsed.toNumber(), 'Gas used greater than estimate' - ).to.be.lessThan(parentGasEstimate.toNumber()) + ).toBeLessThan(parentGasEstimate.toNumber()) expect( await message.status(params.childSigner.provider!), 'executed status' - ).to.eq(ChildToParentMessageStatus.EXECUTED) + ).toBe(ChildToParentMessageStatus.EXECUTED) const balAfter = await params.parentToken.balanceOf( await params.parentSigner.getAddress() ) - expect(balBefore.add(params.amount).toString(), 'Not withdrawn').to.eq( + expect(balBefore.add(params.amount).toString(), 'Not withdrawn').toBe( balAfter.toString() ) } @@ -276,8 +276,10 @@ export const depositToken = async ({ senderAddress, expectedParentGatewayAddress ) - expect(allowance.eq(Erc20Bridger.MAX_APPROVAL), 'set token allowance failed') - .to.be.true + expect( + allowance.eq(Erc20Bridger.MAX_APPROVAL), + 'set token allowance failed' + ).toBe(true) if (isArbitrumNetworkWithCustomFeeToken()) { await ( @@ -295,7 +297,7 @@ export const depositToken = async ({ expect( feeTokenAllowance.eq(Erc20Bridger.MAX_APPROVAL), 'set fee token allowance failed' - ).to.be.true + ).toBe(true) feeTokenBalanceBefore = await ERC20__factory.connect( erc20Bridger.nativeToken!, @@ -329,14 +331,14 @@ export const depositToken = async ({ expect( finalBridgeTokenBalance.toNumber(), 'bridge balance not updated after L1 token deposit txn' - ).to.eq( + ).toBe( // for weth the eth is actually withdrawn, rather than transferred expectedGatewayType === GatewayType.WETH ? 0 : initialBridgeTokenBalance.add(depositAmount).toNumber() ) const parentTokenBalanceAfter = await parentToken.balanceOf(senderAddress) - expect(parentTokenBalanceAfter.toString(), 'user bal after').to.eq( + expect(parentTokenBalanceAfter.toString(), 'user bal after').toBe( parentTokenBalanceBefore.sub(depositAmount).toString() ) @@ -365,7 +367,7 @@ export const depositToken = async ({ .sub(feeTokenBalanceAfter) .lte(maxScaledEstimatedGasFee), 'Too much custom fee token used as gas' - ).to.be.true + ).toBe(true) } const waitRes = await depositRec.waitForChildTransactionReceipt(childSigner) @@ -374,7 +376,7 @@ export const depositToken = async ({ destinationAddress || senderAddress ) - expect(waitRes.status, 'Unexpected status').to.eq(expectedStatus) + expect(waitRes.status, 'Unexpected status').toBe(expectedStatus) if (retryableOverrides) { return { parentToken, @@ -391,7 +393,7 @@ export const depositToken = async ({ parentTokenAddress, parentSigner.provider! ) - expect(parentGateway, 'incorrect parent chain gateway address').to.eq( + expect(parentGateway, 'incorrect parent chain gateway address').toBe( expectedL1Gateway ) @@ -399,7 +401,7 @@ export const depositToken = async ({ parentTokenAddress, childSigner.provider! ) - expect(childGateway, 'incorrect child chain gateway address').to.eq( + expect(childGateway, 'incorrect child chain gateway address').toBe( expectedL2Gateway ) @@ -415,10 +417,10 @@ export const depositToken = async ({ childErc20Addr, childSigner.provider! ) - expect(parentErc20Addr).to.equal( - parentTokenAddress, + expect( + parentErc20Addr, 'getERC20L1Address/getERC20L2Address failed with proper token address' - ) + ).toBe(parentTokenAddress) const tokenBalOnChildAfter = await childToken.balanceOf( destinationAddress || senderAddress @@ -429,7 +431,7 @@ export const depositToken = async ({ expect( tokenBalOnChildAfter.eq(depositAmount), 'child wallet not updated after deposit' - ).to.be.true + ).toBe(true) } // batched token+eth @@ -437,7 +439,7 @@ export const depositToken = async ({ expect( childEthBalanceAfter.gte(childEthBalanceBefore.add(ethDepositAmount)), 'child wallet not updated with the extra eth deposit' - ).to.be.true + ).toBe(true) } return { parentToken, waitRes, childToken } diff --git a/packages/sdk/tests/integration/weth.test.ts b/packages/sdk/tests/integration/weth.test.ts index d79543b49a..57689a010c 100644 --- a/packages/sdk/tests/integration/weth.test.ts +++ b/packages/sdk/tests/integration/weth.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { it, beforeEach, expect } from 'vitest' import { parseEther } from '@ethersproject/units' import { AeWETH__factory } from '../../src/lib/abi/factories/AeWETH__factory' import { @@ -34,7 +34,7 @@ import { ERC20__factory } from '../../src/lib/abi/factories/ERC20__factory' import { describeOnlyWhenEth } from './custom-fee-token/mochaExtensions' describeOnlyWhenEth('WETH', async () => { - beforeEach('skipIfMainnet', async function () { + beforeEach(async function () { await skipIfMainnet(this) }) @@ -56,7 +56,7 @@ describeOnlyWhenEth('WETH', async () => { expect( (await childWETH.balanceOf(await childSigner.getAddress())).toString(), 'start balance weth' - ).to.eq('0') + ).toBe('0') const parentWETH = AeWETH__factory.connect(parentWethAddress, parentSigner) const res = await parentWETH.deposit({ @@ -77,14 +77,14 @@ describeOnlyWhenEth('WETH', async () => { parentWethAddress, childSigner.provider! ) - expect(childWethGateway, 'child weth gateway').to.eq( + expect(childWethGateway, 'child weth gateway').toBe( childChain.tokenBridge.childWethGateway ) const childToken = erc20Bridger.getChildTokenContract( childSigner.provider!, childChain.tokenBridge.childWeth ) - expect(childToken.address, 'child weth').to.eq( + expect(childToken.address, 'child weth').toBe( childChain.tokenBridge.childWeth ) @@ -97,7 +97,7 @@ describeOnlyWhenEth('WETH', async () => { ).wait() const afterBalance = await childSigner.provider!.getBalance(randomAddr) - expect(afterBalance.toString(), 'balance after').to.eq( + expect(afterBalance.toString(), 'balance after').toBe( wethToDeposit.toString() ) }) @@ -119,7 +119,7 @@ describeOnlyWhenEth('WETH', async () => { value: wethToWrap, }) const rec = await res.wait() - expect(rec.status).to.equal(1, 'deposit txn failed') + expect(rec.status, 'deposit txn failed').toBe(1) await withdrawToken({ amount: wethToWithdraw, diff --git a/packages/sdk/tests/unit/addressAlias.test.ts b/packages/sdk/tests/unit/addressAlias.test.ts index 674e42a5f3..650a4243c2 100644 --- a/packages/sdk/tests/unit/addressAlias.test.ts +++ b/packages/sdk/tests/unit/addressAlias.test.ts @@ -16,7 +16,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { Address } from '../../src/lib/dataEntities/address' import { BigNumber } from 'ethers' @@ -35,16 +35,16 @@ describe('Address', () => { const address = new Address(addr) const afterApply = address.applyAlias() - expect(afterApply.value, 'invalid apply alias').to.eq(expectedApply) + expect(afterApply.value, 'invalid apply alias').toBe(expectedApply) const afterApplyUndo = afterApply.undoAlias() - expect(afterApplyUndo.value, 'invalid undo after apply alias').to.eq(addr) + expect(afterApplyUndo.value, 'invalid undo after apply alias').toBe(addr) const afterUndo = address.undoAlias() - expect(afterUndo.value, 'invalid undo alias').to.eq(expectedUndo) + expect(afterUndo.value, 'invalid undo alias').toBe(expectedUndo) const afterUndoApply = afterUndo.applyAlias() - expect(afterUndoApply.value, 'invalid apply after undo alias').to.eq(addr) + expect(afterUndoApply.value, 'invalid apply after undo alias').toBe(addr) } it('does alias correctly below offset', async () => { diff --git a/packages/sdk/tests/unit/calldata.test.ts b/packages/sdk/tests/unit/calldata.test.ts index a1897ddb5c..eed65b002f 100644 --- a/packages/sdk/tests/unit/calldata.test.ts +++ b/packages/sdk/tests/unit/calldata.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { getErc20ParentAddressFromParentToChildTxRequest } from '../../src/lib/utils/calldata' import { ParentToChildTxReqAndSigner } from '../../src/lib/assetBridger/ethBridger' @@ -11,7 +11,7 @@ describe('Calldata', () => { const output = getErc20ParentAddressFromParentToChildTxRequest({ txRequest: { data: calldata }, } as ParentToChildTxReqAndSigner) - expect(output).to.eq(expectedAddress) + expect(output).toBe(expectedAddress) }) it('decodes calldata to get token address from `outboundTransferCustomRefund` method call on gateway router', async () => { @@ -21,44 +21,31 @@ describe('Calldata', () => { const output = getErc20ParentAddressFromParentToChildTxRequest({ txRequest: { data: calldata }, } as ParentToChildTxReqAndSigner) - expect(output).to.eq(expectedAddress) + expect(output).toBe(expectedAddress) }) it('throws when handling bad calldata', async () => { - try { - const calldata = '0xInvalidCalldata' + expect(() => getErc20ParentAddressFromParentToChildTxRequest({ - txRequest: { data: calldata }, + txRequest: { data: '0xInvalidCalldata' }, } as ParentToChildTxReqAndSigner) - } catch (err: any) { - expect(err.message).to.eq( - 'data signature not matching deposits methods' - ) - } + ).toThrow('data signature not matching deposits methods') }) it('throws when handling an empty string', async () => { - try { + expect(() => getErc20ParentAddressFromParentToChildTxRequest({ txRequest: { data: '' }, } as ParentToChildTxReqAndSigner) - } catch (err: any) { - expect(err.message).to.eq( - 'data signature not matching deposits methods' - ) - } + ).toThrow('data signature not matching deposits methods') }) it('throws when handling `undefined` data ', async () => { - try { + expect(() => getErc20ParentAddressFromParentToChildTxRequest({ txRequest: { data: undefined }, } as any as ParentToChildTxReqAndSigner) - } catch (err: any) { - expect(err.message).to.eq( - 'data signature not matching deposits methods' - ) - } + ).toThrow('data signature not matching deposits methods') }) }) }) diff --git a/packages/sdk/tests/unit/childBlocksForL1Block.test.ts b/packages/sdk/tests/unit/childBlocksForL1Block.test.ts index f1004636c6..1d97ba609b 100644 --- a/packages/sdk/tests/unit/childBlocksForL1Block.test.ts +++ b/packages/sdk/tests/unit/childBlocksForL1Block.test.ts @@ -1,5 +1,5 @@ import { BigNumber } from 'ethers' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { JsonRpcProvider } from '@ethersproject/providers' import { getBlockRangesForL1Block, @@ -59,7 +59,7 @@ describe('Child blocks lookup for a Parent block', () => { expect( startBlockCondition, `Child block is not the first block in range for parent block.` - ).to.be.true + ).toBe(true) } if (endBlock && blockAfterEndBlock) { @@ -69,7 +69,7 @@ describe('Child blocks lookup for a Parent block', () => { expect( endBlockCondition, `Child block is not the last block in range for parent block.` - ).to.be.true + ).toBe(true) } } diff --git a/packages/sdk/tests/unit/childToParentMessageEvents.test.ts b/packages/sdk/tests/unit/childToParentMessageEvents.test.ts index 0e5d3f7316..5ae4c29690 100644 --- a/packages/sdk/tests/unit/childToParentMessageEvents.test.ts +++ b/packages/sdk/tests/unit/childToParentMessageEvents.test.ts @@ -16,6 +16,7 @@ /* eslint-env node */ 'use strict' +import { describe, it } from 'vitest' import { Logger, LogLevel } from '@ethersproject/logger' Logger.setLogLevel(LogLevel.ERROR) import { ChildToParentMessage } from '../../src/lib/message/ChildToParentMessage' diff --git a/packages/sdk/tests/unit/messageDataParser.test.ts b/packages/sdk/tests/unit/messageDataParser.test.ts index e6b359f59c..8867917c6b 100644 --- a/packages/sdk/tests/unit/messageDataParser.test.ts +++ b/packages/sdk/tests/unit/messageDataParser.test.ts @@ -1,7 +1,7 @@ /* eslint-env node */ 'use strict' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { BigNumber } from 'ethers' import { parseEther } from 'ethers/lib/utils' @@ -16,32 +16,36 @@ describe('SubmitRetryableMessageDataParser', () => { const res = messageDataParser.parse(retryableData) - expect(res.callValueRefundAddress).to.eq( + expect(res.callValueRefundAddress).toBe( '0x7F869dC59A96e798e759030b3c39398ba584F087' ) - expect(res.data).to.eq( + expect(res.data).toBe( '0x2E567B360000000000000000000000006B175474E89094C44DA98B954EEDEAC495271D0F0000000000000000000000007F869DC59A96E798E759030B3C39398BA584F0870000000000000000000000007F869DC59A96E798E759030B3C39398BA584F08700000000000000000000000000000000000000000000003871022F1082344C7700000000000000000000000000000000000000000000000000000000000000A000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ) - expect(res.destAddress).to.eq('0x467194771dAe2967Aef3ECbEDD3Bf9a310C76C65') - expect(res.excessFeeRefundAddress).to.eq( + expect(res.destAddress).toBe('0x467194771dAe2967Aef3ECbEDD3Bf9a310C76C65') + expect(res.excessFeeRefundAddress).toBe( '0x7F869dC59A96e798e759030b3c39398ba584F087' ) - expect(res.gasLimit.eq(BigNumber.from('0x0210f1')), 'incorrect gas limit') - .to.be.true + expect( + res.gasLimit.eq(BigNumber.from('0x0210f1')), + 'incorrect gas limit' + ).toBe(true) expect( res.l1Value.eq(BigNumber.from('0x30346f1c785e')), 'incorrect l1 value' - ).to.be.true - expect(res.l2CallValue.eq(BigNumber.from(0)), 'incorrect l2 call value').to - .be.true + ).toBe(true) + expect( + res.l2CallValue.eq(BigNumber.from(0)), + 'incorrect l2 call value' + ).toBe(true) expect( res.maxFeePerGas.eq(BigNumber.from('0x172c5865')), 'incorrect max fee per gas' - ).to.be.true + ).toBe(true) expect( res.maxSubmissionFee.eq(BigNumber.from('0x53280cf149')), 'incorrect max submission fee' - ).to.be.true + ).toBe(true) }) // left a separate test here for eth deposits done via a retryable @@ -55,23 +59,27 @@ describe('SubmitRetryableMessageDataParser', () => { const res = messageDataParser.parse(retryableData) - expect(res.callValueRefundAddress).to.eq( + expect(res.callValueRefundAddress).toBe( '0xf71946496600e1e1d47b8A77EB2f109Fd82dc86a' ) - expect(res.data).to.eq('0x') - expect(res.destAddress).to.eq('0xf71946496600e1e1d47b8A77EB2f109Fd82dc86a') - expect(res.excessFeeRefundAddress).to.eq( + expect(res.data).toBe('0x') + expect(res.destAddress).toBe('0xf71946496600e1e1d47b8A77EB2f109Fd82dc86a') + expect(res.excessFeeRefundAddress).toBe( '0xf71946496600e1e1d47b8A77EB2f109Fd82dc86a' ) - expect(res.gasLimit.eq(BigNumber.from(0)), 'incorrect gas limit').to.be.true - expect(res.l1Value.eq(parseEther('30.01')), 'incorrect l1 value').to.be.true - expect(res.l2CallValue.eq(BigNumber.from(0)), 'incorrect l2 call value').to - .be.true - expect(res.maxFeePerGas.eq(BigNumber.from(0)), 'incorrect max fee per gas') - .to.be.true + expect(res.gasLimit.eq(BigNumber.from(0)), 'incorrect gas limit').toBe(true) + expect(res.l1Value.eq(parseEther('30.01')), 'incorrect l1 value').toBe(true) + expect( + res.l2CallValue.eq(BigNumber.from(0)), + 'incorrect l2 call value' + ).toBe(true) + expect( + res.maxFeePerGas.eq(BigNumber.from(0)), + 'incorrect max fee per gas' + ).toBe(true) expect( res.maxSubmissionFee.eq(BigNumber.from('0x370e285a0c')), 'incorrect max submission fee' - ).to.be.true + ).toBe(true) }) }) diff --git a/packages/sdk/tests/unit/multicall.test.ts b/packages/sdk/tests/unit/multicall.test.ts index 04e30a3b3b..2581b5a3d4 100644 --- a/packages/sdk/tests/unit/multicall.test.ts +++ b/packages/sdk/tests/unit/multicall.test.ts @@ -1,12 +1,12 @@ 'use strict' +import { describe, it, expect } from 'vitest' import { getArbitrumNetwork, getNitroGenesisBlock, } from '../../src/lib/dataEntities/networks' import { providers } from 'ethers' import { mock, when, anything, instance, deepEqual } from 'ts-mockito' -import { expect } from 'chai' import { MultiCaller } from '../../src' @@ -74,12 +74,8 @@ describe('Multicall', () => { { symbol: true, name: true } ) - expect(data.name, 'Failed to get token name from bytes32').to.be.equal( - 'Maker' - ) - expect(data.symbol, 'Failed to get token symbol from bytes32').to.be.equal( - 'MKR' - ) + expect(data.name, 'Failed to get token name from bytes32').toBe('Maker') + expect(data.symbol, 'Failed to get token symbol from bytes32').toBe('MKR') }) it('returns parsed data from byte string', async function () { @@ -91,12 +87,11 @@ describe('Multicall', () => { { symbol: true, name: true } ) - expect(data.name, 'Failed to get token name from byte string').to.be.equal( + expect(data.name, 'Failed to get token name from byte string').toBe( 'Uniswap' ) - expect( - data.symbol, - 'Failed to get token symbol from byte string' - ).to.be.equal('UNI') + expect(data.symbol, 'Failed to get token symbol from byte string').toBe( + 'UNI' + ) }) }) diff --git a/packages/sdk/tests/unit/nativeToken.test.ts b/packages/sdk/tests/unit/nativeToken.test.ts index 281804c6bd..6742e261ef 100644 --- a/packages/sdk/tests/unit/nativeToken.test.ts +++ b/packages/sdk/tests/unit/nativeToken.test.ts @@ -1,6 +1,6 @@ 'use strict' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' import { BigNumber } from 'ethers' import { parseEther } from 'ethers/lib/utils' @@ -23,7 +23,7 @@ describe('Native token', () => { decimals: 18, }).eq(BigNumber.from('1234567890000000000')), decimalsToError(18) - ).to.be.true + ).toBe(true) // Rounds up the last digit - in this case no decimals so rounds up 1 to 2 expect( @@ -32,7 +32,7 @@ describe('Native token', () => { decimals: 0, }).eq(BigNumber.from('2')), decimalsToError(0) - ).to.be.true + ).toBe(true) // Rounds up the last digit expect( @@ -41,7 +41,7 @@ describe('Native token', () => { decimals: 1, }).eq(BigNumber.from('13')), decimalsToError(1) - ).to.be.true + ).toBe(true) // Rounds up the last digit expect( @@ -50,7 +50,7 @@ describe('Native token', () => { decimals: 6, }).eq(BigNumber.from('1234568')), decimalsToError(6) - ).to.be.true + ).toBe(true) // Rounds up the last digit expect( @@ -59,7 +59,7 @@ describe('Native token', () => { decimals: 7, }).eq(BigNumber.from('12345679')), decimalsToError(7) - ).to.be.true + ).toBe(true) // Does not round up the last digit because all original decimals are included expect( @@ -68,7 +68,7 @@ describe('Native token', () => { decimals: 8, }).eq(BigNumber.from('123456789')), decimalsToError(8) - ).to.be.true + ).toBe(true) // Does not round up the last digit because all original decimals are included expect( @@ -77,7 +77,7 @@ describe('Native token', () => { decimals: 9, }).eq(BigNumber.from('1234567890')), decimalsToError(9) - ).to.be.true + ).toBe(true) // Does not round up the last digit because all original decimals are included expect( @@ -86,7 +86,7 @@ describe('Native token', () => { decimals: 24, }).eq(BigNumber.from('1234567890000000000000000')), decimalsToError(24) - ).to.be.true + ).toBe(true) }) it('scales native token decimals to 18 decimals', () => { @@ -96,7 +96,7 @@ describe('Native token', () => { decimals: 16, }).eq(BigNumber.from('123456789000000000000')), decimalsToError(16) - ).to.be.true + ).toBe(true) expect( scaleFromNativeTokenDecimalsTo18Decimals({ @@ -104,7 +104,7 @@ describe('Native token', () => { decimals: 18, }).eq(BigNumber.from('1234567890000000000')), decimalsToError(18) - ).to.be.true + ).toBe(true) expect( scaleFromNativeTokenDecimalsTo18Decimals({ @@ -112,6 +112,6 @@ describe('Native token', () => { decimals: 20, }).eq(BigNumber.from('12345678900000000')), decimalsToError(20) - ).to.be.true + ).toBe(true) }) }) diff --git a/packages/sdk/tests/unit/network.test.ts b/packages/sdk/tests/unit/network.test.ts index d59bba0706..213ae2febf 100644 --- a/packages/sdk/tests/unit/network.test.ts +++ b/packages/sdk/tests/unit/network.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai' +import { describe, it, expect, beforeEach } from 'vitest' import { resetNetworksToDefault, registerCustomArbitrumNetwork, @@ -38,13 +38,13 @@ describe('Networks', async () => { registerCustomArbitrumNetwork(customArbitrumNetwork) - expect(await getArbitrumNetwork(mockL2ChainId)).to.be.ok + expect(await getArbitrumNetwork(mockL2ChainId)).toBeTruthy() // assert network has correct parent const arbitrumNetwork = await getArbitrumNetwork( customArbitrumNetwork.chainId ) - expect(arbitrumNetwork.parentChainId).to.equal(ethereumMainnetChainId) + expect(arbitrumNetwork.parentChainId).toBe(ethereumMainnetChainId) }) it('adds a custom L3 network', async function () { @@ -60,18 +60,18 @@ describe('Networks', async () => { registerCustomArbitrumNetwork(customArbitrumNetwork) - expect(await getArbitrumNetwork(mockL3ChainId)).to.be.ok + expect(await getArbitrumNetwork(mockL3ChainId)).toBeTruthy() // assert network has correct parent const l3Network = await getArbitrumNetwork(mockL3ChainId) - expect(l3Network.parentChainId).to.equal(arbitrumOneChainId) + expect(l3Network.parentChainId).toBe(arbitrumOneChainId) }) }) describe('fetching networks', () => { it('successfully fetches an Arbitrum network with `getArbitrumNetwork`', async function () { const network = await getArbitrumNetwork(arbitrumOneChainId) - expect(network.chainId).to.be.eq(arbitrumOneChainId) + expect(network.chainId).toBe(arbitrumOneChainId) }) it('fails to fetch a registered L1 network with `getArbitrumNetwork`', async function () { @@ -79,8 +79,8 @@ describe('Networks', async () => { await getArbitrumNetwork(ethereumMainnetChainId) } catch (err) { // should fail - expect(err).to.be.an('error') - expect((err as Error).message).to.be.eq( + expect(err).toBeInstanceOf(Error) + expect((err as Error).message).toBe( `Unrecognized network ${ethereumMainnetChainId}.` ) } @@ -100,9 +100,9 @@ describe('Networks', async () => { registerCustomArbitrumNetwork(customL3Network) const l3Network = await getArbitrumNetwork(mockL3ChainId) - expect(l3Network.chainId).to.be.eq(mockL3ChainId) + expect(l3Network.chainId).toBe(mockL3ChainId) // assert network has correct parent - expect(l3Network.parentChainId).to.equal(arbitrumOneChainId) + expect(l3Network.parentChainId).toBe(arbitrumOneChainId) }) it('fails to fetch an unrecognized L2/L3 network', async () => { @@ -111,10 +111,8 @@ describe('Networks', async () => { try { await getArbitrumNetwork(chainId) } catch (err) { - expect(err).to.be.instanceOf(Error) - expect((err as Error).message).to.be.eq( - `Unrecognized network ${chainId}.` - ) + expect(err).toBeInstanceOf(Error) + expect((err as Error).message).toBe(`Unrecognized network ${chainId}.`) } }) }) @@ -125,84 +123,85 @@ describe('Networks', async () => { const arbitrumNetworksIds = getArbitrumNetworks().map(n => n.chainId) const expected = [42161, 42170, 421614] - expect(arbitrumNetworksIds).to.have.length(expected.length) - expect(arbitrumNetworksIds).to.have.members(expected) + expect(arbitrumNetworksIds).toHaveLength(expected.length) + expect(arbitrumNetworksIds).toEqual(expect.arrayContaining(expected)) + expect(expected).toEqual(expect.arrayContaining(arbitrumNetworksIds)) }) }) describe('getChildrenForNetwork', () => { it('returns correct children for ethereum mainnet', () => { const children = getChildrenForNetwork(1).map(c => c.chainId) - expect(children).to.have.members([42161, 42170]) + expect(children).toEqual([42161, 42170]) }) it('returns correct children for arbitrum one', () => { const children = getChildrenForNetwork(42161).map(c => c.chainId) - expect(children).to.have.members([]) + expect(children).toEqual([]) }) it('returns correct children for arbitrum nova', () => { const children = getChildrenForNetwork(42170).map(c => c.chainId) - expect(children).to.have.members([]) + expect(children).toEqual([]) }) it('returns correct children for sepolia', () => { const children = getChildrenForNetwork(11155111).map(c => c.chainId) - expect(children).to.have.members([421614]) + expect(children).toEqual([421614]) }) it('returns correct children for arbitrum sepolia', () => { const children = getChildrenForNetwork(421614).map(c => c.chainId) - expect(children).to.have.members([]) + expect(children).toEqual([]) }) }) describe('isParentNetwork', () => { it('returns correct value for ethereum mainnet', () => { - expect(isParentNetwork(1)).to.equal(true) + expect(isParentNetwork(1)).toBe(true) }) it('returns correct value for arbitrum one', () => { - expect(isParentNetwork(42161)).to.equal(false) + expect(isParentNetwork(42161)).toBe(false) }) it('returns correct value for arbitrum nova', () => { - expect(isParentNetwork(42170)).to.equal(false) + expect(isParentNetwork(42170)).toBe(false) }) it('returns correct value for sepolia', () => { - expect(isParentNetwork(11155111)).to.equal(true) + expect(isParentNetwork(11155111)).toBe(true) }) it('returns correct value for arbitrum sepolia', () => { - expect(isParentNetwork(421614)).to.equal(false) + expect(isParentNetwork(421614)).toBe(false) }) }) describe('getMulticallAddress', () => { it('returns correct value for ethereum mainnet', async () => { const multicall = await getMulticallAddress(1) - expect(multicall).to.equal('0x5ba1e12693dc8f9c48aad8770482f4739beed696') + expect(multicall).toBe('0x5ba1e12693dc8f9c48aad8770482f4739beed696') }) it('returns correct value for arbitrum one', async () => { const multicall = await getMulticallAddress(42161) - expect(multicall).to.equal('0x842eC2c7D803033Edf55E478F461FC547Bc54EB2') + expect(multicall).toBe('0x842eC2c7D803033Edf55E478F461FC547Bc54EB2') }) it('returns correct value for arbitrum nova', async () => { const multicall = await getMulticallAddress(42170) - expect(multicall).to.equal('0x5e1eE626420A354BbC9a95FeA1BAd4492e3bcB86') + expect(multicall).toBe('0x5e1eE626420A354BbC9a95FeA1BAd4492e3bcB86') }) it('returns correct value for sepolia', async () => { const multicall = await getMulticallAddress(11155111) - expect(multicall).to.equal('0xded9AD2E65F3c4315745dD915Dbe0A4Df61b2320') + expect(multicall).toBe('0xded9AD2E65F3c4315745dD915Dbe0A4Df61b2320') }) it('returns correct value for arbitrum sepolia', async () => { const multicall = await getMulticallAddress(421614) - expect(multicall).to.equal('0xA115146782b7143fAdB3065D86eACB54c169d092') + expect(multicall).toBe('0xA115146782b7143fAdB3065D86eACB54c169d092') }) }) @@ -210,7 +209,7 @@ describe('Networks', async () => { it('returns ArbitrumNetwork for chain ID', () => { const network = getArbitrumNetwork(arbitrumOneChainId) // TypeScript should infer this as ArbitrumNetwork, not Promise - expect(network.chainId).to.equal(arbitrumOneChainId) + expect(network.chainId).toBe(arbitrumOneChainId) }) it('returns Promise for SignerOrProvider input', async () => { @@ -218,9 +217,9 @@ describe('Networks', async () => { getNetwork: async () => ({ chainId: arbitrumOneChainId }), } as unknown as SignerOrProvider) // TypeScript should infer this as Promise - expect(networkPromise).to.be.an.instanceOf(Promise) + expect(networkPromise).toBeInstanceOf(Promise) const network = await networkPromise - expect(network.chainId).to.equal(arbitrumOneChainId) + expect(network.chainId).toBe(arbitrumOneChainId) }) }) @@ -230,7 +229,7 @@ describe('Networks', async () => { isArbitrumNetworkNativeTokenEther({ nativeToken: undefined, } as ArbitrumNetwork) - ).to.equal(true) + ).toBe(true) }) it('returns `true` when `nativeToken` is zero address', () => { @@ -238,7 +237,7 @@ describe('Networks', async () => { isArbitrumNetworkNativeTokenEther({ nativeToken: constants.AddressZero, } as ArbitrumNetwork) - ).to.equal(true) + ).toBe(true) }) it('returns `false` when `nativeToken` is a valid address', () => { @@ -246,7 +245,7 @@ describe('Networks', async () => { isArbitrumNetworkNativeTokenEther({ nativeToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', } as ArbitrumNetwork) - ).to.equal(false) + ).toBe(false) }) }) }) diff --git a/packages/sdk/tests/unit/parentToChildMessageEvents.test.ts b/packages/sdk/tests/unit/parentToChildMessageEvents.test.ts index 3e53d14ad8..760efc1d4d 100644 --- a/packages/sdk/tests/unit/parentToChildMessageEvents.test.ts +++ b/packages/sdk/tests/unit/parentToChildMessageEvents.test.ts @@ -1,7 +1,7 @@ import { ParentTransactionReceipt } from './../../src/lib/message/ParentTransaction' import { BigNumber, constants, providers } from 'ethers' import { JsonRpcProvider } from '@ethersproject/providers' -import { expect } from 'chai' +import { describe, it, expect } from 'vitest' describe('ParentToChildMessage events', () => { it('does call for nitro events', async () => { @@ -160,8 +160,8 @@ describe('ParentToChildMessage events', () => { ) } catch (err) { // This call should throw an error - expect(err).to.be.an('error') - expect((err as Error).message).to.be.eq( + expect(err).toBeInstanceOf(Error) + expect((err as Error).message).toBe( "This method is only for classic transactions. Use 'getParentToChildMessages' for nitro transactions." ) } finally { @@ -169,7 +169,7 @@ describe('ParentToChildMessage events', () => { expect( txReceipt, 'Classic method was successful using a nitro transaction.' - ).to.be.undefined + ).toBeUndefined() } const isClassic = await parentTxnReceipt.isClassic(arbProvider) @@ -177,56 +177,57 @@ describe('ParentToChildMessage events', () => { await parentTxnReceipt.getParentToChildMessages(arbProvider) )[0] - expect(isClassic, 'incorrect tx type returned by isClassic call').to.be - .false - expect(msg.chainId, 'incorrect chain id').to.be.eq(42161) - expect(msg.sender, 'incorrect sender').to.be.eq( + expect(isClassic, 'incorrect tx type returned by isClassic call').toBe( + false + ) + expect(msg.chainId, 'incorrect chain id').toBe(42161) + expect(msg.sender, 'incorrect sender').toBe( '0xeA3123E9d9911199a6711321d1277285e6d4F3EC' ) expect( msg.messageNumber.eq(BigNumber.from('0x504c')), 'incorrect message number' - ).to.be.true + ).toBe(true) expect( msg.parentBaseFee.eq(BigNumber.from('0x05e0fc4c58')), 'incorrect parent chain base fee' - ).to.be.true + ).toBe(true) expect( msg.messageData.destAddress, 'incorrect dest address on messageData' - ).to.be.eq('0x6c411aD3E74De3E7Bd422b94A27770f5B86C623B') + ).toBe('0x6c411aD3E74De3E7Bd422b94A27770f5B86C623B') expect( msg.messageData.l2CallValue.eq(BigNumber.from('0x0853a0d2313c0000')), 'incorrect child chain call value on messageData' - ).to.be.true + ).toBe(true) expect( msg.messageData.l1Value.eq(BigNumber.from('0x0854e8ab1802ca80')), 'incorrect parent chain value on messageData' - ).to.be.true + ).toBe(true) expect( msg.messageData.maxSubmissionFee.eq(BigNumber.from('0x01270f6740d880')), 'incorrect max submission fee on messageData' - ).to.be.true + ).toBe(true) expect( msg.messageData.excessFeeRefundAddress, 'incorrect excess fee refund address' - ).to.be.eq('0xa2e06c19EE14255889f0Ec0cA37f6D0778D06754') + ).toBe('0xa2e06c19EE14255889f0Ec0cA37f6D0778D06754') expect( msg.messageData.callValueRefundAddress, 'incorrect call value refund address' - ).to.be.eq('0xa2e06c19EE14255889f0Ec0cA37f6D0778D06754') + ).toBe('0xa2e06c19EE14255889f0Ec0cA37f6D0778D06754') expect( msg.messageData.gasLimit.eq(BigNumber.from('0x01d566')), 'incorrect gas limit on messageData' - ).to.be.true + ).toBe(true) expect( msg.messageData.maxFeePerGas.eq(BigNumber.from('0x11e1a300')), 'incorrect max fee per gas on messageData' - ).to.be.true - expect(msg.messageData.data, 'incorrect data on messageData').to.be.eq( + ).toBe(true) + expect(msg.messageData.data, 'incorrect data on messageData').toBe( '0x2e567b36000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a2e06c19ee14255889f0ec0ca37f6d0778d06754000000000000000000000000a2e06c19ee14255889f0ec0ca37f6d0778d067540000000000000000000000000000000000000000000000000853a0d2313c000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ) - expect(msg.retryableCreationId, 'incorrect retryable creation id').to.be.eq( + expect(msg.retryableCreationId, 'incorrect retryable creation id').toBe( '0x8ba13904639c7444d8578cc582a230b8501c9f0f7903f5069d276fdd3a7dea44' ) }) @@ -298,8 +299,8 @@ describe('ParentToChildMessage events', () => { txReceipt = await parentTxnReceipt.getParentToChildMessages(arbProvider) } catch (err) { // This call should throw an error - expect(err).to.be.an('error') - expect((err as Error).message).to.be.eq( + expect(err).toBeInstanceOf(Error) + expect((err as Error).message).toBe( "This method is only for nitro transactions. Use 'getParentToChildMessagesClassic' for classic transactions." ) } finally { @@ -307,7 +308,7 @@ describe('ParentToChildMessage events', () => { expect( txReceipt, 'Nitro method was successful using a classic transaction.' - ).to.be.undefined + ).toBeUndefined() } const isClassic = await parentTxnReceipt.isClassic(arbProvider) @@ -316,19 +317,19 @@ describe('ParentToChildMessage events', () => { )[0] const status = await msg.status() - expect(isClassic, 'incorrect tx type returned by isClassic call').to.be.true - expect(status, 'invalid message status').to.be.eq(5) + expect(isClassic, 'incorrect tx type returned by isClassic call').toBe(true) + expect(status, 'invalid message status').toBe(5) expect( msg.messageNumber.eq(BigNumber.from('0x064371')), 'incorrect message number' - ).to.be.true - expect(msg.retryableCreationId, 'incorrect retryable creation id').to.be.eq( + ).toBe(true) + expect(msg.retryableCreationId, 'incorrect retryable creation id').toBe( '0xc88b1821af42b8281bbf645173e287e4ec50ef96907f5211dc7069e09af20720' ) - expect(msg.autoRedeemId, 'incorrect auto redeem id').to.be.eq( + expect(msg.autoRedeemId, 'incorrect auto redeem id').toBe( '0x38c5c31151344c7a1433a849bbc80472786ebe911630255a6e25d6a2efd39526' ) - expect(msg.childTxHash, 'incorrect child chain tx hash').to.be.eq( + expect(msg.childTxHash, 'incorrect child chain tx hash').toBe( '0xf91e7d2e7526927e915a2357360a3f1108dce0f9c7fa88a7492669adf5c1e53b' ) }) diff --git a/vitest.config.ts b/vitest.config.ts index f7e385ce79..ca0a20fc33 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,8 +4,11 @@ export default defineConfig({ test: { environment: 'node', globals: true, - include: ['**/tests/unit/**/*.test.ts', '**/tests/*.test.ts'], + include: ['**/tests/**/*.test.ts'], exclude: ['**/node_modules/**', '**/dist/**'], testTimeout: 30_000, + hookTimeout: 60_000, + passWithNoTests: true, + allowEmpty: true, }, })