@@ -20,6 +20,7 @@ import {
20
20
getBlock ,
21
21
FUEL_CALL_TX_PARAMS ,
22
22
hardhatSkipTime ,
23
+ fuels_parseEther ,
23
24
} from '@fuel-bridge/test-utils' ;
24
25
import chai from 'chai' ;
25
26
import { toBeHex , parseEther } from 'ethers' ;
@@ -32,8 +33,8 @@ import type {
32
33
Provider ,
33
34
} from 'fuels' ;
34
35
35
- import type { Containers } from '../docker-setup/docker' ;
36
36
import { startContainers } from '../docker-setup/docker' ;
37
+ import { fundWithdrawalTransactionWithBaseAssetResource } from '../utils/utils' ;
37
38
38
39
const { expect } = chai ;
39
40
@@ -52,8 +53,6 @@ describe('Bridging ERC20 tokens', async function () {
52
53
let fuel_bridgeContractId : string ;
53
54
let fuel_testAssetId : string ;
54
55
55
- let containers : Containers ;
56
-
57
56
// override the default test timeout from 2000ms
58
57
this . timeout ( DEFAULT_TIMEOUT_MS ) ;
59
58
@@ -66,7 +65,8 @@ describe('Bridging ERC20 tokens', async function () {
66
65
fuelTokenSender : FuelWallet ,
67
66
ethereumTokenReceiverAddress : string ,
68
67
NUM_TOKENS : bigint ,
69
- DECIMAL_DIFF : bigint
68
+ DECIMAL_DIFF : bigint ,
69
+ useMessageCoin : boolean
70
70
) : Promise < MessageProof | null > {
71
71
// withdraw tokens back to the base chain
72
72
fuel_bridge . account = fuelTokenSender ;
@@ -75,22 +75,19 @@ describe('Bridging ERC20 tokens', async function () {
75
75
const fuelTokenSenderBalance = await fuelTokenSender . getBalance (
76
76
fuel_testAssetId
77
77
) ;
78
- const transactionRequest = await fuel_bridge . functions
79
- . withdraw ( paddedAddress )
80
- . addContracts ( [ fuel_bridge , fuel_bridgeImpl ] )
81
- . txParams ( {
82
- tip : 0 ,
83
- maxFee : 1 ,
84
- } )
85
- . callParams ( {
86
- forward : {
87
- amount : new BN ( NUM_TOKENS . toString ( ) ) . div (
88
- new BN ( DECIMAL_DIFF . toString ( ) )
89
- ) ,
90
- assetId : fuel_testAssetId ,
91
- } ,
92
- } )
93
- . fundWithRequiredCoins ( ) ;
78
+
79
+ const transactionRequest =
80
+ await fundWithdrawalTransactionWithBaseAssetResource (
81
+ env ,
82
+ fuel_bridge ,
83
+ fuelTokenSender ,
84
+ paddedAddress ,
85
+ NUM_TOKENS ,
86
+ 9n ,
87
+ fuel_bridgeImpl ,
88
+ fuel_testAssetId ,
89
+ useMessageCoin
90
+ ) ;
94
91
95
92
const tx = await fuelTokenSender . sendTransaction ( transactionRequest ) ;
96
93
const fWithdrawTxResult = await tx . waitForResult ( ) ;
@@ -208,14 +205,9 @@ describe('Bridging ERC20 tokens', async function () {
208
205
209
206
before ( async ( ) => {
210
207
// spinning up all docker containers
211
- containers = await startContainers ( true , 8080 , 8545 , 4000 ) ;
212
-
213
- env = await setupEnvironment ( {
214
- http_ethereum_client : 'http://127.0.0.1:8545' ,
215
- http_deployer : 'http://127.0.0.1:8080' ,
216
- http_fuel_client : 'http://127.0.0.1:4000/v1/graphql' ,
217
- } ) ;
208
+ await startContainers ( ) ;
218
209
210
+ env = await setupEnvironment ( { } ) ;
219
211
eth_erc20GatewayAddress = (
220
212
await env . eth . fuelERC20Gateway . getAddress ( )
221
213
) . toLowerCase ( ) ;
@@ -309,6 +301,59 @@ describe('Bridging ERC20 tokens', async function () {
309
301
) ;
310
302
} ) ;
311
303
304
+ it ( 'Bridge ETH to Fuel to be used as Message Coin during token withdrawal' , async ( ) => {
305
+ // use the FuelMessagePortal to directly send ETH which should be immediately spendable
306
+ const tx = await env . eth . fuelMessagePortal
307
+ . connect ( ethereumTokenSender )
308
+ . depositETH ( fuelTokenReceiverAddress , {
309
+ value : parseEther ( '1' ) ,
310
+ } ) ;
311
+ const receipt = await tx . wait ( ) ;
312
+ expect ( receipt . status ) . to . equal ( 1 ) ;
313
+
314
+ // parse events from logs
315
+ const filter = env . eth . fuelMessagePortal . filters . MessageSent (
316
+ null , // Args set to null since there should be just 1 event for MessageSent
317
+ null ,
318
+ null ,
319
+ null ,
320
+ null
321
+ ) ;
322
+
323
+ const [ event , ...restOfEvents ] =
324
+ await env . eth . fuelMessagePortal . queryFilter (
325
+ filter ,
326
+ receipt . blockNumber ,
327
+ receipt . blockNumber
328
+ ) ;
329
+ expect ( restOfEvents . length ) . to . be . eq ( 0 ) ; // Should be only 1 event
330
+
331
+ const fuelETHMessageNonce = new BN ( event . args . nonce . toString ( ) ) ;
332
+
333
+ fuelTokenMessageReceiver = fuelTokenReceiver . address ;
334
+
335
+ // wait for message to appear in fuel client
336
+ expect (
337
+ await waitForMessage (
338
+ env . fuel . provider ,
339
+ fuelTokenMessageReceiver ,
340
+ fuelETHMessageNonce ,
341
+ FUEL_MESSAGE_TIMEOUT_MS
342
+ )
343
+ ) . to . not . be . null ;
344
+
345
+ // verify the incoming messages generated when base asset is minted on fuel
346
+ const incomingMessagesonFuel = await env . fuel . signers [ 0 ] . getMessages ( ) ;
347
+
348
+ // eth as bridged once at the start
349
+ expect ( incomingMessagesonFuel . messages . length === 1 ) . to . be . true ;
350
+
351
+ // 1 eth was bridged
352
+ expect (
353
+ incomingMessagesonFuel . messages [ 0 ] . amount . eq ( fuels_parseEther ( '1' ) )
354
+ ) . to . be . true ;
355
+ } ) ;
356
+
312
357
it ( 'Bridge ERC20 via FuelERC20Gateway' , async ( ) => {
313
358
// approve FuelERC20Gateway to spend the tokens
314
359
await eth_testToken
@@ -468,7 +513,8 @@ describe('Bridging ERC20 tokens', async function () {
468
513
fuelTokenSender ,
469
514
ethereumTokenReceiverAddress ,
470
515
NUM_TOKENS ,
471
- DECIMAL_DIFF
516
+ DECIMAL_DIFF ,
517
+ true
472
518
) ;
473
519
} ) ;
474
520
@@ -586,7 +632,8 @@ describe('Bridging ERC20 tokens', async function () {
586
632
fuelTokenSender ,
587
633
ethereumTokenReceiverAddress ,
588
634
NUM_TOKENS ,
589
- DECIMAL_DIFF
635
+ DECIMAL_DIFF ,
636
+ false
590
637
) ;
591
638
592
639
// relay message
@@ -679,14 +726,4 @@ describe('Bridging ERC20 tokens', async function () {
679
726
) . to . be . true ;
680
727
} ) ;
681
728
} ) ;
682
-
683
- // stopping containers post the test
684
- after ( async ( ) => {
685
- await containers . postGresContainer . stop ( ) ;
686
- await containers . l1_node . stop ( ) ;
687
-
688
- await containers . fuel_node . stop ( ) ;
689
-
690
- await containers . block_committer . stop ( ) ;
691
- } ) ;
692
729
} ) ;
0 commit comments