diff --git a/src/governor.cairo b/src/governor.cairo index bea5926..007b099 100644 --- a/src/governor.cairo +++ b/src/governor.cairo @@ -62,6 +62,11 @@ pub trait IGovernor { // Attaches the given text to the proposal. Simply emits an event containing the proposal description. fn describe(ref self: TContractState, id: felt252, description: ByteArray); + // Combined propose and describe methods + fn propose_and_describe( + ref self: TContractState, calls: Span, description: ByteArray + ) -> felt252; + // Get the staker that is used by this governor contract. fn get_staker(self: @TContractState) -> IStakerDispatcher; @@ -244,6 +249,14 @@ pub mod Governor { self.emit(Described { id, description }); } + fn propose_and_describe( + ref self: ContractState, calls: Span, description: ByteArray + ) -> felt252 { + let id = self.propose(calls); + self.describe(id, description); + id + } + fn vote(ref self: ContractState, id: felt252, yea: bool) { let mut proposal = self.proposals.read(id); diff --git a/src/governor_test.cairo b/src/governor_test.cairo index a0735b2..d0499cd 100644 --- a/src/governor_test.cairo +++ b/src/governor_test.cairo @@ -309,6 +309,34 @@ fn test_describe_proposal_successful() { ); } + +#[test] +fn test_propose_and_describe_successful() { + let (staker, token, governor, config) = setup(); + token.approve(staker.contract_address, config.proposal_creation_threshold.into()); + staker.stake(proposer()); + + advance_time(config.voting_weight_smoothing_duration); + + let address_before = get_contract_address(); + set_contract_address(proposer()); + let id = governor + .propose_and_describe( + array![].span(), + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + ); + set_contract_address(address_before); + + pop_log::(governor.contract_address).unwrap(); + assert_eq!( + pop_log::(governor.contract_address).unwrap(), + Governor::Described { + id, + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + } + ); +} + #[test] #[should_panic(expected: ('NOT_PROPOSER', 'ENTRYPOINT_FAILED'))] fn test_describe_proposal_fails_for_unknown_proposal() {