Skip to content

Commit 29f4938

Browse files
committed
Add helpful error if anvil is not running when running integration-mocked test
1 parent 0e22577 commit 29f4938

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

packages/ccip-js/test/integration-mocked.test.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { jest, expect, it, describe, afterEach, beforeAll } from '@jest/globals'
22
import * as CCIP from '../src/api'
33
import * as Viem from 'viem'
44
import * as viemActions from 'viem/actions'
5-
import { parseEther, zeroAddress } from 'viem'
65

76
import { testClient } from './helpers/clients'
87
import { account, ccipLog, ccipTxHash, ccipTxReceipt, onRampAbi, routerAbi } from './helpers/constants'
@@ -27,6 +26,32 @@ describe('Integration- Using Mocks', () => {
2726
jest.clearAllMocks()
2827
})
2928

29+
beforeAll(async () => {
30+
// Create a temporary public client to check if Anvil is running
31+
const tempClient = Viem.createPublicClient({
32+
transport: Viem.http('http://127.0.0.1:8545'),
33+
})
34+
35+
// Try to get the chain ID and verify it's Anvil
36+
try {
37+
const chainId = await tempClient.getChainId()
38+
if (chainId.toString() !== '31337') {
39+
throw new Error(`Wrong chain ID ('${chainId}') detected on port 8545. Expected Anvil's '31337'`)
40+
}
41+
} catch (error) {
42+
if (error instanceof Error && error.message.includes('Wrong chain ID')) {
43+
throw error
44+
}
45+
46+
throw new Error(
47+
'❌ Anvil is not running on port 8545. Please start Anvil first:\n' +
48+
'1. Open a new terminal\n' +
49+
'2. Run: anvil --port 8545\n' +
50+
'3. Then run the tests again',
51+
)
52+
}
53+
})
54+
3055
describe('√ deploy on Anvil', () => {
3156
it('Should Deploy Router.sol', async function () {
3257
const { router } = await getContracts()
@@ -50,7 +75,7 @@ describe('Integration- Using Mocks', () => {
5075

5176
writeContractMock.mockResolvedValueOnce(ccipTxHash)
5277
waitForTransactionReceiptMock.mockResolvedValue(ccipTxReceipt)
53-
const approvedAmount = parseEther('10')
78+
const approvedAmount = Viem.parseEther('10')
5479

5580
// HH: Approval Transaction
5681
await bridgeToken.write.approve([
@@ -76,7 +101,7 @@ describe('Integration- Using Mocks', () => {
76101
// writeContractMock.mockResolvedValueOnce(ccipTxHash)
77102
// waitForTransactionReceiptMock.mockResolvedValue(ccipTxReceipt)
78103
const { bridgeToken, localSimulator, router } = await getContracts()
79-
const approvedAmount = parseEther('0')
104+
const approvedAmount = Viem.parseEther('0')
80105

81106
const { txReceipt } = await ccipClient.approveRouter({
82107
client: testClient,
@@ -114,7 +139,7 @@ describe('Integration- Using Mocks', () => {
114139
writeContractMock.mockResolvedValueOnce(ccipTxHash)
115140
waitForTransactionReceiptMock.mockResolvedValue(ccipTxReceipt)
116141
const { bridgeToken, router } = await getContracts()
117-
const approvedAmount = parseEther('10')
142+
const approvedAmount = Viem.parseEther('10')
118143

119144
// HH: Approval Transaction
120145
await bridgeToken.write.approve([
@@ -214,7 +239,7 @@ describe('Integration- Using Mocks', () => {
214239
// const data = encodeFunctionData({
215240
// abi: CCIP.IERC20ABI,
216241
// functionName: 'transfer',
217-
// args: [Viem.zeroAddress, Viem.parseEther('0.12')],
242+
// args: [Viem.Viem.zeroAddress, Viem.parseEther('0.12')],
218243
// })
219244
// const hhFee = await router.read.getFee([
220245
// '14767482510784806043', // destinationChainSelector: '14767482510784806043',
@@ -226,7 +251,7 @@ describe('Integration- Using Mocks', () => {
226251
// client: testClient,
227252
// routerAddress: router.address,
228253
// destinationChainSelector: '14767482510784806043',
229-
// destinationAccount: zeroAddress,
254+
// destinationAccount: Viem.zeroAddress,
230255
// amount: 1000000000000000000n,
231256
// tokenAddress: '0x94095e6514411C65E7809761F21eF0febe69A977',
232257
// })
@@ -299,7 +324,7 @@ describe('Integration- Using Mocks', () => {
299324

300325
// const hhTransfer = await router.write.ccipSend([
301326
// 14767482510784806043n, // destinationChainSelector
302-
// zeroAddress // destinationAccount
327+
// Viem.zeroAddress // destinationAccount
303328
// ])
304329
// mineBlock(isFork)
305330
// console.log({ hhTransfer })
@@ -308,7 +333,7 @@ describe('Integration- Using Mocks', () => {
308333
client: testClient,
309334
routerAddress: '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59',
310335
destinationChainSelector: '14767482510784806043',
311-
destinationAccount: zeroAddress,
336+
destinationAccount: Viem.zeroAddress,
312337
tokenAddress: '0x94095e6514411C65E7809761F21eF0febe69A977',
313338
amount: 1000000000000000000n,
314339
})
@@ -351,7 +376,7 @@ describe('Integration- Using Mocks', () => {
351376
client: testClient,
352377
routerAddress: router.address,
353378
destinationChainSelector: '14767482510784806043',
354-
destinationAccount: zeroAddress,
379+
destinationAccount: Viem.zeroAddress,
355380
data: Viem.encodeAbiParameters([{ type: 'string', name: 'data' }], ['Hello']),
356381
})
357382
expect(transfer.txHash).toEqual(ccipTxHash)
@@ -371,7 +396,7 @@ describe('Integration- Using Mocks', () => {
371396
client: testClient,
372397
routerAddress: router.address,
373398
destinationChainSelector: '14767482510784806043',
374-
destinationAccount: zeroAddress,
399+
destinationAccount: Viem.zeroAddress,
375400
feeTokenAddress: '0x94095e6514411C65E7809761F21eF0febe69A977',
376401
data: Viem.encodeAbiParameters([{ type: 'string', name: 'data' }], ['Hello']),
377402
})

0 commit comments

Comments
 (0)