@@ -2,7 +2,6 @@ import { jest, expect, it, describe, afterEach, beforeAll } from '@jest/globals'
2
2
import * as CCIP from '../src/api'
3
3
import * as Viem from 'viem'
4
4
import * as viemActions from 'viem/actions'
5
- import { parseEther , zeroAddress } from 'viem'
6
5
7
6
import { testClient } from './helpers/clients'
8
7
import { account , ccipLog , ccipTxHash , ccipTxReceipt , onRampAbi , routerAbi } from './helpers/constants'
@@ -27,6 +26,32 @@ describe('Integration- Using Mocks', () => {
27
26
jest . clearAllMocks ( )
28
27
} )
29
28
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
+
30
55
describe ( '√ deploy on Anvil' , ( ) => {
31
56
it ( 'Should Deploy Router.sol' , async function ( ) {
32
57
const { router } = await getContracts ( )
@@ -50,7 +75,7 @@ describe('Integration- Using Mocks', () => {
50
75
51
76
writeContractMock . mockResolvedValueOnce ( ccipTxHash )
52
77
waitForTransactionReceiptMock . mockResolvedValue ( ccipTxReceipt )
53
- const approvedAmount = parseEther ( '10' )
78
+ const approvedAmount = Viem . parseEther ( '10' )
54
79
55
80
// HH: Approval Transaction
56
81
await bridgeToken . write . approve ( [
@@ -76,7 +101,7 @@ describe('Integration- Using Mocks', () => {
76
101
// writeContractMock.mockResolvedValueOnce(ccipTxHash)
77
102
// waitForTransactionReceiptMock.mockResolvedValue(ccipTxReceipt)
78
103
const { bridgeToken, localSimulator, router } = await getContracts ( )
79
- const approvedAmount = parseEther ( '0' )
104
+ const approvedAmount = Viem . parseEther ( '0' )
80
105
81
106
const { txReceipt } = await ccipClient . approveRouter ( {
82
107
client : testClient ,
@@ -114,7 +139,7 @@ describe('Integration- Using Mocks', () => {
114
139
writeContractMock . mockResolvedValueOnce ( ccipTxHash )
115
140
waitForTransactionReceiptMock . mockResolvedValue ( ccipTxReceipt )
116
141
const { bridgeToken, router } = await getContracts ( )
117
- const approvedAmount = parseEther ( '10' )
142
+ const approvedAmount = Viem . parseEther ( '10' )
118
143
119
144
// HH: Approval Transaction
120
145
await bridgeToken . write . approve ( [
@@ -214,7 +239,7 @@ describe('Integration- Using Mocks', () => {
214
239
// const data = encodeFunctionData({
215
240
// abi: CCIP.IERC20ABI,
216
241
// functionName: 'transfer',
217
- // args: [Viem.zeroAddress, Viem.parseEther('0.12')],
242
+ // args: [Viem.Viem. zeroAddress, Viem.parseEther('0.12')],
218
243
// })
219
244
// const hhFee = await router.read.getFee([
220
245
// '14767482510784806043', // destinationChainSelector: '14767482510784806043',
@@ -226,7 +251,7 @@ describe('Integration- Using Mocks', () => {
226
251
// client: testClient,
227
252
// routerAddress: router.address,
228
253
// destinationChainSelector: '14767482510784806043',
229
- // destinationAccount: zeroAddress,
254
+ // destinationAccount: Viem. zeroAddress,
230
255
// amount: 1000000000000000000n,
231
256
// tokenAddress: '0x94095e6514411C65E7809761F21eF0febe69A977',
232
257
// })
@@ -299,7 +324,7 @@ describe('Integration- Using Mocks', () => {
299
324
300
325
// const hhTransfer = await router.write.ccipSend([
301
326
// 14767482510784806043n, // destinationChainSelector
302
- // zeroAddress // destinationAccount
327
+ // Viem. zeroAddress // destinationAccount
303
328
// ])
304
329
// mineBlock(isFork)
305
330
// console.log({ hhTransfer })
@@ -308,7 +333,7 @@ describe('Integration- Using Mocks', () => {
308
333
client : testClient ,
309
334
routerAddress : '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59' ,
310
335
destinationChainSelector : '14767482510784806043' ,
311
- destinationAccount : zeroAddress ,
336
+ destinationAccount : Viem . zeroAddress ,
312
337
tokenAddress : '0x94095e6514411C65E7809761F21eF0febe69A977' ,
313
338
amount : 1000000000000000000n ,
314
339
} )
@@ -351,7 +376,7 @@ describe('Integration- Using Mocks', () => {
351
376
client : testClient ,
352
377
routerAddress : router . address ,
353
378
destinationChainSelector : '14767482510784806043' ,
354
- destinationAccount : zeroAddress ,
379
+ destinationAccount : Viem . zeroAddress ,
355
380
data : Viem . encodeAbiParameters ( [ { type : 'string' , name : 'data' } ] , [ 'Hello' ] ) ,
356
381
} )
357
382
expect ( transfer . txHash ) . toEqual ( ccipTxHash )
@@ -371,7 +396,7 @@ describe('Integration- Using Mocks', () => {
371
396
client : testClient ,
372
397
routerAddress : router . address ,
373
398
destinationChainSelector : '14767482510784806043' ,
374
- destinationAccount : zeroAddress ,
399
+ destinationAccount : Viem . zeroAddress ,
375
400
feeTokenAddress : '0x94095e6514411C65E7809761F21eF0febe69A977' ,
376
401
data : Viem . encodeAbiParameters ( [ { type : 'string' , name : 'data' } ] , [ 'Hello' ] ) ,
377
402
} )
0 commit comments