Skip to content

Commit

Permalink
chore: add get_strategy_type (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott authored Aug 30, 2023
1 parent d75fe00 commit aaa5b80
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions starknet/src/execution_strategies/vanilla.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ mod VanillaExecutionStrategy {
);
self._num_executed.write(self._num_executed.read() + 1);
}

fn get_strategy_type(self: @ContractState) -> felt252 {
'SimpleQuorumVanilla'
}
}

#[constructor]
Expand Down
2 changes: 2 additions & 0 deletions starknet/src/interfaces/i_execution_strategy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ trait IExecutionStrategy<TContractState> {
votes_abstain: u256,
payload: Array<felt252>
);

fn get_strategy_type(self: @TContractState) -> felt252;
}
1 change: 1 addition & 0 deletions starknet/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod test_space;
mod test_upgrade;
mod test_stark_tx_auth;

mod execution_strategies;
mod proposal_validation_strategies;
mod voting_strategies;

Expand Down
1 change: 1 addition & 0 deletions starknet/src/tests/execution_strategies.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod vanilla;
17 changes: 17 additions & 0 deletions starknet/src/tests/execution_strategies/vanilla.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[cfg(test)]
mod tests {
use sx::execution_strategies::vanilla::{VanillaExecutionStrategy};

#[test]
#[available_gas(10000000)]
fn get_strategy_type() {
let mut state: VanillaExecutionStrategy::ContractState =
VanillaExecutionStrategy::unsafe_new_contract_state();

let strategy_type = VanillaExecutionStrategy::VanillaExecutionStrategy::get_strategy_type(
@state
);

assert(strategy_type == 'SimpleQuorumVanilla', 'invalid strategy type');
}
}
8 changes: 8 additions & 0 deletions starknet/src/tests/mocks/executor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ mod ExecutorExecutionStrategy {
let tx: Transaction = Serde::<Transaction>::deserialize(ref sp4n).unwrap();
call_contract_syscall(tx.target, tx.selector, tx.data.span()).unwrap();
}

fn get_strategy_type(self: @ContractState) -> felt252 {
'Executor'
}
}

#[constructor]
Expand Down Expand Up @@ -60,6 +64,10 @@ mod ExecutorWithoutTxExecutionStrategy {
votes_abstain: u256,
payload: Array<felt252>
) {}

fn get_strategy_type(self: @ContractState) -> felt252 {
'ExecutorWithoutTx'
}
}

#[constructor]
Expand Down

0 comments on commit aaa5b80

Please sign in to comment.