Skip to content

Commit

Permalink
tests: config
Browse files Browse the repository at this point in the history
  • Loading branch information
thounyy committed Oct 24, 2024
1 parent b5baa9c commit ecc8d26
Show file tree
Hide file tree
Showing 4 changed files with 556 additions and 239 deletions.
7 changes: 3 additions & 4 deletions packages/actions/sources/config.move
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const EMetadataNameMissing: vector<u8> = b"New metadata must set a name for the
#[error]
const ENameCannotBeEmpty: vector<u8> = b"Name cannot be empty";
#[error]
const EUpgradeCapDoesntExist: vector<u8> = b"Upgrade Cap does not exist";
const ENoExtensionOrUpgradeCap: vector<u8> = b"No extension or upgrade cap for this package";

// === Structs ===

Expand Down Expand Up @@ -217,11 +217,10 @@ public fun new_config_deps<Config, Outcome, W: drop>(

if (extensions.is_extension(name, package, version)) {
deps.add(extensions, name, package, version);
} else {
assert!(upgrade_policies::has_lock(account, package), EUpgradeCapDoesntExist);
} else if (upgrade_policies::has_lock(account, package)) {
let cap = upgrade_policies::borrow_lock(account, package).upgrade_cap();
deps.add_with_upgrade_cap(cap, name, package, version);
};
} else abort ENoExtensionOrUpgradeCap;
});

proposal.add_action(ConfigDepsAction { deps }, witness);
Expand Down
4 changes: 2 additions & 2 deletions packages/actions/sources/upgrade_policies.move
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public fun has_rule<K: copy + drop + store>(
/// Attaches the UpgradeLock as a Dynamic Field to the account
public fun lock_cap<Config, Outcome>(
auth: Auth,
lock: UpgradeLock,
account: &mut Account<Config, Outcome>,
lock: UpgradeLock,
) {
auth.verify(account.addr());
account.add_managed_asset(
Expand All @@ -135,7 +135,7 @@ public fun lock_cap_with_timelock<Config, Outcome>(
) {
let mut lock = new_lock(upgrade_cap, name, ctx);
add_rule(&mut lock, TimeLockKey {}, TimeLock { delay_ms });
lock_cap(auth, lock, account);
lock_cap(auth, account, lock);
}

public fun has_lock<Config, Outcome>(
Expand Down
24 changes: 12 additions & 12 deletions packages/actions/tests/access_control_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fun create_dummy_proposal(
outcome,
version::current(),
DummyProposal(),
b"Degen".to_string(),
b"".to_string(),
b"dummy".to_string(),
b"".to_string(),
0,
Expand Down Expand Up @@ -111,7 +111,7 @@ fun test_propose_execute_access() {
let (mut scenario, extensions, mut account, clock) = start();
let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
let outcome = multisig::new_outcome(&account, scenario.ctx());
Expand Down Expand Up @@ -142,7 +142,7 @@ fun test_propose_execute_access() {
#[test]
fun test_access_flow() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand Down Expand Up @@ -172,7 +172,7 @@ fun test_access_flow() {
fun test_access_expired() {
let (mut scenario, extensions, mut account, mut clock) = start();
clock.increment_for_testing(1);
let key = b"key".to_string();
let key = b"dummy".to_string();

let mut proposal = create_dummy_proposal(&mut scenario, &mut account, &extensions);

Expand Down Expand Up @@ -203,7 +203,7 @@ fun test_error_lock_cap_already_locked() {
#[test, expected_failure(abort_code = access_control::ENoLock)]
fun test_error_propose_access_no_lock() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
let outcome = multisig::new_outcome(&account, scenario.ctx());
Expand All @@ -224,7 +224,7 @@ fun test_error_propose_access_no_lock() {
#[test, expected_failure(abort_code = access_control::ENoLock)]
fun test_error_access_no_lock() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let mut proposal = create_dummy_proposal(&mut scenario, &mut account, &extensions);

Expand All @@ -245,7 +245,7 @@ fun test_error_access_no_lock() {
#[test, expected_failure(abort_code = access_control::EWrongAccount)]
fun test_error_return_to_wrong_account() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand Down Expand Up @@ -273,7 +273,7 @@ fun test_error_return_to_wrong_account() {
#[test, expected_failure(abort_code = issuer::EWrongAccount)]
fun test_error_access_from_wrong_account() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand Down Expand Up @@ -302,7 +302,7 @@ fun test_error_access_from_wrong_account() {
#[test, expected_failure(abort_code = issuer::EWrongWitness)]
fun test_error_access_from_wrong_constructor_witness() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand All @@ -326,7 +326,7 @@ fun test_error_access_from_wrong_constructor_witness() {
#[test, expected_failure(abort_code = deps::ENotDep)]
fun test_error_access_from_not_dep() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand All @@ -350,7 +350,7 @@ fun test_error_access_from_not_dep() {
#[test, expected_failure(abort_code = issuer::EWrongWitness)]
fun test_error__destroy_access_from_wrong_constructor_witness() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand All @@ -375,7 +375,7 @@ fun test_error__destroy_access_from_wrong_constructor_witness() {
#[test, expected_failure(abort_code = deps::ENotDep)]
fun test_error_destroy_access_from_not_dep() {
let (mut scenario, extensions, mut account, clock) = start();
let key = b"key".to_string();
let key = b"dummy".to_string();

let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx());
access_control::lock_cap(auth, &mut account, cap(&mut scenario));
Expand Down
Loading

0 comments on commit ecc8d26

Please sign in to comment.