From 8177ad2ad0edd8375d270e6ae864e55534b9cb1d Mon Sep 17 00:00:00 2001 From: brentstone Date: Sat, 22 Feb 2025 01:47:05 -0800 Subject: [PATCH] fix tests --- crates/apps_lib/src/client/rpc.rs | 12 ++-- crates/governance/src/finalize_block.rs | 42 ++++++++------ crates/sdk/src/signing.rs | 14 +++-- crates/tests/src/integration/ledger_tests.rs | 58 +++++++++++++------- 4 files changed, 78 insertions(+), 48 deletions(-) diff --git a/crates/apps_lib/src/client/rpc.rs b/crates/apps_lib/src/client/rpc.rs index e861813f1a..5934f330d1 100644 --- a/crates/apps_lib/src/client/rpc.rs +++ b/crates/apps_lib/src/client/rpc.rs @@ -675,11 +675,11 @@ pub async fn query_pgf(context: &impl Namada, _args: args::QueryPgf) { true => { display_line!( context.io(), - "Pgf stewards: no stewards are currently set." + "PGF stewards: no stewards are currently set." ) } false => { - display_line!(context.io(), "Pgf stewards:"); + display_line!(context.io(), "PGF stewards:"); for steward in stewards { display_line!(context.io(), "{:4}- {}", "", steward.address); display_line!(context.io(), "{:4} Reward distribution:", ""); @@ -700,20 +700,20 @@ pub async fn query_pgf(context: &impl Namada, _args: args::QueryPgf) { true => { display_line!( context.io(), - "No continous PGF distributions exist currently." + "\nNo continous PGF distributions exist currently." ) } false => { display_line!( context.io(), - "Continuous PGF distributions (per epoch):" + "\nContinuous PGF distributions (per epoch):" ); for (str_addr, targets) in fundings { - display_line!(context.io(), "\n{:4}- {}", "", str_addr); + display_line!(context.io(), "{:4}- {}", "", str_addr); for (proposal_id, c_target) in targets { display_line!( context.io(), - "{:6}- Prop #{}: {} native tokens, end epoch = {}", + "{:6}- Prop {}: {} native tokens, end epoch = {}", "", proposal_id, c_target.amount().to_string_native(), diff --git a/crates/governance/src/finalize_block.rs b/crates/governance/src/finalize_block.rs index fcb31e682f..e60da43e76 100644 --- a/crates/governance/src/finalize_block.rs +++ b/crates/governance/src/finalize_block.rs @@ -447,28 +447,38 @@ where match funding { PGFAction::Continuous(action) => match action { AddRemove::Add(target) => { - pgf_keys::fundings_handle() - .at(&target.target.target()) - .insert(storage, proposal_id, target.clone())?; tracing::info!( - "Added/Updated Continuous PGF from proposal id {}: \ - set {} to {}.", + "Adding Continuous PGF for {} from Proposal {} in the \ + amount of {} per epoch, {}.", + target.target.target(), proposal_id, target.target.amount().to_string_native(), - target.target.target() + if let Some(ep) = target.end_epoch { + format!("until epoch {}", ep) + } else { + "indefinitely".to_string() + } ); - } - AddRemove::Remove(target) => { pgf_keys::fundings_handle() .at(&target.target.target()) - .remove(storage, &proposal_id)?; + .insert(storage, proposal_id, target.clone())?; + } + AddRemove::Remove(target) => { tracing::info!( - "Removed Continuous PGF from proposal id {}: set {} \ - to {}.", + "Removing Continuous PGF for {} from Proposal {} (set \ + to {} native tokens, end epoch: {}).", + target.target.target(), proposal_id, target.target.amount().to_string_native(), - target.target.target() + if let Some(ep) = target.end_epoch { + format!("{}", ep) + } else { + "None".to_string() + } ); + pgf_keys::fundings_handle() + .at(&target.target.target()) + .remove(storage, &proposal_id)?; } }, PGFAction::Retro(target) => { @@ -522,16 +532,16 @@ where match result { Ok(()) => { tracing::info!( - "Execute Retroactive PGF from proposal id {}: \ - sent {} to {}.", + "Execute Retroactive PGF from Proposal {}: {} \ + native tokens transferred to {}.", proposal_id, target.amount().to_string_native(), target.target() ); } Err(e) => tracing::warn!( - "Error in Retroactive PGF transfer from proposal id \ - {}, amount {} to {}: {}", + "Error in Retroactive PGF transfer from Proposal {}, \ + attempt to transfer {} native tokens to {}: {}", proposal_id, target.amount().to_string_native(), target.target(), diff --git a/crates/sdk/src/signing.rs b/crates/sdk/src/signing.rs index 2b6f9c0f23..c2b74e331b 100644 --- a/crates/sdk/src/signing.rs +++ b/crates/sdk/src/signing.rs @@ -1087,9 +1087,6 @@ fn proposal_type_to_ledger_vector( &target.amount.to_string_native() ) )); - output.push(format!("Port ID: {}", target.port_id)); - output - .push(format!("Channel ID: {}", target.channel_id)); output.push(format!( "End Epoch: {}", if let Some(end_epoch) = end_epoch { @@ -1098,6 +1095,9 @@ fn proposal_type_to_ledger_vector( "None".to_string() } )); + output.push(format!("Port ID: {}", target.port_id)); + output + .push(format!("Channel ID: {}", target.channel_id)); } PGFAction::Retro(PGFTarget::Internal(target)) => { output.push("PGF Action : Retro Payment".to_string()); @@ -3099,6 +3099,7 @@ mod test_signing { "PGF Action : Add Continuous Payment".to_string(), format!("Target: {addr}"), "Amount: NAM 0".to_string(), + "End Epoch: 1".to_string(), ], ); output.clear(); @@ -3123,6 +3124,7 @@ mod test_signing { "PGF Action : Remove Continuous Payment".to_string(), format!("Target: {addr}"), "Amount: NAM 0".to_string(), + "End Epoch: 1".to_string(), ], ); output.clear(); @@ -3158,7 +3160,7 @@ mod test_signing { port_id: PortId::transfer(), channel_id: ChannelId::new(16), }), - end_epoch: Some(Epoch::from(1)), + end_epoch: None, }), // TODO: ask Murisi if this is ok )])), &tx, @@ -3172,6 +3174,7 @@ mod test_signing { "PGF Action : Add Continuous Payment".to_string(), "Target: bloop".to_string(), "Amount: NAM 0".to_string(), + "End Epoch: None".to_string(), "Port ID: transfer".to_string(), "Channel ID: channel-16".to_string(), ], @@ -3187,7 +3190,7 @@ mod test_signing { port_id: PortId::transfer(), channel_id: ChannelId::new(16), }), - end_epoch: Some(Epoch::from(1)), + end_epoch: None, }), // TODO: ask Murisi if this is ok )])), &tx, @@ -3201,6 +3204,7 @@ mod test_signing { "PGF Action : Remove Continuous Payment".to_string(), "Target: bloop".to_string(), "Amount: NAM 0".to_string(), + "End Epoch: None".to_string(), "Port ID: transfer".to_string(), "Channel ID: channel-16".to_string(), ], diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 53639efd4d..118a1430f1 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -1263,7 +1263,7 @@ fn pgf_governance_proposal() -> Result<()> { let query_pgf = vec!["query-pgf", "--node", &validator_one_rpc]; let captured = CapturedOutput::of(|| run(&node, Bin::Client, query_pgf)); assert_matches!(captured.result, Ok(_)); - assert!(captured.contains("Pgf stewards:")); + assert!(captured.contains("PGF stewards:")); assert!(captured.contains(&format!("- {}", defaults::albert_address()))); assert!(captured.contains("Reward distribution:")); assert!( @@ -1314,23 +1314,36 @@ fn pgf_governance_proposal() -> Result<()> { let albert = defaults::albert_address(); let bertha = defaults::bertha_address(); let christel = defaults::christel_address(); - let cont_end_epoch = Epoch::from(9); + let cont_end_epoch = Epoch::from(70); let pgf_funding = PgfFunding { - continuous: vec![ContPGFTarget { - target: PGFTarget::Internal(PGFInternalTarget { - amount: token::Amount::from_u64(10), - target: bertha.clone(), - }), - end_epoch: Some(cont_end_epoch), - }], + continuous: vec![ + ContPGFTarget { + target: PGFTarget::Internal(PGFInternalTarget { + amount: token::Amount::from_u64(10), + target: bertha.clone(), + }), + end_epoch: Some(cont_end_epoch), + }, + ContPGFTarget { + target: PGFTarget::Internal(PGFInternalTarget { + amount: token::Amount::from_u64(35), + target: christel.clone(), + }), + end_epoch: None, + }, + ], retro: vec![PGFTarget::Internal(PGFInternalTarget { amount: token::Amount::from_u64(5), - target: christel, + target: christel.clone(), })], }; - let valid_proposal_json_path = - prepare_proposal_data(node.test_dir.path(), albert, pgf_funding, 36); + let valid_proposal_json_path = prepare_proposal_data( + node.test_dir.path(), + albert.clone(), + pgf_funding, + 36, + ); let submit_proposal_args = apply_use_device(vec![ "init-proposal", @@ -1367,13 +1380,16 @@ fn pgf_governance_proposal() -> Result<()> { let query_pgf = vec!["query-pgf", "--node", &validator_one_rpc]; let captured = CapturedOutput::of(|| run(&node, Bin::Client, query_pgf)); assert_matches!(captured.result, Ok(_)); - assert!(captured.contains("Continuous PGF distributions (per epoch):")); - assert!(captured.contains(bertha.to_string().as_str())); - assert!(captured.contains(&format!( - "Prop #1: {} native tokens, end epoch = {}", - token::Amount::from_u64(10).to_string_native(), - cont_end_epoch - ))); + + assert!(captured.contains("Continuous PGF distributions")); + assert!(captured.contains(&format!("- {}", &bertha))); + assert!( + captured.contains("- Prop 1: 0.000010 native tokens, end epoch = 70") + ); + assert!(captured.contains(&format!("- {}", &christel))); + assert!( + captured.contains("- Prop 1: 0.000035 native tokens, end epoch = None") + ); Ok(()) } @@ -1396,7 +1412,7 @@ fn pgf_steward_change_commission() -> Result<()> { let query_pgf = vec!["query-pgf", "--node", &validator_one_rpc]; let captured = CapturedOutput::of(|| run(&node, Bin::Client, query_pgf)); assert_matches!(captured.result, Ok(_)); - assert!(captured.contains("Pgf stewards:")); + assert!(captured.contains("PGF stewards:")); assert!(captured.contains(&format!("- {}", defaults::albert_address()))); assert!(captured.contains("Reward distribution:")); assert!( @@ -1435,7 +1451,7 @@ fn pgf_steward_change_commission() -> Result<()> { let query_pgf = vec!["query-pgf", "--node", &validator_one_rpc]; let captured = CapturedOutput::of(|| run(&node, Bin::Client, query_pgf)); assert_matches!(captured.result, Ok(_)); - assert!(captured.contains("Pgf stewards:")); + assert!(captured.contains("PGF stewards:")); assert!(captured.contains(&format!("- {}", defaults::albert_address()))); assert!(captured.contains("Reward distribution:")); assert!(