@@ -14,8 +14,8 @@ mod success {
14
14
use super :: * ;
15
15
16
16
use crate :: utils:: constants:: BRIDGED_TOKEN_GATEWAY ;
17
- use crate :: utils:: interface:: src20:: { decimals , total_supply} ;
18
- use crate :: utils:: setup:: { decode_hex , get_asset_id} ;
17
+ use crate :: utils:: interface:: src20:: total_supply;
18
+ use crate :: utils:: setup:: get_asset_id;
19
19
use crate :: utils:: {
20
20
constants:: MESSAGE_AMOUNT ,
21
21
setup:: {
@@ -76,12 +76,12 @@ mod success {
76
76
assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
77
77
}
78
78
79
- // This test is akin to bridging WBTC and mimicking its decimals on Fuel
79
+ // This test is akin to bridging USDT or USDC and mimicking its decimals on Fuel
80
80
#[ tokio:: test]
81
81
async fn deposit_to_wallet_with_6_decimals ( ) {
82
82
let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
83
- let proxy_token_decimals = 6u8 ;
84
- let bridged_token_decimals = 6u8 ;
83
+ let proxy_token_decimals = 6u64 ;
84
+ let bridged_token_decimals = 6u64 ;
85
85
let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
86
86
87
87
let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
@@ -103,8 +103,6 @@ mod success {
103
103
. await ;
104
104
105
105
assert_eq ! ( config. amount. test. as_u64( ) , config. fuel_equivalent_amount( config. amount. test) ) ;
106
- dbg ! ( config. amount. test. as_u64( ) ) ;
107
- dbg ! ( config. fuel_equivalent_amount( config. amount. test) ) ;
108
106
109
107
let ( bridge, utxo_inputs) = setup_environment (
110
108
& mut wallet,
@@ -146,12 +144,12 @@ mod success {
146
144
assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
147
145
}
148
146
149
- // This test is akin to bridging USDC or USDT and mimicking its decimals on Fuel
147
+ // This test is akin to bridging WBTC and mimicking its decimals on Fuel
150
148
#[ tokio:: test]
151
149
async fn deposit_to_wallet_with_8_decimals ( ) {
152
150
let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
153
- let proxy_token_decimals = 8u8 ;
154
- let bridged_token_decimals = 8u8 ;
151
+ let proxy_token_decimals = 8u64 ;
152
+ let bridged_token_decimals = 8u64 ;
155
153
let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
156
154
157
155
let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
@@ -173,8 +171,6 @@ mod success {
173
171
. await ;
174
172
175
173
assert_eq ! ( config. amount. test. as_u64( ) , config. fuel_equivalent_amount( config. amount. test) ) ;
176
- dbg ! ( config. amount. test. as_u64( ) ) ;
177
- dbg ! ( config. fuel_equivalent_amount( config. amount. test) ) ;
178
174
179
175
let ( bridge, utxo_inputs) = setup_environment (
180
176
& mut wallet,
@@ -220,8 +216,8 @@ mod success {
220
216
#[ tokio:: test]
221
217
async fn deposit_to_wallet_with_6_decimals_and_conversion ( ) {
222
218
let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
223
- let proxy_token_decimals = 9u8 ;
224
- let bridged_token_decimals = 6u8 ;
219
+ let proxy_token_decimals = 9u64 ;
220
+ let bridged_token_decimals = 6u64 ;
225
221
let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
226
222
227
223
let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
@@ -260,19 +256,6 @@ mod success {
260
256
261
257
let provider = wallet. provider ( ) . expect ( "Needs provider" ) ;
262
258
263
- let decimals = decimals ( & bridge, get_asset_id ( bridge. contract_id ( ) ) ) . await ;
264
- dbg ! ( decimals) ;
265
-
266
- let decimals = & bridge
267
- . methods ( )
268
- . bridged_token_decimals ( )
269
- . call ( )
270
- . await
271
- . unwrap ( )
272
- . value ;
273
-
274
- dbg ! ( decimals) ;
275
-
276
259
// Relay the test message to the bridge contract
277
260
let tx = relay_message_to_contract (
278
261
& wallet,
@@ -282,7 +265,6 @@ mod success {
282
265
. await ;
283
266
284
267
let receipts = provider. tx_status ( & tx) . await . unwrap ( ) . take_receipts ( ) ;
285
- dbg ! ( & receipts) ;
286
268
287
269
let refund_registered_events = bridge
288
270
. log_decoder ( )
@@ -302,6 +284,139 @@ mod success {
302
284
assert_eq ! ( balance, config. fuel_equivalent_amount( deposit_amount) ) ;
303
285
}
304
286
287
+ // This test is akin to bridging WBTC and and using the standard 9 decimals on Fuel
288
+ #[ tokio:: test]
289
+ async fn deposit_to_wallet_with_8_decimals_and_conversion ( ) {
290
+ let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
291
+ let proxy_token_decimals = 9u64 ;
292
+ let bridged_token_decimals = 8u64 ;
293
+ let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
294
+
295
+ let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
296
+ BridgeFungibleTokenContractConfigurables :: new ( )
297
+ . with_DECIMALS ( proxy_token_decimals)
298
+ . with_BRIDGED_TOKEN_DECIMALS ( bridged_token_decimals)
299
+ ) ;
300
+
301
+ let ( message, coin, deposit_contract) = create_msg_data (
302
+ BRIDGED_TOKEN ,
303
+ BRIDGED_TOKEN_ID ,
304
+ FROM ,
305
+ * wallet. address ( ) . hash ( ) ,
306
+ config. amount . test ,
307
+ configurables. clone ( ) ,
308
+ false ,
309
+ None ,
310
+ )
311
+ . await ;
312
+
313
+ let ( bridge, utxo_inputs) = setup_environment (
314
+ & mut wallet,
315
+ vec ! [ coin] ,
316
+ vec ! [ message] ,
317
+ deposit_contract,
318
+ None ,
319
+ configurables,
320
+ )
321
+ . await ;
322
+
323
+ let provider = wallet. provider ( ) . expect ( "Needs provider" ) ;
324
+
325
+ // Relay the test message to the bridge contract
326
+ let tx = relay_message_to_contract (
327
+ & wallet,
328
+ utxo_inputs. message [ 0 ] . clone ( ) ,
329
+ utxo_inputs. contract ,
330
+ )
331
+ . await ;
332
+
333
+ let receipts = provider. tx_status ( & tx) . await . unwrap ( ) . take_receipts ( ) ;
334
+
335
+ let refund_registered_events = bridge
336
+ . log_decoder ( )
337
+ . decode_logs_with_type :: < RefundRegisteredEvent > ( & receipts)
338
+ . unwrap ( ) ;
339
+
340
+ assert_eq ! ( refund_registered_events. len( ) , 0 ) ;
341
+
342
+ let asset_balance =
343
+ contract_balance ( provider, bridge. contract_id ( ) , AssetId :: default ( ) ) . await ;
344
+ let balance = wallet_balance ( & wallet, & get_asset_id ( bridge. contract_id ( ) ) ) . await ;
345
+
346
+ // Verify the message value was received by the bridge
347
+ assert_eq ! ( asset_balance, MESSAGE_AMOUNT ) ;
348
+
349
+ // Check that wallet now has bridged coins
350
+ assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
351
+ }
352
+
353
+ // Cannot find an example of a token that has more than 18 decimals
354
+ #[ tokio:: test]
355
+ async fn deposit_to_wallet_with_30_decimals_and_conversion ( ) {
356
+ let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
357
+ let proxy_token_decimals = 9u64 ;
358
+ let bridged_token_decimals = 30u64 ;
359
+ let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
360
+
361
+ let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
362
+ BridgeFungibleTokenContractConfigurables :: new ( )
363
+ . with_DECIMALS ( proxy_token_decimals)
364
+ . with_BRIDGED_TOKEN_DECIMALS ( bridged_token_decimals)
365
+ ) ;
366
+
367
+ let ( message, coin, deposit_contract) = create_msg_data (
368
+ BRIDGED_TOKEN ,
369
+ BRIDGED_TOKEN_ID ,
370
+ FROM ,
371
+ * wallet. address ( ) . hash ( ) ,
372
+ config. amount . test ,
373
+ configurables. clone ( ) ,
374
+ false ,
375
+ None ,
376
+ )
377
+ . await ;
378
+
379
+ let ( bridge, utxo_inputs) = setup_environment (
380
+ & mut wallet,
381
+ vec ! [ coin] ,
382
+ vec ! [ message] ,
383
+ deposit_contract,
384
+ None ,
385
+ configurables,
386
+ )
387
+ . await ;
388
+
389
+ let provider = wallet. provider ( ) . expect ( "Needs provider" ) ;
390
+
391
+ // Relay the test message to the bridge contract
392
+ let tx = relay_message_to_contract (
393
+ & wallet,
394
+ utxo_inputs. message [ 0 ] . clone ( ) ,
395
+ utxo_inputs. contract ,
396
+ )
397
+ . await ;
398
+
399
+ let receipts = provider. tx_status ( & tx) . await . unwrap ( ) . take_receipts ( ) ;
400
+
401
+ let refund_registered_events = bridge
402
+ . log_decoder ( )
403
+ . decode_logs_with_type :: < RefundRegisteredEvent > ( & receipts)
404
+ . unwrap ( ) ;
405
+
406
+ assert_eq ! ( refund_registered_events. len( ) , 0 ) ;
407
+
408
+ let asset_balance =
409
+ contract_balance ( provider, bridge. contract_id ( ) , AssetId :: default ( ) ) . await ;
410
+ let balance = wallet_balance ( & wallet, & get_asset_id ( bridge. contract_id ( ) ) ) . await ;
411
+
412
+ // Verify the message value was received by the bridge
413
+ assert_eq ! ( asset_balance, MESSAGE_AMOUNT ) ;
414
+
415
+ // Check that wallet now has bridged coins
416
+ assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
417
+ }
418
+
419
+
305
420
#[ tokio:: test]
306
421
async fn deposit_to_wallet_max_amount ( ) {
307
422
let mut wallet = create_wallet ( ) ;
0 commit comments