@@ -24,7 +24,7 @@ use namada_apps_lib::config::ethereum_bridge;
2424use namada_apps_lib:: config:: genesis:: templates;
2525use namada_apps_lib:: tendermint_rpc:: { Client , HttpClient , Url } ;
2626use namada_core:: masp:: PaymentAddress ;
27- use namada_sdk:: address:: MASP ;
27+ use namada_sdk:: address:: { MASP , PGF } ;
2828use namada_sdk:: chain:: Epoch ;
2929use namada_sdk:: governance:: cli:: onchain:: PgfFunding ;
3030use namada_sdk:: governance:: pgf:: ADDRESS as PGF_ADDRESS ;
@@ -76,6 +76,180 @@ const CW721_WASM: &str = "cw721_base.wasm";
7676const ICS721_WASM : & str = "ics721_base.wasm" ;
7777const NFT_ID : & str = "test_nft" ;
7878
79+ #[ test]
80+ fn ibc_shielded_action_fees ( ) -> Result < ( ) > {
81+ const PIPELINE_LEN : u64 = 2 ;
82+
83+ let update_genesis =
84+ |mut genesis : templates:: All < templates:: Unvalidated > , base_dir : & _ | {
85+ genesis. parameters . parameters . epochs_per_year =
86+ epochs_per_year_from_min_duration ( 60 ) ;
87+ genesis. parameters . gov_params . min_proposal_grace_epochs = 3 ;
88+ genesis. parameters . ibc_params . default_mint_limit =
89+ Amount :: max_signed ( ) ;
90+ genesis
91+ . parameters
92+ . ibc_params
93+ . default_per_epoch_throughput_limit = Amount :: max_signed ( ) ;
94+ genesis. parameters . pos_params . pipeline_len = PIPELINE_LEN ;
95+ setup:: set_validators ( 1 , genesis, base_dir, |_| 0 , vec ! [ ] )
96+ } ;
97+ let ( ledger, gaia, test, test_gaia) =
98+ run_namada_cosmos ( CosmosChainType :: Gaia ( None ) , update_genesis) ?;
99+ let _bg_ledger = ledger. background ( ) ;
100+ let _bg_gaia = gaia. background ( ) ;
101+
102+ let port_id_namada = FT_PORT_ID . parse ( ) . unwrap ( ) ;
103+ let port_id_gaia = FT_PORT_ID . parse ( ) . unwrap ( ) ;
104+
105+ // Create channel between Namada and Gaia while simultaneously
106+ // activating shielded action fees
107+ let ( _bg_hermes, hermes_dir, channel_id_namada, channel_id_gaia) =
108+ std:: thread:: scope ( |s| {
109+ // Activate shielded action fees for samoleans on Namada
110+ // - 1% for IBC shielding ops
111+ // - 2% for IBC unshielding ops
112+ let proposal_thread = s. spawn ( || {
113+ // Delegate tokens on Namada
114+ delegate_token ( & test) . unwrap ( ) ;
115+ let rpc = get_actor_rpc ( & test, Who :: Validator ( 0 ) ) ;
116+ let mut epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
117+ let delegated_epoch = epoch + PIPELINE_LEN ;
118+
119+ // Wait for tokens to be delegated
120+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
121+ while epoch < delegated_epoch {
122+ epoch = epoch_sleep ( & test, & rpc, 120 ) . unwrap ( ) ;
123+ }
124+
125+ // Launch IBC shielded action fees proposal on Namada
126+ let start_epoch = propose_shielded_action_fees ( & test) . unwrap ( ) ;
127+
128+ // Vote
129+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
130+ while epoch < start_epoch {
131+ epoch = epoch_sleep ( & test, & rpc, 120 ) . unwrap ( ) ;
132+ }
133+ submit_votes ( & test) . unwrap ( ) ;
134+
135+ // Wait for grace epoch
136+ let grace_epoch = start_epoch + 6u64 /* grace epoch offset */ ;
137+ epoch = get_epoch ( & test, & rpc) . unwrap ( ) ;
138+ while epoch < grace_epoch {
139+ epoch = epoch_sleep ( & test, & rpc, 120 ) . unwrap ( ) ;
140+ }
141+ } ) ;
142+
143+ // Create channel between Namada and Gaia
144+ let hermes_thread = s. spawn ( || {
145+ let hermes_dir = setup_hermes ( & test, & test_gaia) . unwrap ( ) ;
146+ let ( channel_id_namada, channel_id_gaia) =
147+ create_channel_with_hermes (
148+ & hermes_dir,
149+ & test,
150+ & test_gaia,
151+ & port_id_namada,
152+ & port_id_gaia,
153+ )
154+ . unwrap ( ) ;
155+
156+ // Start relaying
157+ let hermes = run_hermes ( & hermes_dir) . unwrap ( ) ;
158+ let bg_hermes = hermes. background ( ) ;
159+
160+ ( bg_hermes, hermes_dir, channel_id_namada, channel_id_gaia)
161+ } ) ;
162+
163+ proposal_thread. join ( ) . unwrap ( ) ;
164+ hermes_thread. join ( ) . unwrap ( )
165+ } ) ;
166+
167+ // Shielding transfer 200 samoleans from Gaia to Namada
168+ let albert_payment_addr = find_payment_address ( & test, AA_PAYMENT_ADDRESS ) ?;
169+ transfer_from_cosmos (
170+ & test_gaia,
171+ COSMOS_USER ,
172+ albert_payment_addr. to_string ( ) ,
173+ COSMOS_COIN ,
174+ 200 ,
175+ & port_id_gaia,
176+ & channel_id_gaia,
177+ None ,
178+ None ,
179+ ) ?;
180+ wait_for_packet_relay (
181+ & hermes_dir,
182+ & port_id_gaia,
183+ & channel_id_gaia,
184+ & test_gaia,
185+ ) ?;
186+ let ibc_denom_on_namada =
187+ format ! ( "{port_id_namada}/{channel_id_namada}/{COSMOS_COIN}" ) ;
188+ check_balance ( & test, PGF . to_string ( ) , & ibc_denom_on_namada, 2 ) ?;
189+ check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 198 ) ?;
190+ check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 800 ) ?;
191+
192+ // Unshielding transfer 100 samoleans from Namada to Gaia
193+ let gaia_receiver = find_cosmos_address ( & test_gaia, COSMOS_USER ) ?;
194+ transfer (
195+ & test,
196+ A_SPENDING_KEY ,
197+ & gaia_receiver,
198+ & ibc_denom_on_namada,
199+ 100 ,
200+ Some ( BERTHA_KEY ) ,
201+ & port_id_namada,
202+ & channel_id_namada,
203+ None ,
204+ None ,
205+ None ,
206+ None ,
207+ false ,
208+ None ,
209+ None ,
210+ ) ?;
211+ wait_for_packet_relay (
212+ & hermes_dir,
213+ & port_id_namada,
214+ & channel_id_namada,
215+ & test,
216+ ) ?;
217+ check_balance ( & test, PGF . to_string ( ) , & ibc_denom_on_namada, 4 ) ?;
218+ check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 98 ) ?;
219+ check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 898 ) ?;
220+
221+ // Get refunded by unshielding to an invalid address on Gaia
222+ transfer (
223+ & test,
224+ A_SPENDING_KEY ,
225+ "invalid_receiver" ,
226+ & ibc_denom_on_namada,
227+ 50 ,
228+ Some ( BERTHA_KEY ) ,
229+ & port_id_namada,
230+ & channel_id_namada,
231+ None ,
232+ None ,
233+ None ,
234+ None ,
235+ false ,
236+ None ,
237+ None ,
238+ ) ?;
239+ wait_for_packet_relay (
240+ & hermes_dir,
241+ & port_id_namada,
242+ & channel_id_namada,
243+ & test,
244+ ) ?;
245+ // The balance should not have changed
246+ check_balance ( & test, PGF . to_string ( ) , & ibc_denom_on_namada, 4 ) ?;
247+ check_shielded_balance ( & test, AA_VIEWING_KEY , & ibc_denom_on_namada, 98 ) ?;
248+ check_cosmos_balance ( & test_gaia, COSMOS_USER , COSMOS_COIN , 898 ) ?;
249+
250+ Ok ( ( ) )
251+ }
252+
79253#[ test]
80254fn ibc_to_and_from_payment_addrs ( ) -> Result < ( ) > {
81255 const PIPELINE_LEN : u64 = 2 ;
@@ -3355,6 +3529,54 @@ fn propose_inflation(test: &Test) -> Result<Epoch> {
33553529 Ok ( start_epoch. into ( ) )
33563530}
33573531
3532+ fn propose_shielded_action_fees ( test : & Test ) -> Result < Epoch > {
3533+ let albert = find_address ( test, ALBERT ) ?;
3534+ let rpc = get_actor_rpc ( test, Who :: Validator ( 0 ) ) ;
3535+ let epoch = get_epoch ( test, & rpc) ?;
3536+ let start_epoch = ( epoch. 0 + 3 ) / 3 * 3 ;
3537+ let proposal_json = serde_json:: json!( {
3538+ "proposal" : {
3539+ "content" : {
3540+ "title" : "IBC shielded action fees" ,
3541+ "authors" : "bing@bong.us" ,
3542+ "discussions-to" : "www.github.com/anoma/aip/1" ,
3543+ "created" : "2022-03-10T08:54:37Z" ,
3544+ "license" : "MIT" ,
3545+ "abstract" : "bing" ,
3546+ "motivation" : "bong" ,
3547+ "details" : "asdf" ,
3548+ "requires" : "2"
3549+ } ,
3550+ "author" : albert,
3551+ "voting_start_epoch" : start_epoch,
3552+ "voting_end_epoch" : start_epoch + 3_u64 ,
3553+ "activation_epoch" : start_epoch + 6_u64 ,
3554+ } ,
3555+ "data" : TestWasms :: TxProposalIbcShieldedActionFees
3556+ . read_bytes( )
3557+ } ) ;
3558+
3559+ let proposal_json_path = test
3560+ . test_dir
3561+ . path ( )
3562+ . join ( "proposal_ibc_shielded_action_fees.json" ) ;
3563+ write_json_file ( proposal_json_path. as_path ( ) , proposal_json) ;
3564+
3565+ let submit_proposal_args = apply_use_device ( vec ! [
3566+ "init-proposal" ,
3567+ "--data-path" ,
3568+ proposal_json_path. to_str( ) . unwrap( ) ,
3569+ "--gas-limit" ,
3570+ "3000000" ,
3571+ "--node" ,
3572+ & rpc,
3573+ ] ) ;
3574+ let mut client = run ! ( test, Bin :: Client , submit_proposal_args, Some ( 100 ) ) ?;
3575+ client. exp_string ( TX_APPLIED_SUCCESS ) ?;
3576+ client. assert_success ( ) ;
3577+ Ok ( start_epoch. into ( ) )
3578+ }
3579+
33583580fn propose_upgrade_client (
33593581 test_namada : & Test ,
33603582 test_gaia : & Test ,
0 commit comments