Skip to content

Commit

Permalink
Fewer modes s + better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BriungRi committed Aug 9, 2023
1 parent 74ffb39 commit 19fe9c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions router/sources/router.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ module router::router {
// NOTE: New enums must update is_valid_mode(mode: u8)
const MODE_V1: u8 = 0;
const MODE_V1_AND_V2: u8 = 1;
const MODE_V2: u8 = 2;
// const MODE_NEXT: u8 = 3;
// const MODE_NEXT: u8 = 2;

// == ERROR CODES ==

/// Caller is not the admin
const ENOT_ADMIN: u64 = 0;
/// There is no pending admin
const ENO_PENDING_ADMIN: u64 = 1;
/// Caller is not the pending admin
const ENOT_PENDING_ADMIN: u64 = 2;
/// Provided mode is not supported
const EINVALID_MODE: u64 = 3;
/// Function is not implemented in the current mode
const ENOT_IMPLEMENTED_IN_MODE: u64 = 4;

// == OTHER CONSTANTS ==

Expand Down Expand Up @@ -86,7 +91,7 @@ module router::router {
}

inline fun is_valid_mode(mode: u8): bool {
mode <= MODE_V2
mode <= MODE_V1_AND_V2
}

public fun get_admin_addr(): address acquires RouterConfig {
Expand Down
6 changes: 3 additions & 3 deletions router/sources/router_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module router::router_tests {
use std::option;
use std::signer::address_of;

const MAX_MODE: u8 = 2;
const MAX_MODE: u8 = 1;

#[test(
router = @router,
Expand Down Expand Up @@ -144,7 +144,7 @@ module router::router_tests {
test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation);

let i = 0;
while (i <= 2) {
while (i <= MAX_MODE) {
router::set_mode(router, i);
assert!(router::get_mode() == i, 0);
i = i + 1
Expand Down Expand Up @@ -199,6 +199,6 @@ module router::router_tests {
router::init_module_for_test(router);
test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation);

router::set_mode(router, 3);
router::set_mode(router, MAX_MODE + 1);
}
}

0 comments on commit 19fe9c3

Please sign in to comment.