Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add get_strategy_type #525

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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