Skip to content

Commit

Permalink
more cleanup from the consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed May 6, 2024
1 parent d716e43 commit f53214e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 44 deletions.
18 changes: 16 additions & 2 deletions src/execution_state.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
use governance::utils::u64_tuple_storage::{TwoU64TupleStorePacking};
use starknet::storage_access::{StorePacking};

const TWO_POW_64: u128 = 0x10000000000000000;
const TWO_POW_64_DIVISOR: NonZero<u128> = 0x10000000000000000;

impl TwoU64TupleStorePacking of StorePacking<(u64, u64), u128> {
fn pack(value: (u64, u64)) -> u128 {
let (a, b) = value;
a.into() + (b.into() * TWO_POW_64)
}

fn unpack(value: u128) -> (u64, u64) {
let (q, r) = DivRem::div_rem(value, TWO_POW_64_DIVISOR);
(r.try_into().unwrap(), q.try_into().unwrap())
}
}

#[derive(Copy, Drop, Serde, PartialEq, Debug)]
pub struct ExecutionState {
pub created: u64,
Expand All @@ -21,6 +35,6 @@ pub(crate) impl ExecutionStateStorePacking of StorePacking<ExecutionState, felt2
fn unpack(value: felt252) -> ExecutionState {
let u256_value: u256 = value.into();
let (created, executed) = TwoU64TupleStorePacking::unpack(u256_value.low);
ExecutionState { created, executed, canceled: (u256_value.high).try_into().unwrap() }
ExecutionState { created, executed, canceled: u256_value.high.try_into().unwrap() }
}
}
12 changes: 10 additions & 2 deletions src/execution_state_test.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use governance::utils::u64_tuple_storage::{ThreeU64TupleStorePacking, TwoU64TupleStorePacking};
use governance::utils::u64_tuple_storage_test::{assert_pack_unpack};
use governance::execution_state::{ExecutionState};
use starknet::storage_access::{StorePacking};

pub(crate) fn assert_pack_unpack<
T, U, +StorePacking<T, U>, +PartialEq<T>, +core::fmt::Debug<T>, +Drop<T>, +Copy<T>
>(
x: T
) {
assert_eq!(x, StorePacking::<T, U>::unpack(StorePacking::<T, U>::pack(x)));
}

#[test]
fn test_three_tuple_storage_forward_back() {
assert_pack_unpack(ExecutionState { created: 123, executed: 234, canceled: 345 });
Expand All @@ -26,4 +33,5 @@ fn test_three_tuple_storage_forward_back() {
assert_pack_unpack(
ExecutionState { created: 0, executed: 0xffffffffffffffff, canceled: 0xffffffffffffffff }
);
assert_pack_unpack(ExecutionState { created: 0, executed: 0xffffffffffffffff, canceled: 0 });
}
1 change: 0 additions & 1 deletion src/governor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub trait IGovernor<TContractState> {
// Get the proposal info for the given proposal id.
fn get_proposal(self: @TContractState, id: felt252) -> ProposalInfo;


// Configure the delay and the window for call execution. This must be self-called via #queue.
fn configure(ref self: TContractState, config: Config);

Expand Down
5 changes: 2 additions & 3 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod call_trait;
#[cfg(test)]
pub(crate) mod call_trait_test;
pub mod execution_state;
#[cfg(test)]
pub(crate) mod execution_state_test;
pub mod governor;
#[cfg(test)]
pub(crate) mod governor_test;
Expand All @@ -18,9 +20,6 @@ pub(crate) mod interfaces {
}
pub(crate) mod utils {
pub(crate) mod exp2;
pub(crate) mod u64_tuple_storage;
#[cfg(test)]
pub(crate) mod u64_tuple_storage_test;
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/staker_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use core::num::traits::zero::{Zero};
use core::option::{OptionTrait};
use core::result::{Result, ResultTrait};
use core::traits::{TryInto};
use governance::execution_state_test::{assert_pack_unpack};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};

use governance::staker::{
IStakerDispatcher, IStakerDispatcherTrait, Staker,
Staker::{DelegatedSnapshotStorePacking, DelegatedSnapshot},
};
use governance::test::test_token::{TestToken, deploy as deploy_token};
use governance::utils::u64_tuple_storage_test::{assert_pack_unpack};
use starknet::testing::{set_contract_address, set_block_timestamp, pop_log};
use starknet::{
get_contract_address, syscalls::deploy_syscall, ClassHash, contract_address_const,
Expand Down
16 changes: 0 additions & 16 deletions src/utils/u64_tuple_storage.cairo

This file was deleted.

19 changes: 0 additions & 19 deletions src/utils/u64_tuple_storage_test.cairo

This file was deleted.

0 comments on commit f53214e

Please sign in to comment.