Skip to content

Commit

Permalink
add IQuorum
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Aug 30, 2023
1 parent aaa5b80 commit 5c10298
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions starknet/src/execution_strategies/simple_quorum.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion starknet/src/execution_strategies/vanilla.cairo
Original file line number Diff line number Diff line change
@@ -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<ContractState> {
fn quorum(self: @ContractState) -> u256 {
let mut state: SimpleQuorumExecutionStrategy::ContractState =
SimpleQuorumExecutionStrategy::unsafe_new_contract_state();

SimpleQuorumExecutionStrategy::quorum(@state)
}
}

#[external(v0)]
impl VanillaExecutionStrategy of IExecutionStrategy<ContractState> {
fn execute(
Expand Down
2 changes: 2 additions & 0 deletions starknet/src/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -15,3 +16,4 @@ use i_account::{
AccountABI, AccountABIDispatcher, AccountABIDispatcherTrait, AccountCamelABI,
AccountCamelABIDispatcher, AccountCamelABIDispatcherTrait
};
use i_quorum::{IQuorum, IQuorumDispatcher, IQuorumDispatcherTrait};
4 changes: 4 additions & 0 deletions starknet/src/interfaces/i_quorum.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[starknet::interface]
trait IQuorum<TContractState> {
fn quorum(self: @TContractState) -> u256;
}
23 changes: 23 additions & 0 deletions starknet/src/tests/execution_strategies/vanilla.cairo
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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<felt252> = 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');
}
}

0 comments on commit 5c10298

Please sign in to comment.