Skip to content

Commit

Permalink
Move title and description from the transaction struct to a proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
udose-everyday committed Oct 16, 2024
1 parent e28a60b commit a1499ca
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
8 changes: 6 additions & 2 deletions contracts/multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ impl Multisig {
token,
amount,
recipient,
title: title.clone(),
description,
};

let creation_timestamp = env.ledger().timestamp();
Expand All @@ -161,6 +159,8 @@ impl Multisig {
status: ProposalStatus::Open,
creation_timestamp,
expiration_timestamp,
title: title.clone(),
description,
};

save_proposal(&env, &proposal);
Expand All @@ -177,6 +177,8 @@ impl Multisig {
pub fn create_update_proposal(
env: Env,
sender: Address,
title: String,
description: String,
new_wasm_hash: BytesN<32>,
expiration_date: Option<u64>,
) -> Result<(), ContractError> {
Expand Down Expand Up @@ -212,6 +214,8 @@ impl Multisig {
status: ProposalStatus::Open,
creation_timestamp,
expiration_timestamp,
title: title.clone(),
description,
};
save_proposal(&env, &proposal);

Expand Down
4 changes: 2 additions & 2 deletions contracts/multisig/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct Proposal {
pub status: ProposalStatus,
pub creation_timestamp: u64,
pub expiration_timestamp: u64,
pub title: String,
pub description: String,
}

#[contracttype]
Expand All @@ -35,8 +37,6 @@ pub struct Transaction {
pub token: Address,
pub amount: u64,
pub recipient: Address,
pub title: String,
pub description: String,
}

#[contracttype]
Expand Down
20 changes: 10 additions & 10 deletions contracts/multisig/src/tests/transaction_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ fn propose_transaction_proposal_full_quorum() {
Proposal {
id: 1,
sender: member1.clone(),
title: String::from_str(&env, "TxTitle#01"),
description: String::from_str(&env, "TxTestDescription"),
proposal: ProposalType::Transaction(Transaction {
token: token.address.clone(),
amount: 10_000,
recipient: recipient.clone(),
title: String::from_str(&env, "TxTitle#01"),
description: String::from_str(&env, "TxTestDescription")
}),
status: ProposalStatus::Open,
creation_timestamp: 0,
Expand Down Expand Up @@ -1479,12 +1479,12 @@ fn multiple_active_proposals() {
Proposal {
id: 1,
sender: member1.clone(),
title: String::from_str(&env, "TxTitle#01"),
description: String::from_str(&env, "TxTestDescription"),
proposal: ProposalType::Transaction(Transaction {
token: token.address.clone(),
amount: 10_000,
recipient: recipient1.clone(),
title: String::from_str(&env, "TxTitle#01"),
description: String::from_str(&env, "TxTestDescription")
}),
status: ProposalStatus::Open,
creation_timestamp: 0,
Expand All @@ -1496,12 +1496,12 @@ fn multiple_active_proposals() {
Proposal {
id: 2,
sender: member3.clone(),
title: String::from_str(&env, "TxTitle#02"),
description: String::from_str(&env, "TxTestDescription"),
proposal: ProposalType::Transaction(Transaction {
token: token.address.clone(),
amount: 15_000,
recipient: recipient2.clone(),
title: String::from_str(&env, "TxTitle#02"),
description: String::from_str(&env, "TxTestDescription")
}),
status: ProposalStatus::Open,
creation_timestamp: 0,
Expand All @@ -1513,12 +1513,12 @@ fn multiple_active_proposals() {
Proposal {
id: 3,
sender: member2.clone(),
title: String::from_str(&env, "TxTitle#03"),
description: String::from_str(&env, "TxTestDescription"),
proposal: ProposalType::Transaction(Transaction {
token: token2.address.clone(),
amount: 5_000,
recipient: recipient1.clone(),
title: String::from_str(&env, "TxTitle#03"),
description: String::from_str(&env, "TxTestDescription")
}),
status: ProposalStatus::Open,
creation_timestamp: 0,
Expand Down Expand Up @@ -1730,12 +1730,12 @@ fn create_and_execute_transaction_proposal_within_deadline() {
Proposal {
id: 1,
sender: member1.clone(),
title: String::from_str(&env, "TxTitle#01"),
description: String::from_str(&env, "TxTestDescription"),
proposal: ProposalType::Transaction(Transaction {
token: token.address.clone(),
amount: 10_000,
recipient: recipient.clone(),
title: String::from_str(&env, "TxTitle#01"),
description: String::from_str(&env, "TxTestDescription")
}),
status: ProposalStatus::Open,
creation_timestamp: 0,
Expand Down
40 changes: 35 additions & 5 deletions contracts/multisig/src/tests/update_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ fn update_proposal_works() {

// it's not actually a new wasm hash, but we need to use it to test the update proposal
let new_wasm_hash = utils::multisig_wasm_hash(&env);
multisig.create_update_proposal(&member1, &new_wasm_hash, &None);
multisig.create_update_proposal(
&member1,
&String::from_str(&env, "update"),
&String::from_str(&env, "description"),
&new_wasm_hash,
&None,
);
assert_eq!(
env.auths(),
std::vec![(
Expand Down Expand Up @@ -193,7 +199,13 @@ fn update_proposal_should_panic_when_sender_not_a_member() {

let new_wasm_hash = utils::multisig_wasm_hash(&env);
assert_eq!(
multisig.try_create_update_proposal(&not_a_member, &new_wasm_hash, &None),
multisig.try_create_update_proposal(
&not_a_member,
&String::from_str(&env, "update"),
&String::from_str(&env, "description"),
&new_wasm_hash,
&None
),
Err(Ok(ContractError::UnauthorizedNotAMember))
);
}
Expand All @@ -220,7 +232,13 @@ fn create_update_proposal_should_fail_when_invalid_expiration_date() {
let new_wasm_hash = utils::multisig_wasm_hash(&env);
// 1 second less than an hour
assert_eq!(
multisig.try_create_update_proposal(&member1, &new_wasm_hash, &Some(3_599)),
multisig.try_create_update_proposal(
&member1,
&String::from_str(&env, "update"),
&String::from_str(&env, "description"),
&new_wasm_hash,
&Some(3_599)
),
Err(Ok(ContractError::InvalidExpirationDate))
);
}
Expand All @@ -246,7 +264,13 @@ fn create_and_execute_update_proposal_with_expiration_date() {

// it's not actually a new wasm hash, but we need to use it to test the update proposal
let new_wasm_hash = utils::multisig_wasm_hash(&env);
multisig.create_update_proposal(&member1, &new_wasm_hash, &Some(TWO_WEEKS_EXPIRATION_DATE));
multisig.create_update_proposal(
&member1,
&String::from_str(&env, "update"),
&String::from_str(&env, "description"),
&new_wasm_hash,
&Some(TWO_WEEKS_EXPIRATION_DATE),
);

let proposal_id = multisig.query_last_proposal_id();

Expand Down Expand Up @@ -301,7 +325,13 @@ fn query_proposal_readiness() {
);

let new_wasm_hash = utils::multisig_wasm_hash(&env);
multisig.create_update_proposal(&member1, &new_wasm_hash, &None);
multisig.create_update_proposal(
&member1,
&String::from_str(&env, "update"),
&String::from_str(&env, "description"),
&new_wasm_hash,
&None,
);

let proposal_id = multisig.query_last_proposal_id();

Expand Down

0 comments on commit a1499ca

Please sign in to comment.