Skip to content

Commit

Permalink
Add optional category to proposal (#8)
Browse files Browse the repository at this point in the history
* add category arg, update test

* add test

* add docs
  • Loading branch information
amityadav0 authored Sep 26, 2023
1 parent 1a4a44b commit 544ff32
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ ProposalKind::ChangePolicyUpdateParameters { .. },
- `proposal`
- `description`
- `kind`
- `category` [optional]
- proposer account ID
- attached deposit (minimum 1 Ⓝ)

Expand All @@ -324,7 +325,8 @@ ProposalKind::ChangePolicyUpdateParameters { .. },
"kind": {
"AddMemberToRole": {
"member_id": "council_member_3.testnet",
"role": "council"
"role": "council",
"category": "legal"
}
}
}
Expand All @@ -340,7 +342,7 @@ ProposalKind::ChangePolicyUpdateParameters { .. },

```bash
near call genesis.astra.testnet add_proposal \
'{"proposal": {"description": "Add New Council", "kind": {"AddMemberToRole": {"member_id": "council_member_3.testnet", "role": "council"}}}}' \
'{"proposal": {"description": "Add New Council", "kind": {"AddMemberToRole": {"member_id": "council_member_3.testnet", "role": "council", "category": "marketing"}}}}' \
--accountId proposer.testnet \
--amount 1
```
Expand Down
2 changes: 2 additions & 0 deletions astra/src/bounties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl Contract {
bounty_id: id,
receiver_id: sender_id.clone(),
},
category: None
});
claims[claim_idx].completed = true;
self.bounty_claimers.insert(&sender_id, &claims);
Expand Down Expand Up @@ -227,6 +228,7 @@ mod tests {
max_deadline: U64::from(1_000),
},
},
category: None
});
assert_eq!(contract.get_last_bounty_id(), id);
contract.act_proposal(id, Action::VoteApprove, None, Some(false));
Expand Down
22 changes: 22 additions & 0 deletions astra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ mod tests {
amount: U128(parse_near!("100 N")),
msg: None,
},
category: None
})
}

Expand Down Expand Up @@ -399,6 +400,7 @@ mod tests {
member_id: accounts(2),
role: "council".to_string(),
},
category: None
});
}

Expand Down Expand Up @@ -479,6 +481,7 @@ mod tests {
member_id: accounts(2),
role: "missing".to_string(),
},
category: None
});
contract.act_proposal(id, Action::VoteApprove, None, None);
let x = contract.get_policy();
Expand Down Expand Up @@ -535,6 +538,7 @@ mod tests {
kind: ProposalKind::ChangePolicy {
policy: VersionedPolicy::Default(vec![]),
},
category: None
});
}

Expand Down Expand Up @@ -593,6 +597,7 @@ mod tests {
member_id: accounts(2),
role: "Council".to_string(),
},
category: None
});
}

Expand Down Expand Up @@ -630,6 +635,7 @@ mod tests {
fn test_dissolve_missing_proposals() {
let (mut context, mut contract, id)= setup_ctr();
assert_eq!(contract.get_proposal(id).id, id);
assert!(contract.get_proposal(id).proposal.category.is_none());

let mut res = contract.policy.get().unwrap().to_policy();
assert!(!res.roles.is_empty());
Expand All @@ -646,4 +652,20 @@ mod tests {
// remove all proposals, should not throw error because of missing prop
contract.finalize_dissolve(0, 5);
}

#[test]
fn test_category() {
let (_, mut contract, id)= setup_ctr();
let id = contract.add_proposal(ProposalInput {
description: "test".to_string(),
kind: ProposalKind::AddMemberToRole {
member_id: accounts(2),
role: "Council".to_string(),
},
category: Some("legal".to_string())
});

assert!(contract.get_proposal(id).proposal.category.is_some());
assert_eq!(contract.get_proposal(id).proposal.category.unwrap(), "legal".to_string());
}
}
5 changes: 5 additions & 0 deletions astra/src/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ pub struct Proposal {
pub votes: HashMap<AccountId, Vote>,
/// Submission time (for voting period).
pub submission_time: U64,
/// Category of this proposal
pub category: Option<String>
}

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
Expand Down Expand Up @@ -233,6 +235,8 @@ pub struct ProposalInput {
pub description: String,
/// Kind of proposal with relevant information.
pub kind: ProposalKind,
/// Category of proposal
pub category: Option<String>
}

impl From<ProposalInput> for Proposal {
Expand All @@ -245,6 +249,7 @@ impl From<ProposalInput> for Proposal {
vote_counts: HashMap::default(),
votes: HashMap::default(),
submission_time: U64::from(env::block_timestamp()),
category: input.category
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion astra/tests/test_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async fn test_multi_council() -> anyhow::Result<()> {
kind: ProposalKind::ChangePolicy {
policy: VersionedPolicy::Current(new_policy.clone()),
},
category: None
};
let res2 = root.call(dao_contract.id(), "add_proposal")
.args_json(json!({"proposal": proposal}))
Expand Down Expand Up @@ -325,7 +326,8 @@ async fn proposal_tests() -> anyhow::Result<()> {
let config = Config { name: "astra".to_string(), purpose: "testing".to_string(), metadata: Base64VecU8("".to_string().into()) };
let proposal = ProposalInput {
description: "rename the dao".to_string(),
kind: ProposalKind::ChangeConfig { config }
kind: ProposalKind::ChangeConfig { config },
category: None
};
let res = root
.call(dao.id(), "add_proposal")
Expand Down Expand Up @@ -418,6 +420,7 @@ async fn test_create_dao_and_use_token() -> anyhow::Result<()> {
kind: ProposalKind::SetStakingContract {
staking_id: staking.id().parse().unwrap(),
},
category: None
};
let res = user2
.call(dao.id(), "add_proposal")
Expand Down Expand Up @@ -571,6 +574,7 @@ async fn test_failurestest_create_dao_and_use_token() -> anyhow::Result<()> {
amount: U128(1_000_000),
msg: Some("some".to_string()),
},
category: None
};
let res = root
.call(dao.id(), "add_proposal")
Expand Down
4 changes: 3 additions & 1 deletion astra/tests/test_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ async fn test_upgrade_using_factory() -> anyhow::Result<()> {

let proposal = ProposalInput {
description: "proposal to test".to_string(),
kind: ProposalKind::UpgradeSelf { hash }
kind: ProposalKind::UpgradeSelf { hash },
category: None
};
let res = root
.call(&dao, "add_proposal")
Expand Down Expand Up @@ -113,6 +114,7 @@ async fn test_upgrade_other() -> anyhow::Result<()> {
method_name: "upgrade".to_string(),
hash,
},
category: None
};
let res = root
.call(dao.id(), "add_proposal")
Expand Down
3 changes: 3 additions & 0 deletions astra/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub async fn add_member_proposal(
member_id,
role: "council".to_string(),
},
category: None
};
let res = root
.call(dao.id(), "add_proposal")
Expand Down Expand Up @@ -98,6 +99,7 @@ pub async fn add_transfer_proposal(
amount: U128(amount),
msg,
},
category: None
};
let res = root
.call(dao.id(), "add_proposal")
Expand All @@ -123,6 +125,7 @@ pub async fn add_bounty_proposal(root: Account, dao: &Contract) -> anyhow::Resul
max_deadline: U64(env::block_timestamp() + 10_000_000_000),
},
},
category: None
};
let res = root
.call(dao.id(), "add_proposal")
Expand Down

0 comments on commit 544ff32

Please sign in to comment.