Skip to content

Commit

Permalink
add vote_registry view function
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Aug 30, 2023
1 parent aaa5b80 commit 8124467
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions starknet/src/space/space.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ trait ISpace<TContractState> {
fn active_voting_strategies(self: @TContractState) -> u256;
fn next_voting_strategy_index(self: @TContractState) -> u8;
fn proposal_validation_strategy(self: @TContractState) -> Strategy;
// #[view]
fn vote_power(self: @TContractState, proposal_id: u256, choice: Choice) -> u256;
// #[view]
// fn vote_registry(proposal_id: u256, voter: ContractAddress) -> bool;
fn vote_registry(self: @TContractState, proposal_id: u256, voter: UserAddress) -> bool;
fn proposals(self: @TContractState, proposal_id: u256) -> Proposal;
// #[view]
// fn get_proposal_status(proposal_id: u256) -> u8;

// Owner Actions
fn update_settings(ref self: TContractState, input: UpdateSettingsCalldata);
Expand Down Expand Up @@ -745,6 +741,10 @@ mod Space {
}
}

fn vote_registry(self: @ContractState, proposal_id: u256, voter: UserAddress) -> bool {
self._vote_registry.read((proposal_id, voter))
}

fn vote_power(self: @ContractState, proposal_id: u256, choice: Choice) -> u256 {
self._vote_power.read((proposal_id, choice))
}
Expand Down
3 changes: 3 additions & 0 deletions starknet/src/tests/vote.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mod tests {
ArrayTrait::<felt252>::new().serialize(ref vote_calldata);

authenticator.authenticate(space.contract_address, VOTE_SELECTOR, vote_calldata);
assert(space.vote_registry(proposal_id, voter) == true, 'vote registry incorrect');
assert(space.vote_power(proposal_id, Choice::For(())) == 1, 'Vote power should be 1');
assert(space.vote_power(proposal_id, Choice::Against(())) == 0, 'Vote power should be 0');
assert(space.vote_power(proposal_id, Choice::Abstain(())) == 0, 'Vote power should be 0');
Expand Down Expand Up @@ -123,6 +124,7 @@ mod tests {
ArrayTrait::<felt252>::new().serialize(ref vote_calldata);

authenticator.authenticate(space.contract_address, VOTE_SELECTOR, vote_calldata);
assert(space.vote_registry(proposal_id, voter) == true, 'vote registry incorrect');
assert(space.vote_power(proposal_id, Choice::For(())) == 0, 'Vote power should be 0');
assert(space.vote_power(proposal_id, Choice::Against(())) == 1, 'Vote power should be 1');
assert(space.vote_power(proposal_id, Choice::Abstain(())) == 0, 'Vote power should be 0');
Expand Down Expand Up @@ -157,6 +159,7 @@ mod tests {
ArrayTrait::<felt252>::new().serialize(ref vote_calldata);

authenticator.authenticate(space.contract_address, VOTE_SELECTOR, vote_calldata);
assert(space.vote_registry(proposal_id, voter) == true, 'vote registry incorrect');
assert(space.vote_power(proposal_id, Choice::For(())) == 0, 'Vote power should be 0');
assert(space.vote_power(proposal_id, Choice::Against(())) == 0, 'Vote power should be 0');
assert(space.vote_power(proposal_id, Choice::Abstain(())) == 1, 'Vote power should be 1');
Expand Down

0 comments on commit 8124467

Please sign in to comment.