Skip to content

Commit

Permalink
finish set config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Sep 3, 2024
1 parent 6183179 commit a9eb982
Show file tree
Hide file tree
Showing 2 changed files with 379 additions and 10 deletions.
21 changes: 15 additions & 6 deletions contracts/src/mcms.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ trait IManyChainMultiSig<TContractState> {
fn get_root_metadata(self: @TContractState) -> RootMetadata;
}

#[derive(Copy, Drop, Serde, starknet::Store)]
#[derive(Copy, Drop, Serde, starknet::Store, PartialEq, Debug)]
struct Signer {
address: EthAddress,
index: u8,
group: u8
}

#[derive(Copy, Drop, Serde, starknet::Store)]
#[derive(Copy, Drop, Serde, starknet::Store, PartialEq)]
struct RootMetadata {
chain_id: u256,
multisig: ContractAddress,
Expand All @@ -67,14 +67,14 @@ struct Op {
}

// does not implement Storage trait because structs cannot support arrays or maps
#[derive(Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde, PartialEq)]
struct Config {
signers: Span<Signer>,
group_quorums: Span<u8>,
group_parents: Span<u8>
}

#[derive(Copy, Drop, Serde, starknet::Store)]
#[derive(Copy, Drop, Serde, starknet::Store, PartialEq)]
struct ExpiringRootAndOpCount {
root: u256,
valid_until: u32,
Expand Down Expand Up @@ -249,11 +249,11 @@ mod ManyChainMultiSig {
};

assert(
to_u256(prev_address) < to_u256(signer_address),
to_u256(prev_address) < to_u256(signer_address.clone()),
'signer address must increase'
);

let signer = self.s_signers.read(signer_address);
let signer = self.get_signer_by_address(signer_address);
assert(signer.address == signer_address, 'invalid signer');

let mut group = signer.group;
Expand Down Expand Up @@ -478,6 +478,7 @@ mod ManyChainMultiSig {
self.s_signers.write(old_signer.address, empty_signer);
// reset _s_config_signers
self._s_config_signers.write(i.into(), empty_signer);
i += 1;
};
// reset _s_config_signers_len
self._s_config_signers_len.write(0);
Expand Down Expand Up @@ -515,6 +516,9 @@ mod ManyChainMultiSig {
i += 1;
};

// length will always be less than MAX_NUM_SIGNERS so try_into will never panic
self._s_config_signers_len.write(signer_addresses.len().try_into().unwrap());

if clear_root {
let op_count = self.s_expiring_root_and_op_count.read().op_count;
self
Expand Down Expand Up @@ -566,6 +570,7 @@ mod ManyChainMultiSig {
while i < NUM_GROUPS {
group_quorums.append(self._s_config_group_quorums.read(i));
group_parents.append(self._s_config_group_parents.read(i));
i += 1;
};

Config {
Expand Down Expand Up @@ -596,6 +601,10 @@ mod ManyChainMultiSig {
) {
let _response = call_contract_syscall(target, selector, data).unwrap_syscall();
}

fn get_signer_by_address(ref self: ContractState, signer_address: EthAddress) -> Signer {
self.s_signers.read(signer_address)
}
}
}

Loading

0 comments on commit a9eb982

Please sign in to comment.