@@ -78,12 +78,19 @@ const NFT_ID: &str = "test_nft";
7878
7979#[ test]
8080fn ibc_to_and_from_payment_addrs ( ) -> Result < ( ) > {
81+ const PIPELINE_LEN : u64 = 2 ;
82+ const MASP_EPOCH_MULTIPLIER : u64 = 1 ;
83+
8184 let update_genesis =
8285 |mut genesis : templates:: All < templates:: Unvalidated > , base_dir : & _ | {
8386 genesis. parameters . parameters . epochs_per_year =
84- epochs_per_year_from_min_duration ( 1800 ) ;
87+ epochs_per_year_from_min_duration ( 60 ) ;
88+ genesis. parameters . gov_params . min_proposal_grace_epochs = 3 ;
8589 genesis. parameters . ibc_params . default_mint_limit =
8690 Amount :: max_signed ( ) ;
91+ genesis. parameters . pos_params . pipeline_len = PIPELINE_LEN ;
92+ genesis. parameters . parameters . masp_epoch_multiplier =
93+ MASP_EPOCH_MULTIPLIER ;
8794 genesis
8895 . parameters
8996 . ibc_params
@@ -95,6 +102,13 @@ fn ibc_to_and_from_payment_addrs() -> Result<()> {
95102 let _bg_ledger = ledger. background ( ) ;
96103 let _bg_gaia = gaia. background ( ) ;
97104
105+ // Delegate tokens on Namada
106+ delegate_token ( & test) ?;
107+ let rpc = get_actor_rpc ( & test, Who :: Validator ( 0 ) ) ;
108+ let mut epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
109+ let delegated_epoch = epoch + PIPELINE_LEN ;
110+
111+ // Create channel between Namada and Gaia
98112 let hermes_dir = setup_hermes ( & test, & test_gaia) ?;
99113 let port_id_namada = FT_PORT_ID . parse ( ) . unwrap ( ) ;
100114 let port_id_gaia = FT_PORT_ID . parse ( ) . unwrap ( ) ;
@@ -108,7 +122,7 @@ fn ibc_to_and_from_payment_addrs() -> Result<()> {
108122
109123 // Start relaying
110124 let hermes = run_hermes ( & hermes_dir) ?;
111- let _bg_hermes = hermes. background ( ) ;
125+ let bg_hermes = hermes. background ( ) ;
112126
113127 // Shielding transfer 200 samoleans from Gaia to Namada
114128 let albert_payment_addr = find_payment_address ( & test, AA_PAYMENT_ADDRESS ) ?;
@@ -186,10 +200,160 @@ fn ibc_to_and_from_payment_addrs() -> Result<()> {
186200 & channel_id_namada,
187201 & test,
188202 ) ?;
189- // The balance should not be changed
203+ // The balance should not have changed
190204 check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 100 ) ?;
191205 check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 900 ) ?;
192206
207+ // Attempt to mint tokens twice, by including both a payment
208+ // address and a shielding transfer. This should fail.
209+ let shielding_data = {
210+ let shielding_data_path = gen_ibc_shielding_data (
211+ & test,
212+ AA_PAYMENT_ADDRESS ,
213+ COSMOS_COIN ,
214+ 100 ,
215+ & port_id_namada,
216+ & channel_id_namada,
217+ None ,
218+ ) ?;
219+ String :: from_utf8 ( std:: fs:: read ( shielding_data_path) ?) ?
220+ } ;
221+ transfer_from_cosmos (
222+ & test_gaia,
223+ COSMOS_USER ,
224+ albert_payment_addr. to_string ( ) ,
225+ COSMOS_COIN ,
226+ 100 ,
227+ & port_id_gaia,
228+ & channel_id_gaia,
229+ // NB: stuff the shielding data onto a `Right`
230+ // variant, to avoid using the MASP transparent
231+ // address as a receiver, and use the payment
232+ // address instead
233+ Some ( Either :: Right ( shielding_data) ) ,
234+ // NB: add a timeout, to get refunded on Gaia
235+ Some ( Duration :: from_secs ( 10 ) ) ,
236+ ) ?;
237+
238+ // Check that the VP rejects the received packet
239+ let mut hermes = bg_hermes. foreground ( ) ;
240+ hermes. exp_string ( "Attempted to mint IBC tokens twice through the MASP" ) ?;
241+ let bg_hermes = hermes. background ( ) ;
242+ wait_for_packet_relay (
243+ & hermes_dir,
244+ & port_id_gaia,
245+ & channel_id_gaia,
246+ & test_gaia,
247+ ) ?;
248+ check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 100 ) ?;
249+ check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 900 ) ?;
250+
251+ // Now let's activate rewards for samoleans on Namada
252+ {
253+ // Wait for tokens to be delegated, in case
254+ // they haven't yet
255+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
256+ while epoch < delegated_epoch {
257+ epoch = epoch_sleep ( & test, & rpc, 120 ) ?;
258+ }
259+
260+ // Launch inflation proposal on Namada
261+ let start_epoch = propose_inflation ( & test) ?;
262+
263+ // Vote
264+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
265+ while epoch < start_epoch {
266+ epoch = epoch_sleep ( & test, & rpc, 120 ) ?;
267+ }
268+ submit_votes ( & test) ?;
269+
270+ // Wait for grace epoch
271+ let grace_epoch = start_epoch + 6u64 /* grace epoch offset */ ;
272+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
273+ while epoch < grace_epoch {
274+ epoch = epoch_sleep ( & test, & rpc, 120 ) ?;
275+ }
276+
277+ // Wait the next masp epoch to update the conversion state
278+ let new_masp_epoch = grace_epoch + MASP_EPOCH_MULTIPLIER ;
279+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
280+ while epoch < new_masp_epoch {
281+ epoch = epoch_sleep ( & test, & rpc, 120 ) ?;
282+ }
283+ }
284+
285+ // Attempt to mint tokens twice, again, but this time,
286+ // with rewards activated
287+ let shielding_data = {
288+ let shielding_data_path = gen_ibc_shielding_data (
289+ & test,
290+ AA_PAYMENT_ADDRESS ,
291+ COSMOS_COIN ,
292+ 100 ,
293+ & port_id_namada,
294+ & channel_id_namada,
295+ None ,
296+ ) ?;
297+ String :: from_utf8 ( std:: fs:: read ( shielding_data_path) ?) ?
298+ } ;
299+ transfer_from_cosmos (
300+ & test_gaia,
301+ COSMOS_USER ,
302+ albert_payment_addr. to_string ( ) ,
303+ COSMOS_COIN ,
304+ 100 ,
305+ & port_id_gaia,
306+ & channel_id_gaia,
307+ Some ( Either :: Right ( shielding_data) ) ,
308+ Some ( Duration :: from_secs ( 10 ) ) ,
309+ ) ?;
310+
311+ // Check that the VP rejects the received packet
312+ let mut hermes = bg_hermes. foreground ( ) ;
313+ hermes. exp_string ( "Attempted to mint IBC tokens twice through the MASP" ) ?;
314+ let _bg_hermes = hermes. background ( ) ;
315+ wait_for_packet_relay (
316+ & hermes_dir,
317+ & port_id_gaia,
318+ & channel_id_gaia,
319+ & test_gaia,
320+ ) ?;
321+ check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 100 ) ?;
322+ check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 900 ) ?;
323+
324+ // Shielding transfer 100 samoleans from Gaia to Namada (with rewards
325+ // active)
326+ let albert_payment_addr = find_payment_address ( & test, AA_PAYMENT_ADDRESS ) ?;
327+ transfer_from_cosmos (
328+ & test_gaia,
329+ COSMOS_USER ,
330+ albert_payment_addr. to_string ( ) ,
331+ COSMOS_COIN ,
332+ 100 ,
333+ & port_id_gaia,
334+ & channel_id_gaia,
335+ None ,
336+ None ,
337+ ) ?;
338+ wait_for_packet_relay (
339+ & hermes_dir,
340+ & port_id_gaia,
341+ & channel_id_gaia,
342+ & test_gaia,
343+ ) ?;
344+ let ibc_denom_on_namada =
345+ format ! ( "{port_id_namada}/{channel_id_namada}/{COSMOS_COIN}" ) ;
346+ check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 200 ) ?;
347+ check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 800 ) ?;
348+
349+ // Check the balance of the minted NAM rewards
350+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
351+ let new_masp_epoch = epoch + MASP_EPOCH_MULTIPLIER ;
352+ while epoch < new_masp_epoch {
353+ epoch = epoch_sleep ( & test, & rpc, 120 ) ?;
354+ }
355+ check_inflated_balance ( & test, AA_VIEWING_KEY ) ?;
356+
193357 Ok ( ( ) )
194358}
195359
0 commit comments