Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"[move]": {
"editor.tabSize": 4
},
"files.associations": {
"*.move": "rust"
},
"editor.insertSpaces": true
}
40 changes: 13 additions & 27 deletions packages/stablecoin/Move.lock
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 2
manifest_digest = "2D16DF7BBB460E26A4151FFCA9834972024289FF6DFDD87F005D543C741A929E"
version = 3
manifest_digest = "211DA955BFDF90F3CA2193ED2EDD945D3FABFA4631FABD1F214C406080C50CA4"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ name = "Sui" },
{ name = "sui_extensions" },
{ id = "Sui", name = "Sui" },
{ id = "sui_extensions", name = "sui_extensions" },
]

[[move.package]]
name = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "a4185da5659d8d299d34e1bb2515ff1f7e32a20a", subdir = "crates/sui-framework/packages/move-stdlib" }
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.62.1", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
name = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "a4185da5659d8d299d34e1bb2515ff1f7e32a20a", subdir = "crates/sui-framework/packages/sui-framework" }
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.62.1", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ name = "MoveStdlib" },
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
name = "sui_extensions"
id = "sui_extensions"
source = { local = "../sui_extensions" }

dependencies = [
{ name = "Sui" },
{ id = "Sui", name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.32.2"
edition = "2024.beta"
compiler-version = "1.62.1"
edition = "2024"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917"
latest-published-id = "0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xecf47609d7da919ea98e7fd04f6e0648a0a79b337aaad373fa37aac8febf19c8"
latest-published-id = "0xecf47609d7da919ea98e7fd04f6e0648a0a79b337aaad373fa37aac8febf19c8"
published-version = "1"
4 changes: 2 additions & 2 deletions packages/stablecoin/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

[package]
name = "stablecoin"
edition = "2024.beta"
edition = "2024"
license = "Apache 2.0"

[dependencies.Sui]
git = "https://github.com/MystenLabs/sui.git"
subdir = "crates/sui-framework/packages/sui-framework"
rev = "a4185da5659d8d299d34e1bb2515ff1f7e32a20a"
rev = "mainnet-v1.62.1"

[dependencies.sui_extensions]
local = "../sui_extensions"
Expand Down
6 changes: 3 additions & 3 deletions packages/stablecoin/sources/treasury.move
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ module stablecoin::treasury {
/// additionally compatible with this package's version.
entry fun start_migration<T>(treasury: &mut Treasury<T>, ctx: &TxContext) {
treasury.roles.owner_role().assert_sender_is_active_role(ctx);
assert!(treasury.compatible_versions.size() == 1, EMigrationStarted);
assert!(treasury.compatible_versions.length() == 1, EMigrationStarted);

let active_version = treasury.compatible_versions.keys()[0];
assert!(active_version < version_control::current_version(), EObjectMigrated);
Expand All @@ -614,7 +614,7 @@ module stablecoin::treasury {
/// to the previous version.
entry fun abort_migration<T>(treasury: &mut Treasury<T>, ctx: &TxContext) {
treasury.roles.owner_role().assert_sender_is_active_role(ctx);
assert!(treasury.compatible_versions.size() == 2, EMigrationNotStarted);
assert!(treasury.compatible_versions.length() == 2, EMigrationNotStarted);

let pending_version = max(
treasury.compatible_versions.keys()[0],
Expand All @@ -633,7 +633,7 @@ module stablecoin::treasury {
/// only compatible with this package's version.
entry fun complete_migration<T>(treasury: &mut Treasury<T>, ctx: &TxContext) {
treasury.roles.owner_role().assert_sender_is_active_role(ctx);
assert!(treasury.compatible_versions.size() == 2, EMigrationNotStarted);
assert!(treasury.compatible_versions.length() == 2, EMigrationNotStarted);

let (version_a, version_b) = (treasury.compatible_versions.keys()[0], treasury.compatible_versions.keys()[1]);
let (active_version, pending_version) = (min(version_a, version_b), max(version_a, version_b));
Expand Down
24 changes: 12 additions & 12 deletions packages/stablecoin/tests/mint_allowance_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@

#[test_only]
module stablecoin::mint_allowance_tests {
use sui::test_utils::{assert_eq};
use std::unit_test;
use stablecoin::mint_allowance;

public struct MINT_ALLOWANCE_TESTS has drop {}

#[test]
fun create_and_mutate_mint_allowance__should_succeed() {
let mut allowance = mint_allowance::new<MINT_ALLOWANCE_TESTS>();
assert_eq(allowance.value(), 0);
unit_test::assert_eq!(allowance.value(), 0);

allowance.set(1);
assert_eq(allowance.value(), 1);
unit_test::assert_eq!(allowance.value(), 1);

allowance.decrease(1);
assert_eq(allowance.value(), 0);
unit_test::assert_eq!(allowance.value(), 0);

allowance.set(5);
assert_eq(allowance.value(), 5);
unit_test::assert_eq!(allowance.value(), 5);

allowance.increase(3);
assert_eq(allowance.value(), 8);
unit_test::assert_eq!(allowance.value(), 8);

allowance.destroy();
}
Expand All @@ -45,7 +45,7 @@ module stablecoin::mint_allowance_tests {
fun increase__should_fail_on_integer_overflow() {
let mut allowance = mint_allowance::new<MINT_ALLOWANCE_TESTS>();
allowance.set(1);
assert_eq(allowance.value(), 1);
unit_test::assert_eq!(allowance.value(), 1);

allowance.increase(18446744073709551615u64);
allowance.destroy();
Expand All @@ -54,7 +54,7 @@ module stablecoin::mint_allowance_tests {
#[test, expected_failure(abort_code = ::stablecoin::mint_allowance::EInsufficientAllowance)]
fun decrease__should_fail_if_allowance_is_insufficient() {
let mut allowance = mint_allowance::new<MINT_ALLOWANCE_TESTS>();
assert_eq(allowance.value(), 0);
unit_test::assert_eq!(allowance.value(), 0);

allowance.decrease(1);
allowance.destroy();
Expand All @@ -63,16 +63,16 @@ module stablecoin::mint_allowance_tests {
#[test]
fun increase_decrease__should_succeed_if_value_is_zero() {
let mut allowance = mint_allowance::new<MINT_ALLOWANCE_TESTS>();
assert_eq(allowance.value(), 0);
unit_test::assert_eq!(allowance.value(), 0);

allowance.set(100);
assert_eq(allowance.value(), 100);
unit_test::assert_eq!(allowance.value(), 100);

allowance.decrease(0);
assert_eq(allowance.value(), 100);
unit_test::assert_eq!(allowance.value(), 100);

allowance.increase(0);
assert_eq(allowance.value(), 100);
unit_test::assert_eq!(allowance.value(), 100);

allowance.destroy();
}
Expand Down
62 changes: 30 additions & 32 deletions packages/stablecoin/tests/roles_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ module stablecoin::roles_tests {
use sui::{
event,
test_scenario::{Self, Scenario},
test_utils::assert_eq,
test_utils::destroy,
};
use stablecoin::roles::{Self, Roles, OwnerRole};
use sui_extensions::{
Expand Down Expand Up @@ -64,7 +62,7 @@ module stablecoin::roles_tests {
test_update_metadata_updater(METADATA_UPDATER, &mut roles, &mut scenario);

scenario.end();
destroy(roles);
std::unit_test::destroy(roles);
}

#[test, expected_failure(abort_code = two_step_role::ESenderNotActiveRole)]
Expand All @@ -75,7 +73,7 @@ module stablecoin::roles_tests {
test_update_master_minter(RANDOM_ADDRESS, &mut roles, &mut scenario);

scenario.end();
destroy(roles);
std::unit_test::destroy(roles);
}

#[test, expected_failure(abort_code = two_step_role::ESenderNotActiveRole)]
Expand All @@ -86,7 +84,7 @@ module stablecoin::roles_tests {
test_update_blocklister(RANDOM_ADDRESS, &mut roles, &mut scenario);

scenario.end();
destroy(roles);
std::unit_test::destroy(roles);
}

#[test, expected_failure(abort_code = two_step_role::ESenderNotActiveRole)]
Expand All @@ -97,7 +95,7 @@ module stablecoin::roles_tests {
test_update_pauser(RANDOM_ADDRESS, &mut roles, &mut scenario);

scenario.end();
destroy(roles);
std::unit_test::destroy(roles);
}

#[test, expected_failure(abort_code = two_step_role::ESenderNotActiveRole)]
Expand All @@ -108,7 +106,7 @@ module stablecoin::roles_tests {
test_update_metadata_updater(RANDOM_ADDRESS, &mut roles, &mut scenario);

scenario.end();
destroy(roles);
std::unit_test::destroy(roles);
}

// === Helpers ===
Expand All @@ -117,79 +115,79 @@ module stablecoin::roles_tests {
fun setup(): (Scenario, Roles<ROLES_TEST>) {
let mut scenario = test_scenario::begin(DEPLOYER);
let roles = roles::new(OWNER, OWNER, OWNER, OWNER, OWNER, scenario.ctx());
assert_eq(roles.owner(), OWNER);
assert_eq(roles.pending_owner().is_none(), true);
assert_eq(roles.master_minter(), OWNER);
assert_eq(roles.pauser(), OWNER);
assert_eq(roles.blocklister(), OWNER);
std::unit_test::assert_eq!(roles.owner(), OWNER);
std::unit_test::assert_eq!(roles.pending_owner().is_none(), true);
std::unit_test::assert_eq!(roles.master_minter(), OWNER);
std::unit_test::assert_eq!(roles.pauser(), OWNER);
std::unit_test::assert_eq!(roles.blocklister(), OWNER);

(scenario, roles)
}

public(package) fun test_transfer_ownership<T>(new_owner: address, roles: &mut Roles<T>, scenario: &mut Scenario) {
let old_owner = roles.owner();
roles.owner_role_mut().begin_role_transfer(new_owner, scenario.ctx());
assert_eq(roles.owner(), old_owner);
assert_eq(*roles.pending_owner().borrow(), new_owner);
std::unit_test::assert_eq!(roles.owner(), old_owner);
std::unit_test::assert_eq!(*roles.pending_owner().borrow(), new_owner);

let expected_event = two_step_role::create_role_transfer_started_event<OwnerRole<T>>(
old_owner, new_owner
);
assert_eq(event::num_events(), 1);
assert_eq(last_event_by_type(), expected_event);
std::unit_test::assert_eq!(event::num_events(), 1);
std::unit_test::assert_eq!(last_event_by_type(), expected_event);
}

public(package) fun test_accept_ownership<T>(roles: &mut Roles<T>, scenario: &mut Scenario) {
let old_owner = roles.owner();
let pending_owner = roles.pending_owner();
roles.owner_role_mut().accept_role(scenario.ctx());
assert_eq(roles.owner(), *pending_owner.borrow());
assert_eq(roles.pending_owner().is_none(), true);
std::unit_test::assert_eq!(roles.owner(), *pending_owner.borrow());
std::unit_test::assert_eq!(roles.pending_owner().is_none(), true);

let expected_event = two_step_role::create_role_transferred_event<OwnerRole<T>>(
old_owner, *pending_owner.borrow()
);
assert_eq(event::num_events(), 1);
assert_eq(last_event_by_type(), expected_event);
std::unit_test::assert_eq!(event::num_events(), 1);
std::unit_test::assert_eq!(last_event_by_type(), expected_event);
}

public(package) fun test_update_master_minter<T>(new_master_minter: address, roles: &mut Roles<T>, scenario: &mut Scenario) {
let old_master_minter = roles.master_minter();
roles.update_master_minter(new_master_minter, scenario.ctx());
assert_eq(roles.master_minter(), new_master_minter);
std::unit_test::assert_eq!(roles.master_minter(), new_master_minter);

let expected_event = roles::create_master_minter_changed_event<T>(old_master_minter, new_master_minter);
assert_eq(event::num_events(), 1);
assert_eq(last_event_by_type(), expected_event);
std::unit_test::assert_eq!(event::num_events(), 1);
std::unit_test::assert_eq!(last_event_by_type(), expected_event);
}

public(package) fun test_update_blocklister<T>(new_blocklister: address, roles: &mut Roles<T>, scenario: &mut Scenario) {
let old_blocklister = roles.blocklister();
roles.update_blocklister(new_blocklister, scenario.ctx());
assert_eq(roles.blocklister(), new_blocklister);
std::unit_test::assert_eq!(roles.blocklister(), new_blocklister);

let expected_event = roles::create_blocklister_changed_event<T>(old_blocklister, new_blocklister);
assert_eq(event::num_events(), 1);
assert_eq(last_event_by_type(), expected_event);
std::unit_test::assert_eq!(event::num_events(), 1);
std::unit_test::assert_eq!(last_event_by_type(), expected_event);
}

public(package) fun test_update_pauser<T>(new_pauser: address, roles: &mut Roles<T>, scenario: &mut Scenario) {
let old_pauser = roles.pauser();
roles.update_pauser(new_pauser, scenario.ctx());
assert_eq(roles.pauser(), new_pauser);
std::unit_test::assert_eq!(roles.pauser(), new_pauser);

let expected_event = roles::create_pauser_changed_event<T>(old_pauser, new_pauser);
assert_eq(event::num_events(), 1);
assert_eq(last_event_by_type(), expected_event);
std::unit_test::assert_eq!(event::num_events(), 1);
std::unit_test::assert_eq!(last_event_by_type(), expected_event);
}

public(package) fun test_update_metadata_updater<T>(new_metadata_updater: address, roles: &mut Roles<T>, scenario: &mut Scenario) {
let old_metadata_updater = roles.metadata_updater();
roles.update_metadata_updater(new_metadata_updater, scenario.ctx());
assert_eq(roles.metadata_updater(), new_metadata_updater);
std::unit_test::assert_eq!(roles.metadata_updater(), new_metadata_updater);

let expected_event = roles::create_metadata_updater_changed_event<T>(old_metadata_updater, new_metadata_updater);
assert_eq(event::num_events(), 1);
assert_eq(last_event_by_type(), expected_event);
std::unit_test::assert_eq!(event::num_events(), 1);
std::unit_test::assert_eq!(last_event_by_type(), expected_event);
}
}
4 changes: 2 additions & 2 deletions packages/stablecoin/tests/stablecoin_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#[test_only]
module stablecoin::stablecoin_tests {
use std::unit_test;
use sui::{
test_scenario,
test_utils::{assert_eq}
};
use stablecoin::stablecoin::{Self, STABLECOIN};
use sui_extensions::upgrade_service::UpgradeService;
Expand All @@ -32,7 +32,7 @@ module stablecoin::stablecoin_tests {

scenario.next_tx(DEPLOYER);
let upgrade_service = scenario.take_shared<UpgradeService<STABLECOIN>>();
assert_eq(upgrade_service.admin(), DEPLOYER);
unit_test::assert_eq!(upgrade_service.admin(), DEPLOYER);
test_scenario::return_shared(upgrade_service);

scenario.end();
Expand Down
Loading