Skip to content

Commit

Permalink
[deny list v2] Added additional transactional tests (MystenLabs#18600)
Browse files Browse the repository at this point in the history
## Description 

- Added transactional tests around specific underlying config behavior 
- Cannot yet add config specific tests as those APIs are not `public`

## Test plan 

- New tests 

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:

---------

Co-authored-by: ronny-mysten <[email protected]>
  • Loading branch information
tnowacki and ronny-mysten authored Jul 12, 2024
1 parent 5f7b890 commit 8cc4a8d
Show file tree
Hide file tree
Showing 8 changed files with 957 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
processed 12 tasks

init:
A: object(0,0), B: object(0,1)

task 1 'publish'. lines 9-53:
created: object(1,0), object(1,1), object(1,2), object(1,3), object(1,4), object(1,5)
mutated: object(0,0)
unchanged_shared: 0x0000000000000000000000000000000000000000000000000000000000000403
gas summary: computation_cost: 1000000, storage_cost: 20428800, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'run'. lines 54-56:
events: Event { package_id: sui, transaction_module: Identifier("coin"), sender: A, type_: StructTag { address: sui, module: Identifier("deny_list"), name: Identifier("PerTypeConfigCreated"), type_params: [] }, contents: [0, 0, 0, 0, 0, 0, 0, 0, 96, 48, 51, 51, 49, 100, 56, 101, 49, 98, 99, 98, 101, 55, 102, 100, 51, 97, 54, 101, 48, 97, 102, 102, 55, 99, 56, 56, 98, 50, 53, 97, 57, 54, 51, 102, 48, 51, 56, 102, 48, 51, 98, 97, 49, 53, 48, 51, 101, 48, 53, 98, 57, 56, 49, 102, 102, 101, 98, 56, 56, 98, 101, 98, 52, 58, 58, 114, 101, 103, 117, 108, 97, 116, 101, 100, 95, 99, 111, 105, 110, 58, 58, 82, 69, 71, 85, 76, 65, 84, 69, 68, 95, 67, 79, 73, 78, 116, 239, 154, 198, 227, 43, 235, 247, 62, 51, 2, 238, 1, 255, 251, 178, 127, 24, 217, 192, 109, 173, 216, 65, 206, 45, 158, 164, 2, 239, 79, 140] }
created: object(2,0), object(2,1), object(2,2)
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
gas summary: computation_cost: 1000000, storage_cost: 12190400, storage_rebate: 2746260, non_refundable_storage_fee: 27740

task 3 'run'. lines 57-59:
created: object(3,0)
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
gas summary: computation_cost: 1000000, storage_cost: 6657600, storage_rebate: 4356396, non_refundable_storage_fee: 44004

task 4 'view-object'. lines 60-60:
Owner: Object ID: ( fake(2,0) )
Version: 3
Contents: sui::dynamic_field::Field<sui::deny_list::AddressKey, sui::config::Setting<bool>> {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,1),
},
},
name: sui::deny_list::AddressKey {
pos0: B,
},
value: sui::config::Setting<bool> {
data: std::option::Option<sui::config::SettingData<bool>> {
vec: vector[
sui::config::SettingData<bool> {
newer_value_epoch: 0u64,
newer_value: std::option::Option<bool> {
vec: vector[
true,
],
},
older_value_opt: std::option::Option<bool> {
vec: vector[],
},
},
],
},
},
}

task 5 'view-object'. lines 62-64:
Owner: Object ID: ( fake(2,0) )
Version: 4
Contents: sui::dynamic_field::Field<sui::deny_list::GlobalPauseKey, sui::config::Setting<bool>> {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(3,0),
},
},
name: sui::deny_list::GlobalPauseKey {
dummy_field: false,
},
value: sui::config::Setting<bool> {
data: std::option::Option<sui::config::SettingData<bool>> {
vec: vector[
sui::config::SettingData<bool> {
newer_value_epoch: 0u64,
newer_value: std::option::Option<bool> {
vec: vector[
true,
],
},
older_value_opt: std::option::Option<bool> {
vec: vector[],
},
},
],
},
},
}

task 6 'run'. lines 65-67:
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
deleted: object(2,1)
gas summary: computation_cost: 1000000, storage_cost: 4400400, storage_rebate: 6794172, non_refundable_storage_fee: 68628

task 7 'run'. lines 68-70:
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
deleted: object(3,0)
gas summary: computation_cost: 1000000, storage_cost: 4400400, storage_rebate: 6591024, non_refundable_storage_fee: 66576

task 8 'view-object'. lines 71-71:
No object at id 2,1

task 9 'view-object'. lines 73-75:
No object at id 3,0

task 10 'run'. lines 76-78:
mutated: object(0,0)
unchanged_shared: 0x0000000000000000000000000000000000000000000000000000000000000403
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 11 'run'. lines 79-79:
mutated: object(0,0)
unchanged_shared: 0x0000000000000000000000000000000000000000000000000000000000000403
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// This test verifies the correct deletion of the Config's setting object within the same epoch
// that it was created

//# init --accounts A B --addresses test=0x0

//# publish --sender A
module test::regulated_coin {
use sui::coin;
use sui::deny_list::DenyList;

public struct REGULATED_COIN has drop {}

fun init(otw: REGULATED_COIN, ctx: &mut TxContext) {
let (mut treasury_cap, deny_cap, metadata) = coin::create_regulated_currency_v2(
otw,
9,
b"RC",
b"REGULATED_COIN",
b"A new regulated coin",
option::none(),
true,
ctx
);
let coin = coin::mint(&mut treasury_cap, 10000, ctx);
transfer::public_transfer(coin, tx_context::sender(ctx));
transfer::public_transfer(deny_cap, tx_context::sender(ctx));
transfer::public_freeze_object(treasury_cap);
transfer::public_freeze_object(metadata);
}

entry fun assert_address_deny_status(
deny_list: &DenyList,
addr: address,
expected: bool,
) {
let status = coin::deny_list_v2_contains_next_epoch<REGULATED_COIN>(deny_list, addr);
assert!(status == expected, 0);
}

entry fun assert_global_pause_status(
deny_list: &DenyList,
expected: bool,
) {
let status =
coin::deny_list_v2_is_global_pause_enabled_next_epoch<REGULATED_COIN>(deny_list);
assert!(status == expected, 0);
}
}

// Deny account B.
//# run sui::coin::deny_list_v2_add --args object(0x403) object(1,3) @B --type-args test::regulated_coin::REGULATED_COIN --sender A

// Enable global pause.
//# run sui::coin::deny_list_v2_enable_global_pause --args object(0x403) object(1,3) --type-args test::regulated_coin::REGULATED_COIN --sender A

// View the setting objects
//# view-object 2,1

//# view-object 3,0

// Undeny account B.
//# run sui::coin::deny_list_v2_remove --args object(0x403) object(1,3) @B --type-args test::regulated_coin::REGULATED_COIN --sender A

// Disable global pause.
//# run sui::coin::deny_list_v2_disable_global_pause --args object(0x403) object(1,3) --type-args test::regulated_coin::REGULATED_COIN --sender A

// Verify the setting objects are deleted
//# view-object 2,1

//# view-object 3,0

// Assert that the address is no longer denied.
//# run test::regulated_coin::assert_address_deny_status --args immshared(0x403) @B false --sender A

// Assert that global pause is disabled.
//# run test::regulated_coin::assert_global_pause_status --args immshared(0x403) false --sender A
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
processed 18 tasks

init:
A: object(0,0), B: object(0,1)

task 1 'publish'. lines 9-53:
created: object(1,0), object(1,1), object(1,2), object(1,3), object(1,4), object(1,5)
mutated: object(0,0)
unchanged_shared: 0x0000000000000000000000000000000000000000000000000000000000000403
gas summary: computation_cost: 1000000, storage_cost: 20428800, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'run'. lines 54-56:
events: Event { package_id: sui, transaction_module: Identifier("coin"), sender: A, type_: StructTag { address: sui, module: Identifier("deny_list"), name: Identifier("PerTypeConfigCreated"), type_params: [] }, contents: [0, 0, 0, 0, 0, 0, 0, 0, 96, 48, 51, 51, 49, 100, 56, 101, 49, 98, 99, 98, 101, 55, 102, 100, 51, 97, 54, 101, 48, 97, 102, 102, 55, 99, 56, 56, 98, 50, 53, 97, 57, 54, 51, 102, 48, 51, 56, 102, 48, 51, 98, 97, 49, 53, 48, 51, 101, 48, 53, 98, 57, 56, 49, 102, 102, 101, 98, 56, 56, 98, 101, 98, 52, 58, 58, 114, 101, 103, 117, 108, 97, 116, 101, 100, 95, 99, 111, 105, 110, 58, 58, 82, 69, 71, 85, 76, 65, 84, 69, 68, 95, 67, 79, 73, 78, 116, 239, 154, 198, 227, 43, 235, 247, 62, 51, 2, 238, 1, 255, 251, 178, 127, 24, 217, 192, 109, 173, 216, 65, 206, 45, 158, 164, 2, 239, 79, 140] }
created: object(2,0), object(2,1), object(2,2)
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
gas summary: computation_cost: 1000000, storage_cost: 12190400, storage_rebate: 2746260, non_refundable_storage_fee: 27740

task 3 'run'. lines 57-59:
created: object(3,0)
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
gas summary: computation_cost: 1000000, storage_cost: 6657600, storage_rebate: 4356396, non_refundable_storage_fee: 44004

task 4 'view-object'. lines 60-60:
Owner: Object ID: ( fake(2,0) )
Version: 3
Contents: sui::dynamic_field::Field<sui::deny_list::AddressKey, sui::config::Setting<bool>> {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,1),
},
},
name: sui::deny_list::AddressKey {
pos0: B,
},
value: sui::config::Setting<bool> {
data: std::option::Option<sui::config::SettingData<bool>> {
vec: vector[
sui::config::SettingData<bool> {
newer_value_epoch: 0u64,
newer_value: std::option::Option<bool> {
vec: vector[
true,
],
},
older_value_opt: std::option::Option<bool> {
vec: vector[],
},
},
],
},
},
}

task 5 'view-object'. lines 62-62:
Owner: Object ID: ( fake(2,0) )
Version: 4
Contents: sui::dynamic_field::Field<sui::deny_list::GlobalPauseKey, sui::config::Setting<bool>> {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(3,0),
},
},
name: sui::deny_list::GlobalPauseKey {
dummy_field: false,
},
value: sui::config::Setting<bool> {
data: std::option::Option<sui::config::SettingData<bool>> {
vec: vector[
sui::config::SettingData<bool> {
newer_value_epoch: 0u64,
newer_value: std::option::Option<bool> {
vec: vector[
true,
],
},
older_value_opt: std::option::Option<bool> {
vec: vector[],
},
},
],
},
},
}

task 6 'advance-epoch'. lines 64-66:
Epoch advanced: 1

task 7 'run'. lines 67-69:
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3), object(2,1)
gas summary: computation_cost: 1000000, storage_cost: 6862800, storage_rebate: 6794172, non_refundable_storage_fee: 68628

task 8 'run'. lines 70-72:
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3), object(3,0)
gas summary: computation_cost: 1000000, storage_cost: 6657600, storage_rebate: 6591024, non_refundable_storage_fee: 66576

task 9 'view-object'. lines 73-73:
Owner: Object ID: ( fake(2,0) )
Version: 5
Contents: sui::dynamic_field::Field<sui::deny_list::AddressKey, sui::config::Setting<bool>> {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,1),
},
},
name: sui::deny_list::AddressKey {
pos0: B,
},
value: sui::config::Setting<bool> {
data: std::option::Option<sui::config::SettingData<bool>> {
vec: vector[
sui::config::SettingData<bool> {
newer_value_epoch: 1u64,
newer_value: std::option::Option<bool> {
vec: vector[],
},
older_value_opt: std::option::Option<bool> {
vec: vector[
true,
],
},
},
],
},
},
}

task 10 'view-object'. lines 75-75:
Owner: Object ID: ( fake(2,0) )
Version: 6
Contents: sui::dynamic_field::Field<sui::deny_list::GlobalPauseKey, sui::config::Setting<bool>> {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(3,0),
},
},
name: sui::deny_list::GlobalPauseKey {
dummy_field: false,
},
value: sui::config::Setting<bool> {
data: std::option::Option<sui::config::SettingData<bool>> {
vec: vector[
sui::config::SettingData<bool> {
newer_value_epoch: 1u64,
newer_value: std::option::Option<bool> {
vec: vector[],
},
older_value_opt: std::option::Option<bool> {
vec: vector[
true,
],
},
},
],
},
},
}

task 11 'advance-epoch'. lines 77-79:
Epoch advanced: 2

task 12 'run'. lines 80-82:
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
deleted: object(2,1)
gas summary: computation_cost: 1000000, storage_cost: 4400400, storage_rebate: 6794172, non_refundable_storage_fee: 68628

task 13 'run'. lines 83-85:
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
deleted: object(3,0)
gas summary: computation_cost: 1000000, storage_cost: 4400400, storage_rebate: 6591024, non_refundable_storage_fee: 66576

task 14 'view-object'. lines 86-86:
No object at id 2,1

task 15 'view-object'. lines 88-90:
No object at id 3,0

task 16 'run'. lines 91-93:
mutated: object(0,0)
unchanged_shared: 0x0000000000000000000000000000000000000000000000000000000000000403
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 17 'run'. lines 94-94:
mutated: object(0,0)
unchanged_shared: 0x0000000000000000000000000000000000000000000000000000000000000403
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
Loading

0 comments on commit 8cc4a8d

Please sign in to comment.