Skip to content

Commit

Permalink
tests: update according to refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thounyy committed Sep 9, 2024
1 parent afa7a0e commit b6c5226
Show file tree
Hide file tree
Showing 23 changed files with 2,092 additions and 2,159 deletions.
43 changes: 25 additions & 18 deletions packages/actions/sources/config.move
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct Config<T> has store {
// === [PROPOSAL] Public functions ===

// step 1: propose to change the name
public fun propose_name(
public fun propose_config_name(
multisig: &mut Multisig,
key: String,
description: String,
Expand All @@ -67,7 +67,7 @@ public fun propose_name(
// step 2: multiple members have to approve the proposal (multisig::approve_proposal)

// step 3: execute the action and modify Multisig object
public fun execute_name(
public fun execute_config_name(
mut executable: Executable,
multisig: &mut Multisig,
) {
Expand All @@ -77,7 +77,7 @@ public fun execute_name(

// step 1: propose to modify multisig rules (everything touching weights)
// threshold has to be valid (reachable and different from 0 for global)
public fun propose_modify_rules(
public fun propose_config_rules(
multisig: &mut Multisig,
key: String,
description: String,
Expand All @@ -93,7 +93,7 @@ public fun propose_modify_rules(
role_thresholds: vector<u64>,
ctx: &mut TxContext
) {
verify_new_rules(weights, roles, global, role_names, role_thresholds);
verify_new_rules(addresses, weights, roles, global, role_names, role_thresholds);
// verify new rules are valid
let proposal_mut = multisig.create_proposal(
Issuer {},
Expand All @@ -112,7 +112,7 @@ public fun propose_modify_rules(
// step 2: multiple members have to approve the proposal (multisig::approve_proposal)

// step 3: execute the action and modify Multisig object
public fun execute_modify_rules(
public fun execute_config_rules(
mut executable: Executable,
multisig: &mut Multisig,
) {
Expand All @@ -122,7 +122,7 @@ public fun execute_modify_rules(
}

// step 1: propose to update the version
public fun propose_deps(
public fun propose_config_deps(
multisig: &mut Multisig,
key: String,
description: String,
Expand All @@ -149,7 +149,7 @@ public fun propose_deps(
// step 3: execute the proposal and return the action (multisig::execute_proposal)

// step 4: execute the action and modify Multisig object
public fun execute_deps(
public fun execute_config_deps(
mut executable: Executable,
multisig: &mut Multisig,
) {
Expand All @@ -174,9 +174,9 @@ public fun config_name<I: copy + drop>(

public fun new_config_members(
proposal: &mut Proposal,
mut addresses: vector<address>,
mut weights: vector<u64>,
mut roles: vector<vector<String>>,
addresses: vector<address>,
weights: vector<u64>,
mut roles: vector<vector<String>>, // inner vectors can be empty
) {
assert!(
addresses.length() == weights.length() &&
Expand Down Expand Up @@ -204,8 +204,8 @@ public fun config_members<I: copy + drop>(
public fun new_config_thresholds(
proposal: &mut Proposal,
global: u64,
mut role_names: vector<String>,
mut role_thresholds: vector<u64>,
role_names: vector<String>,
role_thresholds: vector<u64>,
) {
assert!(role_names.length() == role_thresholds.length(), ERolesNotSameLength);
assert!(global != 0, EThresholdNull);
Expand All @@ -224,7 +224,10 @@ public fun config_thresholds<I: copy + drop>(
issuer: I,
) {
// threshold modification must be the latest action to be executed to ensure it is reachable
assert!(executable.action_index<Config<Thresholds>>() + 1 == executable.actions_length(), EThresholdNotLastAction);
assert!(
executable.action_index<Config<Thresholds>>() + 1 - executable.next_to_destroy() == executable.actions_length(),
EThresholdNotLastAction
);

let Config { inner } = executable.remove_action(issuer);
*multisig.thresholds_mut(executable, issuer) = inner;
Expand Down Expand Up @@ -253,23 +256,27 @@ public fun config_deps<I: copy + drop>(

fun verify_new_rules(
// members
mut weights: vector<u64>,
mut roles: vector<vector<String>>,
addresses: vector<address>,
weights: vector<u64>,
roles: vector<vector<String>>,
// thresholds
global: u64,
role_names: vector<String>,
role_thresholds: vector<u64>,
) {
let total_weight = weights.fold!(0, |acc, weight| acc + weight);
let total_weight = weights.fold!(0, |acc, weight| acc + weight);
assert!(addresses.length() == weights.length() && addresses.length() == roles.length(), EMembersNotSameLength);
assert!(role_names.length() == role_thresholds.length(), ERolesNotSameLength);
assert!(total_weight >= global, EThresholdTooHigh);
assert!(global != 0, EThresholdNull);

let mut weights_for_role: VecMap<String, u64> = vec_map::empty();
weights.zip_do!(roles, |weight, roles_for_addr| {
roles_for_addr.do!(|role| {
if (weights_for_role.contains(&role)) {
weights_for_role.insert(role, weight);
} else {
*weights_for_role.get_mut(&role) = weight;
} else {
weights_for_role.insert(role, weight);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/sources/kiosk.move
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public fun take<O: key + store, I: copy + drop>(
let lock_mut = borrow_lock_mut(multisig, name);
assert!(take_mut.recipient == ctx.sender(), EWrongReceiver);

let nft_id = take_mut.nft_ids.pop_back();
let nft_id = take_mut.nft_ids.remove(0);
multisig_kiosk.list<O>(&lock_mut.kiosk_owner_cap, nft_id, 0);
let (nft, mut request) = multisig_kiosk.purchase<O>(nft_id, coin::zero<SUI>(ctx));

Expand Down
Loading

0 comments on commit b6c5226

Please sign in to comment.