-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add router management #60
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
#[test_only] | ||
module router::router_tests { | ||
use aptos_names_v2::test_helper; | ||
use std::vector; | ||
use router::router; | ||
use std::option; | ||
use std::signer::address_of; | ||
|
||
const MAX_MODE: u8 = 1; | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
fun test_initialization( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
assert!(router::get_admin_addr() == @router, 0); | ||
assert!(option::is_none(&router::get_pending_admin_addr()), 1); | ||
assert!(router::get_mode() == 0, 2) | ||
} | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
fun test_accept_admin( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
let users = test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
let user = vector::borrow(&users, 0); | ||
let user_addr = address_of(user); | ||
|
||
router::set_pending_admin(router, user_addr); | ||
assert!(router::get_admin_addr() == @router, 0); | ||
assert!(option::extract(&mut router::get_pending_admin_addr()) == user_addr, 1); | ||
|
||
router::accept_pending_admin(user); | ||
assert!(router::get_admin_addr() == user_addr, 0); | ||
assert!(option::is_none(&router::get_pending_admin_addr()), 1); | ||
} | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
#[expected_failure(abort_code = 327682, location = router)] | ||
fun test_accept_admin_only_pending_admin( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
let users = test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
let user = vector::borrow(&users, 0); | ||
let user_addr = address_of(user); | ||
|
||
router::set_pending_admin(router, user_addr); | ||
assert!(router::get_admin_addr() == @router, 0); | ||
assert!(option::extract(&mut router::get_pending_admin_addr()) == user_addr, 1); | ||
|
||
router::accept_pending_admin(router); | ||
} | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
#[expected_failure(abort_code = 327680, location = router)] | ||
fun test_set_pending_admin_only_admin( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
let users = test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
let user = vector::borrow(&users, 0); | ||
|
||
router::set_pending_admin(user, address_of(user)); | ||
} | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
fun test_set_mode( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
|
||
let i = 0; | ||
while (i <= MAX_MODE) { | ||
router::set_mode(router, i); | ||
assert!(router::get_mode() == i, 0); | ||
i = i + 1 | ||
} | ||
} | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
#[expected_failure(abort_code = 327680, location = router)] | ||
fun test_set_mode_admin_only( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
let users = test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
let user = vector::borrow(&users, 0); | ||
|
||
router::set_mode(user, 0); | ||
} | ||
|
||
#[test( | ||
router = @router, | ||
aptos_names = @aptos_names, | ||
aptos_names_v2 = @aptos_names_v2, | ||
user = @0x077, | ||
aptos = @0x1, | ||
rando = @0x266f, | ||
foundation = @0xf01d | ||
)] | ||
#[expected_failure(abort_code = 65539, location = router)] | ||
fun test_set_mode_invalid_mode( | ||
router: &signer, | ||
aptos_names: &signer, | ||
aptos_names_v2: &signer, | ||
user: signer, | ||
aptos: signer, | ||
rando: signer, | ||
foundation: signer | ||
) { | ||
router::init_module_for_test(router); | ||
test_helper::e2e_test_setup(aptos_names, aptos_names_v2, user, &aptos, rando, &foundation); | ||
|
||
router::set_mode(router, MAX_MODE + 1); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: two spaces :P