Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Feb 27, 2025
1 parent b5b65f2 commit 8177ad2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 48 deletions.
12 changes: 6 additions & 6 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:", "");
Expand All @@ -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(),
Expand Down
42 changes: 26 additions & 16 deletions crates/governance/src/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(),
Expand Down
14 changes: 9 additions & 5 deletions crates/sdk/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
],
Expand All @@ -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,
Expand All @@ -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(),
],
Expand Down
58 changes: 37 additions & 21 deletions crates/tests/src/integration/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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!(
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit 8177ad2

Please sign in to comment.