Skip to content

Commit

Permalink
Make proposal_id a required field in gov proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jan 5, 2024
1 parent 63e6611 commit 5f735e0
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 22 deletions.
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 @@ -126,7 +126,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 @@ -178,7 +178,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 @@ -250,7 +250,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 @@ -20,7 +20,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
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 @@ -180,7 +180,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

0 comments on commit 5f735e0

Please sign in to comment.