Skip to content

Commit

Permalink
Merge branch 'tiago+gian/required-proposal-id' (#2365)
Browse files Browse the repository at this point in the history
* tiago+gian/required-proposal-id:
  Changelog #2365
  `prepare_proposal_data` test helper requires proposal id
  Fix docstr errs
  Make `proposal_id` a required field in gov proposals
  • Loading branch information
brentstone committed Jan 10, 2024
2 parents 9bc5d94 + a4fa318 commit aefd723
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- When constructing a governance proposal the id is now a required field.
([\#2365](https://github.com/anoma/namada/pull/2365))
2 changes: 1 addition & 1 deletion apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl Default for BenchShell {
let signed_tx = bench_shell.generate_tx(
TX_INIT_PROPOSAL_WASM,
InitProposalData {
id: None,
id: 0,
content: content_section.get_hash(),
author: defaults::albert_address(),
r#type: ProposalType::Default(None),
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ mod test_finalize_block {
shell.proposal_data.insert(proposal_id);

let proposal = InitProposalData {
id: Some(proposal_id),
id: proposal_id,
content: Hash::default(),
author: validator.clone(),
voting_start_epoch: Epoch::default(),
Expand Down
6 changes: 3 additions & 3 deletions benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn governance(c: &mut Criterion) {
shell.generate_tx(
TX_INIT_PROPOSAL_WASM,
InitProposalData {
id: None,
id: 0,
content: content_section.get_hash(),
author: defaults::albert_address(),
r#type: ProposalType::Default(None),
Expand Down Expand Up @@ -174,7 +174,7 @@ fn governance(c: &mut Criterion) {
shell.generate_tx(
TX_INIT_PROPOSAL_WASM,
InitProposalData {
id: Some(1),
id: 1,
content: content_section.get_hash(),
author: defaults::albert_address(),
r#type: ProposalType::Default(Some(
Expand Down Expand Up @@ -246,7 +246,7 @@ fn governance(c: &mut Criterion) {
// let governance_proposal = shell.generate_tx(
// TX_INIT_PROPOSAL_WASM,
// InitProposalData {
// id: None,
// id: 0,
// content: content_section.get_hash(),
// author: defaults::albert_address(),
// r#type: ProposalType::Default(None),
Expand Down
4 changes: 2 additions & 2 deletions benches/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ fn init_proposal(c: &mut Criterion) {
shell.generate_tx(
TX_INIT_PROPOSAL_WASM,
InitProposalData {
id: None,
id: 0,
content: content_section.get_hash(),
author: defaults::albert_address(),
r#type: ProposalType::Default(None),
Expand Down Expand Up @@ -512,7 +512,7 @@ fn init_proposal(c: &mut Criterion) {
shell.generate_tx(
TX_INIT_PROPOSAL_WASM,
InitProposalData {
id: Some(1),
id: 1,
content: content_section.get_hash(),
author: defaults::albert_address(),
r#type: ProposalType::Default(Some(
Expand Down
2 changes: 1 addition & 1 deletion core/src/ledger/governance/cli/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::types::storage::Epoch;
/// The proposal structure
pub struct OnChainProposal {
/// The proposal id
pub id: Option<u64>,
pub id: u64,
/// The proposal content
pub content: BTreeMap<String, String>,
/// The proposal author address
Expand Down
9 changes: 4 additions & 5 deletions core/src/ledger/storage_api/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ where
S: StorageRead + StorageWrite,
{
let counter_key = governance_keys::get_counter_key();
let proposal_id = if let Some(id) = data.id {
id
} else {
storage.read(&counter_key)?.unwrap()
};
let proposal_id = storage.read(&counter_key)?.expect(
"Storage should have been initialized with an initial governance \
proposal id",
);

let content_key = governance_keys::get_content_key(proposal_id);
storage.write_bytes(&content_key, content)?;
Expand Down
8 changes: 5 additions & 3 deletions core/src/types/dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ impl Dec {
/// the division is impossible (e.g., division by zero or overflow), `None`
/// is returned.
///
/// Example:
/// ```
///
/// For instance:
///
/// ```ignore
/// let x = Dec::new(3, 1).unwrap(); // Represents 0.3
/// let y = Dec::new(2, 1).unwrap(); // Represents 0.2
/// let result = x.trunc_div(&y).unwrap();
/// assert_eq!(result, Dec::new(15, 1).unwrap()); // Result is 1.5 truncated to 1 decimal place
/// ```
///
/// # Arguments
///
/// * `rhs`: The right-hand side `Dec` value for the division.
///
/// # Returns
///
/// An `Option<Dec>` which is `Some` with the result if the division is
/// successful, or `None` if the division cannot be performed.
pub fn trunc_div(&self, rhs: &Self) -> Option<Self> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/types/transaction/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum ProposalError {
)]
pub struct InitProposalData {
/// The proposal id
pub id: Option<u64>,
pub id: u64,
/// The proposal content
pub content: Hash,
/// The proposal author address
Expand Down Expand Up @@ -170,7 +170,7 @@ pub mod tests {
prop_compose! {
/// Generate a proposal initialization
pub fn arb_init_proposal()(
id: Option<u64>,
id: u64,
content in arb_hash(),
author in arb_non_internal_address(),
r#type in arb_proposal_type(),
Expand Down
2 changes: 1 addition & 1 deletion light_sdk/src/transaction/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl InitProposal {
/// Build a raw InitProposal transaction from the given parameters
#[allow(clippy::too_many_arguments)]
pub fn new(
id: Option<u64>,
id: u64,
content: Hash,
author: Address,
r#type: ProposalType,
Expand Down
9 changes: 3 additions & 6 deletions sdk/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,7 @@ pub async fn to_ledger_vector(
.hash();

tv.output.push("Type : Init proposal".to_string());
if let Some(id) = init_proposal_data.id.as_ref() {
tv.output.push(format!("ID : {}", id));
}
tv.output.push(format!("ID : {}", init_proposal_data.id));
tv.output.extend(vec![
format!(
"Proposal type : {}",
Expand All @@ -1107,9 +1105,8 @@ pub async fn to_ledger_vector(
format!("Content : {}", HEXLOWER.encode(&extra.0)),
]);

if let Some(id) = init_proposal_data.id.as_ref() {
tv.output_expert.push(format!("ID : {}", id));
}
tv.output_expert
.push(format!("ID : {}", init_proposal_data.id));
tv.output_expert.extend(vec![
format!(
"Proposal type : {}",
Expand Down
9 changes: 7 additions & 2 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,7 @@ fn proposal_submission() -> Result<()> {
let albert = find_address(&test, ALBERT)?;
let valid_proposal_json_path = prepare_proposal_data(
&test,
0,
albert,
TestWasms::TxProposalCode.read_bytes(),
12,
Expand Down Expand Up @@ -1886,6 +1887,7 @@ fn proposal_submission() -> Result<()> {
let albert = find_address(&test, ALBERT)?;
let invalid_proposal_json = prepare_proposal_data(
&test,
1,
albert,
TestWasms::TxProposalCode.read_bytes(),
1,
Expand Down Expand Up @@ -2144,7 +2146,7 @@ fn pgf_governance_proposal() -> Result<()> {
};

let valid_proposal_json_path =
prepare_proposal_data(&test, albert, pgf_stewards, 12);
prepare_proposal_data(&test, 0, albert, pgf_stewards, 12);
let validator_one_rpc = get_actor_rpc(&test, Who::Validator(0));

let submit_proposal_args = vec![
Expand Down Expand Up @@ -2333,7 +2335,7 @@ fn pgf_governance_proposal() -> Result<()> {
};

let valid_proposal_json_path =
prepare_proposal_data(&test, albert, pgf_funding, 36);
prepare_proposal_data(&test, 1, albert, pgf_funding, 36);
let validator_one_rpc = get_actor_rpc(&test, Who::Validator(0));

let submit_proposal_args = vec![
Expand Down Expand Up @@ -2929,6 +2931,7 @@ fn implicit_account_reveal_pk() -> Result<()> {
let author = find_address(&test, source).unwrap();
let valid_proposal_json_path = prepare_proposal_data(
&test,
0,
author,
TestWasms::TxProposalCode.read_bytes(),
12,
Expand Down Expand Up @@ -3045,12 +3048,14 @@ fn test_epoch_sleep() -> Result<()> {
/// This can be submitted with "init-proposal" command.
pub fn prepare_proposal_data(
test: &setup::Test,
id: u64,
source: Address,
data: impl serde::Serialize,
start_epoch: u64,
) -> PathBuf {
let valid_proposal_json = json!({
"proposal": {
"id": id,
"content": {
"title": "TheTitle",
"authors": "[email protected]",
Expand Down

0 comments on commit aefd723

Please sign in to comment.