-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[language][diem-framework] rewrite account_limits/basics.move as unit…
… test
- Loading branch information
1 parent
ed21b8e
commit 8aad1a1
Showing
7 changed files
with
188 additions
and
316 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
Binary file modified
BIN
+0 Bytes
(100%)
...m-framework/DPN/releases/artifacts/current/build/DiemCoreFramework/source_maps/Roles.mvsm
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
#[test_only] | ||
module DiemFramework::AccountLimitsTests { | ||
use Std::Signer; | ||
use DiemFramework::Genesis; | ||
use DiemFramework::AccountLimits; | ||
use DiemFramework::XUS::XUS; | ||
use DiemFramework::Roles; | ||
|
||
struct Hold<T> has key { x: T } | ||
public fun hold<T: store>(account: &signer, x: T) { | ||
move_to(account, Hold<T>{ x }) | ||
} | ||
|
||
fun setup(dr: &signer, tc: &signer, vasp: &signer) { | ||
Genesis::setup(dr, tc); | ||
|
||
Roles::new_parent_vasp_role(tc, vasp); | ||
|
||
AccountLimits::publish_unrestricted_limits_for_testing<XUS>(vasp); | ||
AccountLimits::publish_window<XUS>(dr, vasp, Signer::address_of(vasp)); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 1)] | ||
fun grant_mutation_capability_after_genesis(dr: signer, tc: signer, vasp: signer) { | ||
Genesis::setup(&dr, &tc); | ||
|
||
hold(&vasp, AccountLimits::grant_mutation_capability(&vasp)); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
fun publish_window(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 262)] | ||
fun publish_window_twice(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
|
||
AccountLimits::publish_window<XUS>(&dr, &vasp, Signer::address_of(&vasp)); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 2)] | ||
fun publish_window_non_diem_root(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::publish_window<XUS>(&vasp, &vasp, Signer::address_of(&vasp)); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 5)] | ||
fun publish_window_non_existent_limit_address(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::publish_window<XUS>(&dr, &vasp, @0x42 /* non-exsistent */); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 6)] | ||
fun publish_unrestricted_limits_for_testing_twice(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::publish_unrestricted_limits_for_testing<XUS>(&vasp); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
fun update_limits_definition_1(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::update_limits_definition<XUS>( | ||
&tc, | ||
Signer::address_of(&vasp), | ||
100, /* new_max_inflow */ | ||
200, /* new_max_outflow */ | ||
150, /* new_max_holding_balance */ | ||
10000, /* new_time_period */ | ||
) | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
fun update_limits_definition_2(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::update_limits_definition<XUS>( | ||
&tc, | ||
Signer::address_of(&vasp), | ||
0, /* new_max_inflow */ | ||
0, /* new_max_outflow */ | ||
150, /* new_max_holding_balance */ | ||
10000, /* new_time_period */ | ||
) | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
fun update_limits_definition_twice(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::update_limits_definition<XUS>( | ||
&tc, | ||
Signer::address_of(&vasp), | ||
100, /* new_max_inflow */ | ||
200, /* new_max_outflow */ | ||
150, /* new_max_holding_balance */ | ||
10000, /* new_time_period */ | ||
); | ||
AccountLimits::update_limits_definition<XUS>( | ||
&tc, | ||
Signer::address_of(&vasp), | ||
0, /* new_max_inflow */ | ||
0, /* new_max_outflow */ | ||
150, /* new_max_holding_balance */ | ||
10000, /* new_time_period */ | ||
) | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 258)] | ||
fun update_limits_definition_non_tc(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::update_limits_definition<XUS>( | ||
&dr, | ||
Signer::address_of(&vasp), | ||
100, /* new_max_inflow */ | ||
200, /* new_max_outflow */ | ||
150, /* new_max_holding_balance */ | ||
10000, /* new_time_period */ | ||
) | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 5)] | ||
fun update_limits_definition_non_exsistent(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
AccountLimits::update_limits_definition<XUS>( | ||
&tc, | ||
@0x42, // non-exsistent | ||
100, /* new_max_inflow */ | ||
200, /* new_max_outflow */ | ||
150, /* new_max_holding_balance */ | ||
10000, /* new_time_period */ | ||
) | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
fun update_window_info(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
let vasp_addr = Signer::address_of(&vasp); | ||
AccountLimits::update_window_info<XUS>( | ||
&tc, | ||
vasp_addr, | ||
120, | ||
vasp_addr, | ||
); | ||
AccountLimits::update_window_info<XUS>( | ||
&tc, | ||
vasp_addr, | ||
0, | ||
vasp_addr, | ||
); | ||
AccountLimits::update_window_info<XUS>( | ||
&tc, | ||
vasp_addr, | ||
120, | ||
vasp_addr, | ||
); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
#[expected_failure(abort_code = 258)] | ||
fun update_window_info_non_tc(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
let vasp_addr = Signer::address_of(&vasp); | ||
AccountLimits::update_window_info<XUS>( | ||
&dr, | ||
vasp_addr, | ||
120, | ||
vasp_addr, | ||
); | ||
} | ||
|
||
#[test(dr = @DiemRoot, tc = @TreasuryCompliance, vasp = @0x2)] | ||
fun has_limits_published(dr: signer, tc: signer, vasp: signer) { | ||
setup(&dr, &tc, &vasp); | ||
assert!(AccountLimits::has_limits_published<XUS>(Signer::address_of(&vasp)), 1); | ||
assert!(!AccountLimits::has_limits_published<XUS>(@0x42 /* non-exsistent */), 3); | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
language/move-compiler/functional-tests/tests/diem/account_limits/basics.exp
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.