From eb04552e27da70564f78d9eb0befdfda981aae66 Mon Sep 17 00:00:00 2001 From: Scott Piriou <30843220+pscott@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:16:49 +0200 Subject: [PATCH] feat: add get_proposal_status --- .../execution_strategies/eth_relayer.cairo | 11 +++++++++ .../execution_strategies/simple_quorum.cairo | 2 +- .../src/execution_strategies/vanilla.cairo | 24 +++++++++++++------ .../src/interfaces/i_execution_strategy.cairo | 11 ++++++++- starknet/src/tests/mocks/executor.cairo | 22 +++++++++++++++++ 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/starknet/src/execution_strategies/eth_relayer.cairo b/starknet/src/execution_strategies/eth_relayer.cairo index 42d570ce..972130e4 100644 --- a/starknet/src/execution_strategies/eth_relayer.cairo +++ b/starknet/src/execution_strategies/eth_relayer.cairo @@ -30,5 +30,16 @@ mod EthRelayerExecutionStrategy { send_message_to_l1_syscall(l1_destination, message_payload); } + + fn get_proposal_status( + self: @TContractState, + proposal: Proposal, + votes_for: u256, + votes_against: u256, + votes_abstain: u256, + ) -> ProposalStatus { + panic_with_felt252('unimplemented'); + ProposalStatus::Cancelled(()) + } } } diff --git a/starknet/src/execution_strategies/simple_quorum.cairo b/starknet/src/execution_strategies/simple_quorum.cairo index 1053ec2d..0dceea3c 100644 --- a/starknet/src/execution_strategies/simple_quorum.cairo +++ b/starknet/src/execution_strategies/simple_quorum.cairo @@ -25,7 +25,7 @@ mod SimpleQuorumExecutionStrategy { proposal: @Proposal, votes_for: u256, votes_against: u256, - votes_abstain: u256 + votes_abstain: u256, ) -> ProposalStatus { let accepted = _quorum_reached(self._quorum.read(), votes_for, votes_against, votes_abstain) & _supported(votes_for, votes_against); diff --git a/starknet/src/execution_strategies/vanilla.cairo b/starknet/src/execution_strategies/vanilla.cairo index 1bb2d631..c2e618b8 100644 --- a/starknet/src/execution_strategies/vanilla.cairo +++ b/starknet/src/execution_strategies/vanilla.cairo @@ -19,13 +19,8 @@ mod VanillaExecutionStrategy { votes_abstain: u256, payload: Array ) { - // TODO: this is probably wrong. - let mut state: SimpleQuorumExecutionStrategy::ContractState = - SimpleQuorumExecutionStrategy::unsafe_new_contract_state(); - - let proposal_status = SimpleQuorumExecutionStrategy::get_proposal_status( - @state, @proposal, votes_for, votes_against, votes_abstain - ); + let proposal_status = self + .get_proposal_status(proposal, votes_for, votes_against, votes_abstain,); assert( (proposal_status == ProposalStatus::Accepted(())) | (proposal_status == ProposalStatus::VotingPeriodAccepted(())), @@ -34,6 +29,21 @@ mod VanillaExecutionStrategy { self._num_executed.write(self._num_executed.read() + 1); } + fn get_proposal_status( + self: @ContractState, + proposal: Proposal, + votes_for: u256, + votes_against: u256, + votes_abstain: u256, + ) -> ProposalStatus { + let mut state: SimpleQuorumExecutionStrategy::ContractState = + SimpleQuorumExecutionStrategy::unsafe_new_contract_state(); + + SimpleQuorumExecutionStrategy::get_proposal_status( + @state, @proposal, votes_for, votes_against, votes_abstain, + ) + } + fn get_strategy_type(self: @ContractState) -> felt252 { 'SimpleQuorumVanilla' } diff --git a/starknet/src/interfaces/i_execution_strategy.cairo b/starknet/src/interfaces/i_execution_strategy.cairo index cfc6a728..51bd7025 100644 --- a/starknet/src/interfaces/i_execution_strategy.cairo +++ b/starknet/src/interfaces/i_execution_strategy.cairo @@ -1,5 +1,6 @@ use array::ArrayTrait; -use sx::types::Proposal; +use sx::types::{Proposal, ProposalStatus}; +use serde::Serde; #[starknet::interface] trait IExecutionStrategy { @@ -12,5 +13,13 @@ trait IExecutionStrategy { payload: Array ); + fn get_proposal_status( + self: @TContractState, + proposal: Proposal, + votes_for: u256, + votes_against: u256, + votes_abstain: u256, + ) -> ProposalStatus; + fn get_strategy_type(self: @TContractState) -> felt252; } diff --git a/starknet/src/tests/mocks/executor.cairo b/starknet/src/tests/mocks/executor.cairo index 351d02f2..9194ea74 100644 --- a/starknet/src/tests/mocks/executor.cairo +++ b/starknet/src/tests/mocks/executor.cairo @@ -34,6 +34,17 @@ mod ExecutorExecutionStrategy { call_contract_syscall(tx.target, tx.selector, tx.data.span()).unwrap(); } + fn get_proposal_status( + self: @ContractState, + proposal: Proposal, + votes_for: u256, + votes_against: u256, + votes_abstain: u256, + ) -> ProposalStatus { + panic_with_felt252('unimplemented'); + ProposalStatus::Cancelled(()) + } + fn get_strategy_type(self: @ContractState) -> felt252 { 'Executor' } @@ -65,6 +76,17 @@ mod ExecutorWithoutTxExecutionStrategy { payload: Array ) {} + fn get_proposal_status( + self: @ContractState, + proposal: Proposal, + votes_for: u256, + votes_against: u256, + votes_abstain: u256, + ) -> ProposalStatus { + panic_with_felt252('unimplemented'); + ProposalStatus::Cancelled(()) + } + fn get_strategy_type(self: @ContractState) -> felt252 { 'ExecutorWithoutTx' }