@@ -13,15 +13,17 @@ use std::str::FromStr;
13
13
mod success {
14
14
use super :: * ;
15
15
16
- use crate :: utils:: interface:: src20:: total_supply;
17
- use crate :: utils:: setup:: get_asset_id;
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} ;
18
19
use crate :: utils:: {
19
20
constants:: MESSAGE_AMOUNT ,
20
21
setup:: {
21
22
contract_balance, create_recipient_contract, encode_hex, precalculate_deposit_id,
22
23
wallet_balance, RefundRegisteredEvent ,
23
24
} ,
24
25
} ;
26
+ use fuels:: types:: SizedAsciiString ;
25
27
use fuels:: { prelude:: AssetId , programs:: contract:: SettableContract , types:: Bits256 } ;
26
28
use primitive_types:: U256 as Unsigned256 ;
27
29
@@ -74,6 +76,232 @@ mod success {
74
76
assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
75
77
}
76
78
79
+ // This test is akin to bridging WBTC and mimicking its decimals on Fuel
80
+ #[ tokio:: test]
81
+ async fn deposit_to_wallet_with_6_decimals ( ) {
82
+ let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
83
+ let proxy_token_decimals = 6u8 ;
84
+ let bridged_token_decimals = 6u8 ;
85
+ let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
86
+
87
+ let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
88
+ BridgeFungibleTokenContractConfigurables :: new ( )
89
+ . with_DECIMALS ( proxy_token_decimals)
90
+ . with_BRIDGED_TOKEN_DECIMALS ( bridged_token_decimals)
91
+ ) ;
92
+
93
+ let ( message, coin, deposit_contract) = create_msg_data (
94
+ BRIDGED_TOKEN ,
95
+ BRIDGED_TOKEN_ID ,
96
+ FROM ,
97
+ * wallet. address ( ) . hash ( ) ,
98
+ config. amount . test ,
99
+ configurables. clone ( ) ,
100
+ false ,
101
+ None ,
102
+ )
103
+ . await ;
104
+
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
+
109
+ let ( bridge, utxo_inputs) = setup_environment (
110
+ & mut wallet,
111
+ vec ! [ coin] ,
112
+ vec ! [ message] ,
113
+ deposit_contract,
114
+ None ,
115
+ configurables,
116
+ )
117
+ . await ;
118
+
119
+ let provider = wallet. provider ( ) . expect ( "Needs provider" ) ;
120
+
121
+ // Relay the test message to the bridge contract
122
+ let tx = relay_message_to_contract (
123
+ & wallet,
124
+ utxo_inputs. message [ 0 ] . clone ( ) ,
125
+ utxo_inputs. contract ,
126
+ )
127
+ . await ;
128
+
129
+ let receipts = provider. tx_status ( & tx) . await . unwrap ( ) . take_receipts ( ) ;
130
+
131
+ let refund_registered_events = bridge
132
+ . log_decoder ( )
133
+ . decode_logs_with_type :: < RefundRegisteredEvent > ( & receipts)
134
+ . unwrap ( ) ;
135
+
136
+ assert_eq ! ( refund_registered_events. len( ) , 0 ) ;
137
+
138
+ let asset_balance =
139
+ contract_balance ( provider, bridge. contract_id ( ) , AssetId :: default ( ) ) . await ;
140
+ let balance = wallet_balance ( & wallet, & get_asset_id ( bridge. contract_id ( ) ) ) . await ;
141
+
142
+ // Verify the message value was received by the bridge
143
+ assert_eq ! ( asset_balance, MESSAGE_AMOUNT ) ;
144
+
145
+ // Check that wallet now has bridged coins
146
+ assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
147
+ }
148
+
149
+ // This test is akin to bridging USDC or USDT and mimicking its decimals on Fuel
150
+ #[ tokio:: test]
151
+ async fn deposit_to_wallet_with_8_decimals ( ) {
152
+ let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
153
+ let proxy_token_decimals = 8u8 ;
154
+ let bridged_token_decimals = 8u8 ;
155
+ let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
156
+
157
+ let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
158
+ BridgeFungibleTokenContractConfigurables :: new ( )
159
+ . with_DECIMALS ( proxy_token_decimals)
160
+ . with_BRIDGED_TOKEN_DECIMALS ( bridged_token_decimals)
161
+ ) ;
162
+
163
+ let ( message, coin, deposit_contract) = create_msg_data (
164
+ BRIDGED_TOKEN ,
165
+ BRIDGED_TOKEN_ID ,
166
+ FROM ,
167
+ * wallet. address ( ) . hash ( ) ,
168
+ config. amount . test ,
169
+ configurables. clone ( ) ,
170
+ false ,
171
+ None ,
172
+ )
173
+ . await ;
174
+
175
+ 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
+
179
+ let ( bridge, utxo_inputs) = setup_environment (
180
+ & mut wallet,
181
+ vec ! [ coin] ,
182
+ vec ! [ message] ,
183
+ deposit_contract,
184
+ None ,
185
+ configurables,
186
+ )
187
+ . await ;
188
+
189
+ let provider = wallet. provider ( ) . expect ( "Needs provider" ) ;
190
+
191
+ // Relay the test message to the bridge contract
192
+ let tx = relay_message_to_contract (
193
+ & wallet,
194
+ utxo_inputs. message [ 0 ] . clone ( ) ,
195
+ utxo_inputs. contract ,
196
+ )
197
+ . await ;
198
+
199
+ let receipts = provider. tx_status ( & tx) . await . unwrap ( ) . take_receipts ( ) ;
200
+
201
+ let refund_registered_events = bridge
202
+ . log_decoder ( )
203
+ . decode_logs_with_type :: < RefundRegisteredEvent > ( & receipts)
204
+ . unwrap ( ) ;
205
+
206
+ assert_eq ! ( refund_registered_events. len( ) , 0 ) ;
207
+
208
+ let asset_balance =
209
+ contract_balance ( provider, bridge. contract_id ( ) , AssetId :: default ( ) ) . await ;
210
+ let balance = wallet_balance ( & wallet, & get_asset_id ( bridge. contract_id ( ) ) ) . await ;
211
+
212
+ // Verify the message value was received by the bridge
213
+ assert_eq ! ( asset_balance, MESSAGE_AMOUNT ) ;
214
+
215
+ // Check that wallet now has bridged coins
216
+ assert_eq ! ( balance, config. fuel_equivalent_amount( config. amount. test) ) ;
217
+ }
218
+
219
+ // This test is akin to bridging USDC or USDT and using the standard 9 decimals on Fuel
220
+ #[ tokio:: test]
221
+ async fn deposit_to_wallet_with_6_decimals_and_conversion ( ) {
222
+ let mut wallet: fuels:: accounts:: wallet:: WalletUnlocked = create_wallet ( ) ;
223
+ let proxy_token_decimals = 9u8 ;
224
+ let bridged_token_decimals = 6u8 ;
225
+ let config = BridgingConfig :: new ( bridged_token_decimals, proxy_token_decimals) ;
226
+
227
+ let configurables: Option < BridgeFungibleTokenContractConfigurables > = Some (
228
+ BridgeFungibleTokenContractConfigurables :: new ( )
229
+ . with_DECIMALS ( proxy_token_decimals)
230
+ . with_BRIDGED_TOKEN_DECIMALS ( bridged_token_decimals)
231
+ . with_BRIDGED_TOKEN_GATEWAY ( Bits256 :: from_hex_str ( BRIDGED_TOKEN_GATEWAY ) . unwrap ( ) )
232
+ . with_BRIDGED_TOKEN ( Bits256 :: from_hex_str ( BRIDGED_TOKEN ) . unwrap ( ) )
233
+ . with_NAME ( SizedAsciiString :: < 64 > :: new ( String :: from ( "MY_TOKEN " ) ) . unwrap ( ) )
234
+ . with_SYMBOL ( SizedAsciiString :: < 32 > :: new ( String :: from ( "MYTKN " ) ) . unwrap ( ) )
235
+ ) ;
236
+
237
+ let deposit_amount = config. amount . min ;
238
+
239
+ let ( message, coin, deposit_contract) = create_msg_data (
240
+ BRIDGED_TOKEN ,
241
+ BRIDGED_TOKEN_ID ,
242
+ FROM ,
243
+ * wallet. address ( ) . hash ( ) ,
244
+ deposit_amount,
245
+ configurables. clone ( ) ,
246
+ false ,
247
+ None ,
248
+ )
249
+ . await ;
250
+
251
+ let ( bridge, utxo_inputs) = setup_environment (
252
+ & mut wallet,
253
+ vec ! [ coin] ,
254
+ vec ! [ message] ,
255
+ deposit_contract,
256
+ None ,
257
+ configurables,
258
+ )
259
+ . await ;
260
+
261
+ let provider = wallet. provider ( ) . expect ( "Needs provider" ) ;
262
+
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
+ // Relay the test message to the bridge contract
277
+ let tx = relay_message_to_contract (
278
+ & wallet,
279
+ utxo_inputs. message [ 0 ] . clone ( ) ,
280
+ utxo_inputs. contract ,
281
+ )
282
+ . await ;
283
+
284
+ let receipts = provider. tx_status ( & tx) . await . unwrap ( ) . take_receipts ( ) ;
285
+ dbg ! ( & receipts) ;
286
+
287
+ let refund_registered_events = bridge
288
+ . log_decoder ( )
289
+ . decode_logs_with_type :: < RefundRegisteredEvent > ( & receipts)
290
+ . unwrap ( ) ;
291
+
292
+ assert_eq ! ( refund_registered_events. len( ) , 0 ) ;
293
+
294
+ let asset_balance =
295
+ contract_balance ( provider, bridge. contract_id ( ) , AssetId :: default ( ) ) . await ;
296
+ let balance = wallet_balance ( & wallet, & get_asset_id ( bridge. contract_id ( ) ) ) . await ;
297
+
298
+ // Verify the message value was received by the bridge
299
+ assert_eq ! ( asset_balance, MESSAGE_AMOUNT ) ;
300
+
301
+ // Check that wallet now has bridged coins
302
+ assert_eq ! ( balance, config. fuel_equivalent_amount( deposit_amount) ) ;
303
+ }
304
+
77
305
#[ tokio:: test]
78
306
async fn deposit_to_wallet_max_amount ( ) {
79
307
let mut wallet = create_wallet ( ) ;
0 commit comments