From 5c1029820bbc32d3fadf71bd0001b68eaa71dc9a Mon Sep 17 00:00:00 2001 From: Scott Piriou <30843220+pscott@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:43:53 +0200 Subject: [PATCH] add IQuorum --- .../execution_strategies/simple_quorum.cairo | 5 ++++ .../src/execution_strategies/vanilla.cairo | 13 ++++++++++- starknet/src/interfaces.cairo | 2 ++ starknet/src/interfaces/i_quorum.cairo | 4 ++++ .../tests/execution_strategies/vanilla.cairo | 23 +++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 starknet/src/interfaces/i_quorum.cairo diff --git a/starknet/src/execution_strategies/simple_quorum.cairo b/starknet/src/execution_strategies/simple_quorum.cairo index 1053ec2d..c9491b05 100644 --- a/starknet/src/execution_strategies/simple_quorum.cairo +++ b/starknet/src/execution_strategies/simple_quorum.cairo @@ -19,6 +19,11 @@ mod SimpleQuorumExecutionStrategy { self._quorum.write(quorum); } + #[internal] + fn quorum(self: @ContractState) -> u256 { + self._quorum.read() + } + #[internal] fn get_proposal_status( self: @ContractState, diff --git a/starknet/src/execution_strategies/vanilla.cairo b/starknet/src/execution_strategies/vanilla.cairo index 1bb2d631..23b34126 100644 --- a/starknet/src/execution_strategies/vanilla.cairo +++ b/starknet/src/execution_strategies/vanilla.cairo @@ -1,14 +1,25 @@ #[starknet::contract] mod VanillaExecutionStrategy { - use sx::interfaces::IExecutionStrategy; + use sx::interfaces::{IExecutionStrategy, IQuorum}; use sx::types::{Proposal, ProposalStatus}; use sx::execution_strategies::simple_quorum::SimpleQuorumExecutionStrategy; + #[storage] struct Storage { _num_executed: felt252 } + #[external(v0)] + impl QuorumImpl of IQuorum { + fn quorum(self: @ContractState) -> u256 { + let mut state: SimpleQuorumExecutionStrategy::ContractState = + SimpleQuorumExecutionStrategy::unsafe_new_contract_state(); + + SimpleQuorumExecutionStrategy::quorum(@state) + } + } + #[external(v0)] impl VanillaExecutionStrategy of IExecutionStrategy { fn execute( diff --git a/starknet/src/interfaces.cairo b/starknet/src/interfaces.cairo index 3b37529f..d0f49df1 100644 --- a/starknet/src/interfaces.cairo +++ b/starknet/src/interfaces.cairo @@ -2,6 +2,7 @@ mod i_voting_strategy; mod i_execution_strategy; mod i_proposal_validation_strategy; mod i_account; +mod i_quorum; use i_voting_strategy::{IVotingStrategy, IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait}; use i_execution_strategy::{ @@ -15,3 +16,4 @@ use i_account::{ AccountABI, AccountABIDispatcher, AccountABIDispatcherTrait, AccountCamelABI, AccountCamelABIDispatcher, AccountCamelABIDispatcherTrait }; +use i_quorum::{IQuorum, IQuorumDispatcher, IQuorumDispatcherTrait}; diff --git a/starknet/src/interfaces/i_quorum.cairo b/starknet/src/interfaces/i_quorum.cairo new file mode 100644 index 00000000..df84c46a --- /dev/null +++ b/starknet/src/interfaces/i_quorum.cairo @@ -0,0 +1,4 @@ +#[starknet::interface] +trait IQuorum { + fn quorum(self: @TContractState) -> u256; +} diff --git a/starknet/src/tests/execution_strategies/vanilla.cairo b/starknet/src/tests/execution_strategies/vanilla.cairo index 795ca46a..c118df4d 100644 --- a/starknet/src/tests/execution_strategies/vanilla.cairo +++ b/starknet/src/tests/execution_strategies/vanilla.cairo @@ -1,6 +1,9 @@ #[cfg(test)] mod tests { + use sx::interfaces::{IQuorum, IQuorumDispatcher, IQuorumDispatcherTrait}; use sx::execution_strategies::vanilla::{VanillaExecutionStrategy}; + use sx::execution_strategies::simple_quorum::SimpleQuorumExecutionStrategy; + use starknet::syscalls::{deploy_syscall}; #[test] #[available_gas(10000000)] @@ -14,4 +17,24 @@ mod tests { assert(strategy_type == 'SimpleQuorumVanilla', 'invalid strategy type'); } + + #[test] + #[available_gas(10000000)] + fn get_quorum() { + let quorum = 42_u256; + let mut constructor_calldata: Array = array![]; + quorum.serialize(ref constructor_calldata); + + let (contract, _) = deploy_syscall( + VanillaExecutionStrategy::TEST_CLASS_HASH.try_into().unwrap(), + 0, + constructor_calldata.span(), + false, + ) + .unwrap(); + + let strat = IQuorumDispatcher { contract_address: contract, }; + + assert(strat.quorum() == quorum, 'invalid quorum'); + } }