-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sui-framework] Reserve addresses for the deny list
- Loading branch information
Showing
4 changed files
with
157 additions
and
14 deletions.
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
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
48 changes: 48 additions & 0 deletions
48
crates/sui-framework/packages/sui-framework/tests/deny_list_tests.move
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,48 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[test_only] | ||
module sui::deny_list_tests { | ||
use sui::deny_list; | ||
use sui::test_scenario; | ||
use std::type_name; | ||
|
||
public struct X() | ||
|
||
#[test, expected_failure(abort_code = sui::deny_list::EInvalidAddress)] | ||
fun add_zero() { | ||
let mut ctx = tx_context::dummy(); | ||
let mut dl = deny_list::new_for_testing(&mut ctx); | ||
let ty = type_name::into_string(type_name::get_with_original_ids<X>()).into_bytes(); | ||
dl.add(1, ty, deny_list::reserved_addresses()[0]); // should error | ||
abort 0 // should not be reached | ||
} | ||
|
||
#[test, expected_failure(abort_code = sui::deny_list::EInvalidAddress)] | ||
fun remove_zero() { | ||
let mut ctx = tx_context::dummy(); | ||
let mut dl = deny_list::new_for_testing(&mut ctx); | ||
let ty = type_name::into_string(type_name::get_with_original_ids<X>()).into_bytes(); | ||
dl.add(1, ty, deny_list::reserved_addresses()[1]); // should error | ||
abort 0 // should not be reached | ||
} | ||
|
||
#[test] | ||
fun contains_zero () { | ||
let mut scenario = test_scenario::begin(@0); | ||
deny_list::create_for_test(scenario.ctx()); | ||
scenario.next_tx(@0); | ||
let dl: deny_list::DenyList = scenario.take_shared(); | ||
let ty = type_name::into_string(type_name::get_with_original_ids<X>()).into_bytes(); | ||
let reserved = deny_list::reserved_addresses(); | ||
let mut i = 0; | ||
let n = reserved.length(); | ||
while (i < n) { | ||
assert!(!dl.contains(1, ty, reserved[i]), 0); | ||
i = i + 1; | ||
}; | ||
test_scenario::return_shared(dl); | ||
scenario.end(); | ||
} | ||
|
||
} |