diff --git a/sui/wormhole/Move.lock b/sui/wormhole/Move.lock index 570d17a100..0ed1a84b8e 100644 --- a/sui/wormhole/Move.lock +++ b/sui/wormhole/Move.lock @@ -2,7 +2,7 @@ [move] version = 0 -manifest_digest = "E8C411A83F4F7EF268B73C732B9B6F49F7B204F0C9C2530765365C38B76EF646" +manifest_digest = "F24DE9952B3B73F37574346F868C342DE75B44914ED8C68274D2F1401E25806F" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ @@ -11,17 +11,17 @@ dependencies = [ [[move.package]] name = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "041c5f2bae2fe52079e44b70514333532d69f4e6", subdir = "crates/sui-framework/packages/move-stdlib" } +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } [[move.package]] name = "Sui" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "041c5f2bae2fe52079e44b70514333532d69f4e6", subdir = "crates/sui-framework/packages/sui-framework" } +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } dependencies = [ { name = "MoveStdlib" }, ] [move.toolchain-version] -compiler-version = "1.19.0" -edition = "legacy" +compiler-version = "1.34.0" +edition = "2024.beta" flavor = "sui" diff --git a/sui/wormhole/Move.mainnet.toml b/sui/wormhole/Move.mainnet.toml index 7465390ebb..59dcd52ac8 100644 --- a/sui/wormhole/Move.mainnet.toml +++ b/sui/wormhole/Move.mainnet.toml @@ -6,7 +6,7 @@ published-at = "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb [dependencies.Sui] git = "https://github.com/MystenLabs/sui.git" subdir = "crates/sui-framework/packages/sui-framework" -rev = "041c5f2bae2fe52079e44b70514333532d69f4e6" +rev = "framework/mainnet" [addresses] wormhole = "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a" diff --git a/sui/wormhole/Move.testnet.toml b/sui/wormhole/Move.testnet.toml index ed34ccb472..ad3732fa10 100644 --- a/sui/wormhole/Move.testnet.toml +++ b/sui/wormhole/Move.testnet.toml @@ -6,7 +6,7 @@ published-at = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a [dependencies.Sui] git = "https://github.com/MystenLabs/sui.git" subdir = "crates/sui-framework/packages/sui-framework" -rev = "041c5f2bae2fe52079e44b70514333532d69f4e6" +rev = "framework/testnet" [addresses] wormhole = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94" diff --git a/sui/wormhole/Move.toml b/sui/wormhole/Move.toml deleted file mode 120000 index b7c17ea819..0000000000 --- a/sui/wormhole/Move.toml +++ /dev/null @@ -1 +0,0 @@ -Move.testnet.toml \ No newline at end of file diff --git a/sui/wormhole/Move.toml b/sui/wormhole/Move.toml new file mode 100644 index 0000000000..e322d58738 --- /dev/null +++ b/sui/wormhole/Move.toml @@ -0,0 +1,13 @@ +[package] +name = "Wormhole" +version = "0.2.0" +edition = "2024.beta" +published-at = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94" + +[dependencies.Sui] +git = "https://github.com/MystenLabs/sui.git" +subdir = "crates/sui-framework/packages/sui-framework" +rev = "framework/testnet" + +[addresses] +wormhole = "0x123456" diff --git a/sui/wormhole/sources/datatypes/bytes20.move b/sui/wormhole/sources/datatypes/bytes20.move index 3c097dec69..cdf1b7f000 100644 --- a/sui/wormhole/sources/datatypes/bytes20.move +++ b/sui/wormhole/sources/datatypes/bytes20.move @@ -3,7 +3,6 @@ /// This module implements a custom type representing a fixed-size array of /// length 20. module wormhole::bytes20 { - use std::vector::{Self}; use wormhole::bytes::{Self}; use wormhole::cursor::{Cursor}; @@ -17,7 +16,7 @@ module wormhole::bytes20 { const LEN: u64 = 20; /// Container for `vector`, which has length == 20. - struct Bytes20 has copy, drop, store { + public struct Bytes20 has copy, drop, store { data: vector } @@ -33,10 +32,10 @@ module wormhole::bytes20 { /// Create new `Bytes20` of all zeros. public fun default(): Bytes20 { - let data = vector::empty(); - let i = 0; + let mut data = vector[]; + let mut i = 0; while (i < LEN) { - vector::push_back(&mut data, 0); + data.push_back(0); i = i + 1; }; new(data) @@ -49,8 +48,8 @@ module wormhole::bytes20 { /// Either trim or pad (depending on length of the input `vector`) to 20 /// bytes. - public fun from_bytes(buf: vector): Bytes20 { - let len = vector::length(&buf); + public fun from_bytes(mut buf: vector): Bytes20 { + let len = buf.length(); if (len > LEN) { trim_nonzero_left(&mut buf); new(buf) @@ -72,9 +71,9 @@ module wormhole::bytes20 { /// Validate that any of the bytes in underlying data is non-zero. public fun is_nonzero(self: &Bytes20): bool { - let i = 0; + let mut i = 0; while (i < LEN) { - if (*vector::borrow(&self.data, i) > 0) { + if (*self.data.borrow(i) > 0) { return true }; i = i + 1; @@ -85,29 +84,28 @@ module wormhole::bytes20 { /// Check that the input data is correct length. fun is_valid(data: &vector): bool { - vector::length(data) == LEN + data.length() == LEN } /// For vector size less than 20, add zeros to the left. fun pad_left(data: &vector, data_reversed: bool): vector { - let out = vector::empty(); - let len = vector::length(data); - let i = len; + let mut out = vector[]; + let len = data.length(); + let mut i = len; while (i < LEN) { - vector::push_back(&mut out, 0); + out.push_back(0); i = i + 1; }; if (data_reversed) { - let i = 0; + let mut i = 0; while (i < len) { - vector::push_back( - &mut out, - *vector::borrow(data, len - i - 1) + out.push_back( + *data.borrow(len - i - 1) ); i = i + 1; }; } else { - vector::append(&mut out, *data); + out.append(*data); }; out @@ -116,26 +114,25 @@ module wormhole::bytes20 { /// Trim bytes from the left if they are zero. If any of these bytes /// are non-zero, abort. fun trim_nonzero_left(data: &mut vector) { - vector::reverse(data); - let (i, n) = (0, vector::length(data) - LEN); + data.reverse(); + let (mut i, n) = (0, data.length() - LEN); while (i < n) { - assert!(vector::pop_back(data) == 0, E_CANNOT_TRIM_NONZERO); + assert!(data.pop_back() == 0, E_CANNOT_TRIM_NONZERO); i = i + 1; }; - vector::reverse(data); + data.reverse(); } } #[test_only] module wormhole::bytes20_tests { - use std::vector::{Self}; use wormhole::bytes20::{Self}; #[test] public fun new() { let data = x"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; - assert!(vector::length(&data) == 20, 0); + assert!(data.length() == 20, 0); let actual = bytes20::new(data); assert!(bytes20::data(&actual) == data, 0); @@ -170,7 +167,7 @@ module wormhole::bytes20_tests { public fun cannot_new_non_20_byte_vector() { let data = x"deadbeefdeadbeefdeadbeefdeadbeefdeadbe"; - assert!(vector::length(&data) != 20, 0); + assert!(data.length() != 20, 0); bytes20::new(data); } } diff --git a/sui/wormhole/sources/datatypes/bytes32.move b/sui/wormhole/sources/datatypes/bytes32.move index ab713f6f25..c76c74ee9d 100644 --- a/sui/wormhole/sources/datatypes/bytes32.move +++ b/sui/wormhole/sources/datatypes/bytes32.move @@ -3,9 +3,7 @@ /// This module implements a custom type representing a fixed-size array of /// length 32. module wormhole::bytes32 { - use std::option::{Self}; use std::string::{Self, String}; - use std::vector::{Self}; use sui::bcs::{Self}; use wormhole::bytes::{Self}; @@ -22,7 +20,7 @@ module wormhole::bytes32 { const LEN: u64 = 32; /// Container for `vector`, which has length == 32. - struct Bytes32 has copy, drop, store { + public struct Bytes32 has copy, drop, store { data: vector, } @@ -38,10 +36,10 @@ module wormhole::bytes32 { /// Create new `Bytes20` of all zeros. public fun default(): Bytes32 { - let data = vector::empty(); - let i = 0; + let mut data = vector[]; + let mut i = 0; while (i < LEN) { - vector::push_back(&mut data, 0); + data.push_back(0); i = i + 1; }; new(data) @@ -54,16 +52,16 @@ module wormhole::bytes32 { /// Serialize `u256` as big-endian format in zero-padded `Bytes32`. public fun from_u256_be(value: u256): Bytes32 { - let buf = bcs::to_bytes(&value); - vector::reverse(&mut buf); + let mut buf = bcs::to_bytes(&value); + buf.reverse(); new(buf) } /// Deserialize from big-endian `u256`. public fun to_u256_be(value: Bytes32): u256 { - let cur = cursor::new(to_bytes(value)); + let mut cur = cursor::new(to_bytes(value)); let out = bytes::take_u256_be(&mut cur); - cursor::destroy_empty(cur); + cur.destroy_empty(); out } @@ -83,8 +81,8 @@ module wormhole::bytes32 { /// Either trim or pad (depending on length of the input `vector`) to 32 /// bytes. - public fun from_bytes(buf: vector): Bytes32 { - let len = vector::length(&buf); + public fun from_bytes(mut buf: vector): Bytes32 { + let len = buf.length(); if (len > LEN) { trim_nonzero_left(&mut buf); new(buf) @@ -115,20 +113,20 @@ module wormhole::bytes32 { } public fun from_utf8(str: String): Bytes32 { - let data = *string::bytes(&str); - let len = vector::length(&data); + let mut data = *str.as_bytes(); + let len = data.length(); if (len > LEN) { // Trim from end. - let i = len; + let mut i = len; while (i > LEN) { - vector::pop_back(&mut data); + data.pop_back(); i = i - 1; } } else { // Pad right to `LEN`. - let i = len; + let mut i = len; while (i < LEN) { - vector::push_back(&mut data, 0); + data.push_back(0); i = i + 1; } }; @@ -141,21 +139,21 @@ module wormhole::bytes32 { /// character at the 32 byte boundary, which, when split, results in an /// invalid code point, so we remove it. public fun to_utf8(value: Bytes32): String { - let data = to_bytes(value); + let mut data = to_bytes(value); - let utf8 = string::try_utf8(data); + let mut utf8 = string::try_utf8(data); while (option::is_none(&utf8)) { - vector::pop_back(&mut data); + data.pop_back(); utf8 = string::try_utf8(data); }; - let buf = *string::bytes(&option::extract(&mut utf8)); + let mut buf = *string::as_bytes(&utf8.extract()); // Now trim zeros from the right. while ( - *vector::borrow(&buf, vector::length(&buf) - 1) == 0 + *buf.borrow(buf.length() - 1) == 0 ) { - vector::pop_back(&mut buf); + buf.pop_back(); }; string::utf8(buf) @@ -163,9 +161,9 @@ module wormhole::bytes32 { /// Validate that any of the bytes in underlying data is non-zero. public fun is_nonzero(self: &Bytes32): bool { - let i = 0; + let mut i = 0; while (i < LEN) { - if (*vector::borrow(&self.data, i) > 0) { + if (*self.data.borrow(i) > 0) { return true }; i = i + 1; @@ -176,29 +174,28 @@ module wormhole::bytes32 { /// Check that the input data is correct length. fun is_valid(data: &vector): bool { - vector::length(data) == LEN + data.length() == LEN } /// For vector size less than 32, add zeros to the left. fun pad_left(data: &vector, data_reversed: bool): vector { - let out = vector::empty(); - let len = vector::length(data); - let i = len; + let mut out = vector[]; + let len = data.length(); + let mut i = len; while (i < LEN) { - vector::push_back(&mut out, 0); + out.push_back(0); i = i + 1; }; if (data_reversed) { - let i = 0; + let mut i = 0; while (i < len) { - vector::push_back( - &mut out, - *vector::borrow(data, len - i - 1) + out.push_back( + *data.borrow(len - i - 1) ); i = i + 1; }; } else { - vector::append(&mut out, *data); + out.append(*data); }; out @@ -207,19 +204,18 @@ module wormhole::bytes32 { /// Trim bytes from the left if they are zero. If any of these bytes /// are non-zero, abort. fun trim_nonzero_left(data: &mut vector) { - vector::reverse(data); - let (i, n) = (0, vector::length(data) - LEN); + data.reverse(); + let (mut i, n) = (0, data.length() - LEN); while (i < n) { - assert!(vector::pop_back(data) == 0, E_CANNOT_TRIM_NONZERO); + assert!(data.pop_back() == 0, E_CANNOT_TRIM_NONZERO); i = i + 1; }; - vector::reverse(data); + data.reverse(); } } #[test_only] module wormhole::bytes32_tests { - use std::vector::{Self}; use wormhole::bytes32::{Self}; @@ -227,7 +223,7 @@ module wormhole::bytes32_tests { public fun new() { let data = x"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; - assert!(vector::length(&data) == 32, 0); + assert!(data.length() == 32, 0); let actual = bytes32::new(data); assert!(bytes32::data(&actual) == data, 0); @@ -281,7 +277,7 @@ module wormhole::bytes32_tests { public fun cannot_new_non_32_byte_vector() { let data = x"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbe"; - assert!(vector::length(&data) != 32, 0); + assert!(data.length() != 32, 0); bytes32::new(data); } } diff --git a/sui/wormhole/sources/datatypes/external_address.move b/sui/wormhole/sources/datatypes/external_address.move index b2134caf35..0687c26228 100644 --- a/sui/wormhole/sources/datatypes/external_address.move +++ b/sui/wormhole/sources/datatypes/external_address.move @@ -3,7 +3,6 @@ /// This module implements a custom type for a 32-byte standardized address, /// which is meant to represent an address from any other network. module wormhole::external_address { - use sui::object::{Self, ID}; use wormhole::bytes32::{Self, Bytes32}; use wormhole::cursor::{Cursor}; @@ -11,7 +10,7 @@ module wormhole::external_address { const E_ZERO_ADDRESS: u64 = 0; /// Container for `Bytes32`. - struct ExternalAddress has copy, drop, store { + public struct ExternalAddress has copy, drop, store { value: Bytes32, } diff --git a/sui/wormhole/sources/datatypes/guardian_signature.move b/sui/wormhole/sources/datatypes/guardian_signature.move index 58698d51a6..548898e326 100644 --- a/sui/wormhole/sources/datatypes/guardian_signature.move +++ b/sui/wormhole/sources/datatypes/guardian_signature.move @@ -4,12 +4,11 @@ /// with recovery ID of a particular hashed VAA message body. The components of /// `GuardianSignature` are used to perform public key recovery using ECDSA. module wormhole::guardian_signature { - use std::vector::{Self}; use wormhole::bytes32::{Self, Bytes32}; /// Container for elliptic curve signature parameters and Guardian index. - struct GuardianSignature has store, drop { + public struct GuardianSignature has store, drop { r: Bytes32, s: Bytes32, recovery_id: u8, @@ -55,10 +54,10 @@ module wormhole::guardian_signature { /// consumed by `ecdsa_k1` for public key recovery. public fun to_rsv(gs: GuardianSignature): vector { let GuardianSignature { r, s, recovery_id, index: _ } = gs; - let out = vector::empty(); - vector::append(&mut out, bytes32::to_bytes(r)); - vector::append(&mut out, bytes32::to_bytes(s)); - vector::push_back(&mut out, recovery_id); + let mut out = vector::empty(); + out.append(bytes32::to_bytes(r)); + out.append(bytes32::to_bytes(s)); + out.push_back(recovery_id); out } } diff --git a/sui/wormhole/sources/emitter.move b/sui/wormhole/sources/emitter.move index 5c5f2dbe73..8fd4e1ab76 100644 --- a/sui/wormhole/sources/emitter.move +++ b/sui/wormhole/sources/emitter.move @@ -4,27 +4,24 @@ /// Wormhole messages. Its external address is determined by the capability's /// `id`, which is a 32-byte vector. module wormhole::emitter { - use sui::object::{Self, ID, UID}; - use sui::tx_context::{TxContext}; use wormhole::state::{Self, State}; - friend wormhole::publish_message; /// Event reflecting when `new` is called. - struct EmitterCreated has drop, copy { + public struct EmitterCreated has drop, copy { emitter_cap: ID } /// Event reflecting when `destroy` is called. - struct EmitterDestroyed has drop, copy { + public struct EmitterDestroyed has drop, copy { emitter_cap: ID } /// `EmitterCap` is a Sui object that gives a user or smart contract the /// capability to send Wormhole messages. For every Wormhole message /// emitted, a unique `sequence` is used. - struct EmitterCap has key, store { + public struct EmitterCap has key, store { id: UID, /// Sequence number of the next wormhole message. @@ -56,7 +53,7 @@ module wormhole::emitter { /// Once a Wormhole message is emitted, an `EmitterCap` upticks its /// internal `sequence` for the next message. - public(friend) fun use_sequence(self: &mut EmitterCap): u64 { + public(package) fun use_sequence(self: &mut EmitterCap): u64 { let sequence = self.sequence; self.sequence = sequence + 1; sequence @@ -94,7 +91,6 @@ module wormhole::emitter { #[test_only] module wormhole::emitter_tests { - use sui::object::{Self}; use sui::test_scenario::{Self}; use wormhole::emitter::{Self}; @@ -111,14 +107,14 @@ module wormhole::emitter_tests { fun test_emitter() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Ignore effects. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); let worm_state = take_state(scenario); @@ -141,7 +137,7 @@ module wormhole::emitter_tests { return_state(worm_state); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -149,19 +145,19 @@ module wormhole::emitter_tests { fun test_cannot_new_emitter_outdated_version() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Ignore effects. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than diff --git a/sui/wormhole/sources/governance/set_fee.move b/sui/wormhole/sources/governance/set_fee.move index ab3431b7ca..d37b784eda 100644 --- a/sui/wormhole/sources/governance/set_fee.move +++ b/sui/wormhole/sources/governance/set_fee.move @@ -11,9 +11,9 @@ module wormhole::set_fee { /// Specific governance payload ID (action) for setting Wormhole fee. const ACTION_SET_FEE: u8 = 3; - struct GovernanceWitness has drop {} + public struct GovernanceWitness has drop {} - struct SetFee { + public struct SetFee { amount: u64 } @@ -22,8 +22,8 @@ module wormhole::set_fee { ): DecreeTicket { governance_message::authorize_verify_local( GovernanceWitness {}, - state::governance_chain(wormhole_state), - state::governance_contract(wormhole_state), + wormhole_state.governance_chain(), + wormhole_state.governance_contract(), state::governance_module(), ACTION_SET_FEE ) @@ -41,7 +41,7 @@ module wormhole::set_fee { receipt: DecreeReceipt ): u64 { // This capability ensures that the current build version is used. - let latest_only = state::assert_latest_only(wormhole_state); + let latest_only = wormhole_state.assert_latest_only(); let payload = governance_message::take_payload( @@ -58,7 +58,7 @@ module wormhole::set_fee { } fun deserialize(payload: vector): SetFee { - let cur = cursor::new(payload); + let mut cur = cursor::new(payload); // This amount cannot be greater than max u64. let amount = bytes32::to_u64_be(bytes32::take_bytes(&mut cur)); @@ -83,7 +83,6 @@ module wormhole::set_fee_tests { use wormhole::cursor::{Self}; use wormhole::governance_message::{Self}; use wormhole::set_fee::{Self}; - use wormhole::state::{Self}; use wormhole::vaa::{Self}; use wormhole::version_control::{Self}; use wormhole::wormhole_scenario::{ @@ -110,20 +109,20 @@ module wormhole::set_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 420; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `set_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Double-check current fee (from setup). - assert!(state::message_fee(&worm_state) == wormhole_fee, 0); + assert!(worm_state.message_fee() == wormhole_fee, 0); let verified_vaa = vaa::parse_and_verify(&worm_state, VAA_SET_FEE_1, &the_clock); @@ -134,11 +133,10 @@ module wormhole::set_fee_tests { assert!(wormhole_fee != fee_amount, 0); // Confirm the fee changed. - assert!(state::message_fee(&worm_state) == fee_amount, 0); + assert!(worm_state.message_fee() == fee_amount, 0); // And confirm that we can deposit the new fee amount. - state::deposit_fee_test_only( - &mut worm_state, + worm_state.deposit_fee_test_only( balance::create_for_testing(fee_amount) ); @@ -153,14 +151,14 @@ module wormhole::set_fee_tests { let fee_amount = set_fee(&mut worm_state, receipt); // Confirm. - assert!(state::message_fee(&worm_state) == fee_amount, 0); + assert!(worm_state.message_fee() == fee_amount, 0); // Clean up. return_state(worm_state); return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -170,7 +168,7 @@ module wormhole::set_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 420; @@ -180,13 +178,13 @@ module wormhole::set_fee_tests { upgrade_wormhole(scenario); // Prepare test to execute `set_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Double-check current fee (from setup). - assert!(state::message_fee(&worm_state) == wormhole_fee, 0); + assert!(worm_state.message_fee() == wormhole_fee, 0); let verified_vaa = vaa::parse_and_verify(&worm_state, VAA_SET_FEE_1, &the_clock); @@ -196,14 +194,14 @@ module wormhole::set_fee_tests { let fee_amount = set_fee(&mut worm_state, receipt); // Confirm the fee changed. - assert!(state::message_fee(&worm_state) == fee_amount, 0); + assert!(worm_state.message_fee() == fee_amount, 0); // Clean up. return_state(worm_state); return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -214,16 +212,16 @@ module wormhole::set_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 420; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `set_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Set once. @@ -254,16 +252,16 @@ module wormhole::set_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 420; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `set_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Show that the encoded fee is greater than u64 max. @@ -274,13 +272,13 @@ module wormhole::set_fee_tests { &the_clock ); let payload = - governance_message::take_decree(vaa::payload(&verified_vaa)); - let cur = cursor::new(payload); + governance_message::take_decree(verified_vaa.payload()); + let mut cur = cursor::new(payload); let fee_amount = bytes::take_u256_be(&mut cur); assert!(fee_amount > 0xffffffffffffffff, 0); - cursor::destroy_empty(cur); + cur.destroy_empty(); let ticket = set_fee::authorize_governance(&worm_state); let receipt = @@ -300,26 +298,25 @@ module wormhole::set_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 420; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `set_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than // this build. - state::migrate_version_test_only( - &mut worm_state, + worm_state.migrate_version_test_only( version_control::previous_version_test_only(), version_control::next_version() ); diff --git a/sui/wormhole/sources/governance/transfer_fee.move b/sui/wormhole/sources/governance/transfer_fee.move index f31274b8e0..76a0403a6d 100644 --- a/sui/wormhole/sources/governance/transfer_fee.move +++ b/sui/wormhole/sources/governance/transfer_fee.move @@ -4,8 +4,6 @@ /// amount of collected fees to an intended recipient. module wormhole::transfer_fee { use sui::coin::{Self}; - use sui::transfer::{Self}; - use sui::tx_context::{TxContext}; use wormhole::bytes32::{Self}; use wormhole::cursor::{Self}; @@ -16,9 +14,9 @@ module wormhole::transfer_fee { /// Specific governance payload ID (action) for setting Wormhole fee. const ACTION_TRANSFER_FEE: u8 = 4; - struct GovernanceWitness has drop {} + public struct GovernanceWitness has drop {} - struct TransferFee { + public struct TransferFee { amount: u64, recipient: address } @@ -82,7 +80,7 @@ module wormhole::transfer_fee { } fun deserialize(payload: vector): TransferFee { - let cur = cursor::new(payload); + let mut cur = cursor::new(payload); // This amount cannot be greater than max u64. let amount = bytes32::to_u64_be(bytes32::take_bytes(&mut cur)); @@ -107,7 +105,7 @@ module wormhole::transfer_fee { #[test_only] module wormhole::transfer_fee_tests { use sui::balance::{Self}; - use sui::coin::{Self, Coin}; + use sui::coin::{Coin}; use sui::sui::{SUI}; use sui::test_scenario::{Self}; @@ -116,7 +114,6 @@ module wormhole::transfer_fee_tests { use wormhole::cursor::{Self}; use wormhole::external_address::{Self}; use wormhole::governance_message::{Self}; - use wormhole::state::{Self}; use wormhole::transfer_fee::{Self}; use wormhole::vaa::{Self}; use wormhole::version_control::{Self}; @@ -145,7 +142,7 @@ module wormhole::transfer_fee_tests { // Set up. let (caller, recipient) = two_people(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -154,17 +151,16 @@ module wormhole::transfer_fee_tests { // Prepare test to execute `transfer_fee`. test_scenario::next_tx(scenario, caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Double-check current fee (from setup). - assert!(state::message_fee(&worm_state) == wormhole_fee, 0); + assert!(worm_state.message_fee() == wormhole_fee, 0); // Deposit fee several times. - let (i, n) = (0, 8); + let (mut i, n) = (0, 8); while (i < n) { - state::deposit_fee_test_only( - &mut worm_state, + worm_state.deposit_fee_test_only( balance::create_for_testing(wormhole_fee) ); i = i + 1; @@ -172,7 +168,7 @@ module wormhole::transfer_fee_tests { // Double-check balance. let total_deposited = n * wormhole_fee; - assert!(state::fees_collected(&worm_state) == total_deposited, 0); + assert!(worm_state.fees_collected() == total_deposited, 0); let verified_vaa = vaa::parse_and_verify(&worm_state, VAA_TRANSFER_FEE_1, &the_clock); @@ -188,24 +184,24 @@ module wormhole::transfer_fee_tests { assert!(withdrawn == 1200, 0); // Ignore effects. - test_scenario::next_tx(scenario, caller); + scenario.next_tx( caller); // Verify that the recipient received the withdrawal. let withdrawn_coin = - test_scenario::take_from_address>(scenario, recipient); - assert!(coin::value(&withdrawn_coin) == withdrawn, 0); + scenario.take_from_address>(recipient); + assert!(withdrawn_coin.value() == withdrawn, 0); // And there is still a balance on Wormhole's fee collector. let remaining = total_deposited - withdrawn; - assert!(state::fees_collected(&worm_state) == remaining, 0); + assert!(worm_state.fees_collected() == remaining, 0); // Clean up. - coin::burn_for_testing(withdrawn_coin); + withdrawn_coin.burn_for_testing(); return_state(worm_state); return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -215,7 +211,7 @@ module wormhole::transfer_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -225,19 +221,18 @@ module wormhole::transfer_fee_tests { upgrade_wormhole(scenario); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Double-check current fee (from setup). - assert!(state::message_fee(&worm_state) == wormhole_fee, 0); + assert!(worm_state.message_fee() == wormhole_fee, 0); // Deposit fee several times. - let (i, n) = (0, 8); + let (mut i, n) = (0, 8); while (i < n) { - state::deposit_fee_test_only( - &mut worm_state, + worm_state.deposit_fee_test_only( balance::create_for_testing(wormhole_fee) ); i = i + 1; @@ -245,7 +240,7 @@ module wormhole::transfer_fee_tests { // Double-check balance. let total_deposited = n * wormhole_fee; - assert!(state::fees_collected(&worm_state) == total_deposited, 0); + assert!(worm_state.fees_collected() == total_deposited, 0); let verified_vaa = vaa::parse_and_verify(&worm_state, VAA_TRANSFER_FEE_1, &the_clock); @@ -265,7 +260,7 @@ module wormhole::transfer_fee_tests { return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -276,26 +271,25 @@ module wormhole::transfer_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Double-check current fee (from setup). - assert!(state::message_fee(&worm_state) == wormhole_fee, 0); + assert!(worm_state.message_fee() == wormhole_fee, 0); // Deposit fee several times. - let (i, n) = (0, 8); + let (mut i, n) = (0, 8); while (i < n) { - state::deposit_fee_test_only( - &mut worm_state, + worm_state.deposit_fee_test_only( balance::create_for_testing(wormhole_fee) ); i = i + 1; @@ -328,31 +322,31 @@ module wormhole::transfer_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Show balance is zero. - assert!(state::fees_collected(&worm_state) == 0, 0); + assert!(worm_state.fees_collected() == 0, 0); // Show that the encoded fee is greater than zero. let verified_vaa = vaa::parse_and_verify(&worm_state, VAA_TRANSFER_FEE_1, &the_clock); let payload = - governance_message::take_decree(vaa::payload(&verified_vaa)); - let cur = cursor::new(payload); + governance_message::take_decree(verified_vaa.payload()); + let mut cur = cursor::new(payload); let amount = bytes::take_u256_be(&mut cur); assert!(amount > 0, 0); - cursor::take_rest(cur); + cur.take_rest(); let ticket = transfer_fee::authorize_governance(&worm_state); let receipt = @@ -371,20 +365,20 @@ module wormhole::transfer_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Show balance is zero. - assert!(state::fees_collected(&worm_state) == 0, 0); + assert!(worm_state.fees_collected() == 0, 0); // Show that the encoded fee is greater than zero. let verified_vaa = @@ -394,15 +388,15 @@ module wormhole::transfer_fee_tests { &the_clock ); let payload = - governance_message::take_decree(vaa::payload(&verified_vaa)); - let cur = cursor::new(payload); + governance_message::take_decree(verified_vaa.payload()); + let mut cur = cursor::new(payload); bytes::take_u256_be(&mut cur); // Confirm recipient is zero address. let addr = bytes32::take_bytes(&mut cur); assert!(!bytes32::is_nonzero(&addr), 0); - cursor::destroy_empty(cur); + cur.destroy_empty(); let ticket = transfer_fee::authorize_governance(&worm_state); let receipt = @@ -421,20 +415,20 @@ module wormhole::transfer_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Show balance is zero. - assert!(state::fees_collected(&worm_state) == 0, 0); + assert!(worm_state.fees_collected() == 0, 0); // Show that the encoded fee is greater than zero. let verified_vaa = @@ -444,12 +438,12 @@ module wormhole::transfer_fee_tests { &the_clock ); let payload = - governance_message::take_decree(vaa::payload(&verified_vaa)); - let cur = cursor::new(payload); + governance_message::take_decree(verified_vaa.payload()); + let mut cur = cursor::new(payload); let amount = bytes::take_u256_be(&mut cur); assert!(amount > 0xffffffffffffffff, 0); - cursor::take_rest(cur); + cur.take_rest(); let ticket = transfer_fee::authorize_governance(&worm_state); let receipt = @@ -468,26 +462,25 @@ module wormhole::transfer_fee_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Double-check current fee (from setup). - assert!(state::message_fee(&worm_state) == wormhole_fee, 0); + assert!(worm_state.message_fee() == wormhole_fee, 0); // Deposit fee several times. - let (i, n) = (0, 8); + let (mut i, n) = (0, 8); while (i < n) { - state::deposit_fee_test_only( - &mut worm_state, + worm_state.deposit_fee_test_only( balance::create_for_testing(wormhole_fee) ); i = i + 1; @@ -495,19 +488,18 @@ module wormhole::transfer_fee_tests { // Double-check balance. let total_deposited = n * wormhole_fee; - assert!(state::fees_collected(&worm_state) == total_deposited, 0); + assert!(worm_state.fees_collected() == total_deposited, 0); // Prepare test to execute `transfer_fee`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than // this build. - state::migrate_version_test_only( - &mut worm_state, + worm_state.migrate_version_test_only( version_control::previous_version_test_only(), version_control::next_version() ); diff --git a/sui/wormhole/sources/governance/update_guardian_set.move b/sui/wormhole/sources/governance/update_guardian_set.move index 15bfb1953b..9110238402 100644 --- a/sui/wormhole/sources/governance/update_guardian_set.move +++ b/sui/wormhole/sources/governance/update_guardian_set.move @@ -5,7 +5,6 @@ /// this process, the previous guardian set's expiration time is set. Keep in /// mind that the current guardian set has no expiration. module wormhole::update_guardian_set { - use std::vector::{Self}; use sui::clock::{Clock}; use wormhole::bytes::{Self}; @@ -23,14 +22,14 @@ module wormhole::update_guardian_set { /// Specific governance payload ID (action) for updating the guardian set. const ACTION_UPDATE_GUARDIAN_SET: u8 = 2; - struct GovernanceWitness has drop {} + public struct GovernanceWitness has drop {} /// Event reflecting a Guardian Set update. - struct GuardianSetAdded has drop, copy { + public struct GuardianSetAdded has drop, copy { new_index: u32 } - struct UpdateGuardianSet { + public struct UpdateGuardianSet { new_index: u32, guardians: vector, } @@ -110,16 +109,16 @@ module wormhole::update_guardian_set { } fun deserialize(payload: vector): UpdateGuardianSet { - let cur = cursor::new(payload); + let mut cur = cursor::new(payload); let new_index = bytes::take_u32_be(&mut cur); let num_guardians = bytes::take_u8(&mut cur); assert!(num_guardians > 0, E_NO_GUARDIANS); - let guardians = vector::empty(); - let i = 0; + let mut guardians = vector::empty(); + let mut i = 0; while (i < num_guardians) { let key = bytes::take_bytes(&mut cur, 20); - vector::push_back(&mut guardians, guardian::new(key)); + guardians.push_back(guardian::new(key)); i = i + 1; }; cursor::destroy_empty(cur); @@ -135,16 +134,12 @@ module wormhole::update_guardian_set { #[test_only] module wormhole::update_guardian_set_tests { - use std::vector::{Self}; - use sui::clock::{Self}; use sui::test_scenario::{Self}; use wormhole::bytes::{Self}; use wormhole::cursor::{Self}; use wormhole::governance_message::{Self}; use wormhole::guardian::{Self}; - use wormhole::guardian_set::{Self}; - use wormhole::state::{Self}; use wormhole::update_guardian_set::{Self}; use wormhole::vaa::{Self}; use wormhole::version_control::{Self}; @@ -174,17 +169,17 @@ module wormhole::update_guardian_set_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `update_guardian_set`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); - let the_clock = take_clock(scenario); + let mut worm_state = take_state(scenario); + let mut the_clock = take_clock(scenario); let verified_vaa = vaa::parse_and_verify( @@ -200,17 +195,17 @@ module wormhole::update_guardian_set_tests { assert!(new_index == 1, 0); let new_guardian_set = - state::guardian_set_at(&worm_state, new_index); + worm_state.guardian_set_at(new_index); // Verify new guardian set index. - assert!(state::guardian_set_index(&worm_state) == new_index, 0); + assert!(worm_state.guardian_set_index() == new_index, 0); assert!( - guardian_set::index(new_guardian_set) == state::guardian_set_index(&worm_state), + new_guardian_set.index() == worm_state.guardian_set_index(), 0 ); // Check that the guardians agree with what we expect. - let guardians = guardian_set::guardians(new_guardian_set); + let guardians = new_guardian_set.guardians(); let expected = vector[ guardian::new(x"befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe"), guardian::new(x"88d7d8b32a9105d228100e72dffe2fae0705d31c"), @@ -232,39 +227,39 @@ module wormhole::update_guardian_set_tests { guardian::new(x"246ab29fc6ebedf2d392a51ab2dc5c59d0902a03"), guardian::new(x"132a84dfd920b35a3d0ba5f7a0635df298f9033e"), ]; - assert!(vector::length(&expected) == vector::length(guardians), 0); + assert!(expected.length() == guardians.length(), 0); - let cur = cursor::new(expected); - let i = 0; - while (!cursor::is_empty(&cur)) { - let left = guardian::as_bytes(vector::borrow(guardians, i)); - let right = guardian::to_bytes(cursor::poke(&mut cur)); + let mut cur = cursor::new(expected); + let mut i = 0; + while (!cur.is_empty()) { + let left = guardian::as_bytes(guardians.borrow(i)); + let right = guardian::to_bytes(cur.poke()); assert!(left == right, 0); i = i + 1; }; - cursor::destroy_empty(cur); + cur.destroy_empty(); // Make sure old guardian set is still active. let old_guardian_set = - state::guardian_set_at(&worm_state, new_index - 1); - assert!(guardian_set::is_active(old_guardian_set, &the_clock), 0); + worm_state.guardian_set_at(new_index - 1); + assert!(old_guardian_set.is_active(&the_clock), 0); // Fast forward time beyond expiration by // `guardian_set_seconds_to_live`. let tick_ms = - (state::guardian_set_seconds_to_live(&worm_state) as u64) * 1000; - clock::increment_for_testing(&mut the_clock, tick_ms + 1); + (worm_state.guardian_set_seconds_to_live() as u64) * 1000; + the_clock.increment_for_testing( tick_ms + 1); // Now the old guardian set should be expired (because in the test setup // time to live is set to 2 epochs). - assert!(!guardian_set::is_active(old_guardian_set, &the_clock), 0); + assert!(!old_guardian_set.is_active(&the_clock), 0); // Clean up. return_state(worm_state); return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -274,7 +269,7 @@ module wormhole::update_guardian_set_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -284,9 +279,9 @@ module wormhole::update_guardian_set_tests { upgrade_wormhole(scenario); // Prepare test to execute `update_guardian_set`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); let verified_vaa = @@ -307,7 +302,7 @@ module wormhole::update_guardian_set_tests { return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -320,16 +315,16 @@ module wormhole::update_guardian_set_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `update_guardian_set`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); let verified_vaa = @@ -356,7 +351,7 @@ module wormhole::update_guardian_set_tests { let new_index = update_guardian_set(&mut worm_state, receipt, &the_clock); assert!(new_index == 2, 0); - assert!(state::guardian_set_index(&worm_state) == 2, 0); + assert!(worm_state.guardian_set_index() == 2, 0); let verified_vaa = vaa::parse_and_verify( @@ -381,16 +376,16 @@ module wormhole::update_guardian_set_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `update_guardian_set`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); @@ -403,7 +398,7 @@ module wormhole::update_guardian_set_tests { ); let payload = governance_message::take_decree(vaa::payload(&verified_vaa)); - let cur = cursor::new(payload); + let mut cur = cursor::new(payload); let new_guardian_set_index = bytes::take_u32_be(&mut cur); assert!(new_guardian_set_index == 1, 0); @@ -411,7 +406,7 @@ module wormhole::update_guardian_set_tests { let num_guardians = bytes::take_u8(&mut cur); assert!(num_guardians == 0, 0); - cursor::destroy_empty(cur); + cur.destroy_empty(); let ticket = update_guardian_set::authorize_governance(&worm_state); let receipt = @@ -430,26 +425,25 @@ module wormhole::update_guardian_set_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; set_up_wormhole(scenario, wormhole_fee); // Prepare test to execute `update_guardian_set`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than // this build. - state::migrate_version_test_only( - &mut worm_state, + worm_state.migrate_version_test_only( version_control::previous_version_test_only(), version_control::next_version() ); diff --git a/sui/wormhole/sources/governance/upgrade_contract.move b/sui/wormhole/sources/governance/upgrade_contract.move index 018511e784..a2c235e3ee 100644 --- a/sui/wormhole/sources/governance/upgrade_contract.move +++ b/sui/wormhole/sources/governance/upgrade_contract.move @@ -8,7 +8,6 @@ /// 3. Upgrade. /// 4. Commit upgrade. module wormhole::upgrade_contract { - use sui::object::{ID}; use sui::package::{UpgradeReceipt, UpgradeTicket}; use wormhole::bytes32::{Self, Bytes32}; @@ -16,7 +15,6 @@ module wormhole::upgrade_contract { use wormhole::governance_message::{Self, DecreeTicket, DecreeReceipt}; use wormhole::state::{Self, State}; - friend wormhole::migrate; /// Digest is all zeros. const E_DIGEST_ZERO_BYTES: u64 = 0; @@ -25,15 +23,15 @@ module wormhole::upgrade_contract { /// contract. const ACTION_UPGRADE_CONTRACT: u8 = 1; - struct GovernanceWitness has drop {} + public struct GovernanceWitness has drop {} // Event reflecting package upgrade. - struct ContractUpgraded has drop, copy { + public struct ContractUpgraded has drop, copy { old_contract: ID, new_contract: ID } - struct UpgradeContract { + public struct UpgradeContract { digest: Bytes32 } @@ -88,7 +86,7 @@ module wormhole::upgrade_contract { /// /// During migration, we make sure that the digest equals what we expect by /// passing in the same VAA used to upgrade the package. - public(friend) fun take_digest(governance_payload: vector): Bytes32 { + public(package) fun take_digest(governance_payload: vector): Bytes32 { // Deserialize the payload as the build digest. let UpgradeContract { digest } = deserialize(governance_payload); @@ -103,13 +101,13 @@ module wormhole::upgrade_contract { } fun deserialize(payload: vector): UpgradeContract { - let cur = cursor::new(payload); + let mut cur = cursor::new(payload); // This amount cannot be greater than max u64. let digest = bytes32::take_bytes(&mut cur); assert!(bytes32::is_nonzero(&digest), E_DIGEST_ZERO_BYTES); - cursor::destroy_empty(cur); + cur.destroy_empty(); UpgradeContract { digest } } diff --git a/sui/wormhole/sources/governance_message.move b/sui/wormhole/sources/governance_message.move index 20d4cfee5f..e050a243ea 100644 --- a/sui/wormhole/sources/governance_message.move +++ b/sui/wormhole/sources/governance_message.move @@ -33,7 +33,7 @@ module wormhole::governance_message { /// and `authorize_verify_local`) require a witness of type `T`. This is to /// ensure that `DecreeTicket`s cannot be mixed up between modules /// maliciously. - struct DecreeTicket { + public struct DecreeTicket { governance_chain: u16, governance_contract: ExternalAddress, module_name: Bytes32, @@ -41,7 +41,7 @@ module wormhole::governance_message { global: bool } - struct DecreeReceipt { + public struct DecreeReceipt { payload: vector, digest: Bytes32, sequence: u64 @@ -173,7 +173,7 @@ module wormhole::governance_message { } fun deserialize(buf: vector): (Bytes32, u8, u16, vector) { - let cur = cursor::new(buf); + let mut cur = cursor::new(buf); ( bytes32::take_bytes(&mut cur), @@ -205,7 +205,6 @@ module wormhole::governance_message { #[test_only] module wormhole::governance_message_tests { use sui::test_scenario::{Self}; - use sui::tx_context::{Self}; use wormhole::bytes32::{Self}; use wormhole::consumed_vaas::{Self}; @@ -223,7 +222,7 @@ module wormhole::governance_message_tests { take_state }; - struct GovernanceWitness has drop {} + public struct GovernanceWitness has drop {} const VAA_UPDATE_GUARDIAN_SET_1: vector = x"010000000001004f74e9596bd8246ef456918594ae16e81365b52c0cf4490b2a029fb101b058311f4a5592baeac014dc58215faad36453467a85a4c3e1c6cf5166e80f6e4dc50b0100bc614e000000000001000000000000000000000000000000000000000000000000000000000000000400000000000000010100000000000000000000000000000000000000000000000000000000436f72650200000000000113befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe88d7d8b32a9105d228100e72dffe2fae0705d31c58076f561cc62a47087b567c86f986426dfcd000bd6e9833490f8fa87c733a183cd076a6cbd29074b853fcf0a5c78c1b56d15fce7a154e6ebe9ed7a2af3503dbd2e37518ab04d7ce78b630f98b15b78a785632dea5609064803b1c8ea8bb2c77a6004bd109a281a698c0f5ba31f158585b41f4f33659e54d3178443ab76a60e21690dbfb17f7f59f09ae3ea1647ec26ae49b14060660504f4da1c2059e1c5ab6810ac3d8e1258bd2f004a94ca0cd4c68fc1c061180610e96d645b12f47ae5cf4546b18538739e90f2edb0d8530e31a218e72b9480202acbaeb06178da78858e5e5c4705cdd4b668ffe3be5bae4867c9d5efe3a05efc62d60e1d19faeb56a80223cdd3472d791b7d32c05abb1cc00b6381fa0c4928f0c56fc14bc029b8809069093d712a3fd4dfab31963597e246ab29fc6ebedf2d392a51ab2dc5c59d0902a03132a84dfd920b35a3d0ba5f7a0635df298f9033e"; @@ -234,7 +233,7 @@ module wormhole::governance_message_tests { fun test_global_action() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -272,7 +271,7 @@ module wormhole::governance_message_tests { let receipt = governance_message::verify_vaa(&worm_state, verified_vaa, ticket); - let consumed = consumed_vaas::new(&mut tx_context::dummy()); + let mut consumed = consumed_vaas::new(&mut tx_context::dummy()); let payload = governance_message::take_payload(&mut consumed, receipt); assert!(payload == expected_payload, 0); @@ -289,7 +288,7 @@ module wormhole::governance_message_tests { fun test_local_action() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -323,7 +322,7 @@ module wormhole::governance_message_tests { let receipt = governance_message::verify_vaa(&worm_state, verified_vaa, ticket); - let consumed = consumed_vaas::new(&mut tx_context::dummy()); + let mut consumed = consumed_vaas::new(&mut tx_context::dummy()); let payload = governance_message::take_payload(&mut consumed, receipt); assert!(payload == expected_payload, 0); @@ -343,7 +342,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_invalid_governance_chain() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -388,7 +387,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_invalid_governance_emitter() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -433,7 +432,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_invalid_governance_module() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -486,7 +485,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_invalid_governance_action() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -539,7 +538,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_governance_target_chain_nonzero() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -592,7 +591,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_governance_target_chain_not_sui() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -647,7 +646,7 @@ module wormhole::governance_message_tests { fun test_cannot_verify_vaa_outdated_version() { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; let wormhole_fee = 350; @@ -656,7 +655,7 @@ module wormhole::governance_message_tests { // Prepare test setting sender to `caller`. test_scenario::next_tx(scenario, caller); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); let verified_vaa = diff --git a/sui/wormhole/sources/migrate.move b/sui/wormhole/sources/migrate.move index 958a0b12f8..0fb8eff9f9 100644 --- a/sui/wormhole/sources/migrate.move +++ b/sui/wormhole/sources/migrate.move @@ -9,7 +9,6 @@ /// required minimum version. module wormhole::migrate { use sui::clock::{Clock}; - use sui::object::{ID}; use wormhole::governance_message::{Self}; use wormhole::state::{Self, State}; @@ -17,7 +16,7 @@ module wormhole::migrate { use wormhole::vaa::{Self}; /// Event reflecting when `migrate` is successfully executed. - struct MigrateComplete has drop, copy { + public struct MigrateComplete has drop, copy { package: ID } @@ -107,7 +106,6 @@ module wormhole::migrate { module wormhole::migrate_tests { use sui::test_scenario::{Self}; - use wormhole::state::{Self}; use wormhole::wormhole_scenario::{ person, return_clock, @@ -126,7 +124,7 @@ module wormhole::migrate_tests { use wormhole::migrate::{migrate}; let user = person(); - let my_scenario = test_scenario::begin(user); + let mut my_scenario = test_scenario::begin(user); let scenario = &mut my_scenario; // Initialize Wormhole. @@ -134,15 +132,15 @@ module wormhole::migrate_tests { set_up_wormhole(scenario, wormhole_message_fee); // Next transaction should be conducted as an ordinary user. - test_scenario::next_tx(scenario, user); + scenario.next_tx(user); // Upgrade (digest is just b"new build") for testing purposes. upgrade_wormhole(scenario); // Ignore effects. - test_scenario::next_tx(scenario, user); + scenario.next_tx(user); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Set up migrate (which prepares this package to be the same state as @@ -150,7 +148,7 @@ module wormhole::migrate_tests { wormhole::migrate::set_up_migrate(&mut worm_state); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than @@ -158,7 +156,7 @@ module wormhole::migrate_tests { migrate(&mut worm_state, UPGRADE_VAA, &the_clock); // Make sure we emitted an event. - let effects = test_scenario::next_tx(scenario, user); + let effects = scenario.next_tx(user); assert!(test_scenario::num_user_events(&effects) == 1, 0); // Clean up. @@ -166,7 +164,7 @@ module wormhole::migrate_tests { return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -177,7 +175,7 @@ module wormhole::migrate_tests { use wormhole::migrate::{migrate}; let user = person(); - let my_scenario = test_scenario::begin(user); + let mut my_scenario = test_scenario::begin(user); let scenario = &mut my_scenario; // Initialize Wormhole. @@ -185,15 +183,15 @@ module wormhole::migrate_tests { set_up_wormhole(scenario, wormhole_message_fee); // Next transaction should be conducted as an ordinary user. - test_scenario::next_tx(scenario, user); + scenario.next_tx(user); // Upgrade (digest is just b"new build") for testing purposes. upgrade_wormhole(scenario); // Ignore effects. - test_scenario::next_tx(scenario, user); + scenario.next_tx(user); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // Set up migrate (which prepares this package to be the same state as @@ -201,7 +199,7 @@ module wormhole::migrate_tests { wormhole::migrate::set_up_migrate(&mut worm_state); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than @@ -209,7 +207,7 @@ module wormhole::migrate_tests { migrate(&mut worm_state, UPGRADE_VAA, &the_clock); // Make sure we emitted an event. - let effects = test_scenario::next_tx(scenario, user); + let effects = scenario.next_tx(user); assert!(test_scenario::num_user_events(&effects) == 1, 0); // You shall not pass! diff --git a/sui/wormhole/sources/publish_message.move b/sui/wormhole/sources/publish_message.move index 3255fee5ba..3f1d9d3f45 100644 --- a/sui/wormhole/sources/publish_message.move +++ b/sui/wormhole/sources/publish_message.move @@ -26,7 +26,6 @@ module wormhole::publish_message { use sui::coin::{Self, Coin}; use sui::clock::{Self, Clock}; - use sui::object::{Self, ID}; use sui::sui::{SUI}; use wormhole::emitter::{Self, EmitterCap}; @@ -34,7 +33,7 @@ module wormhole::publish_message { /// This type is emitted via `sui::event` module. Guardians pick up this /// observation and attest to its existence. - struct WormholeMessage has drop, copy { + public struct WormholeMessage has drop, copy { /// `EmitterCap` object ID. sender: ID, /// From `EmitterCap`. @@ -54,7 +53,7 @@ module wormhole::publish_message { /// The only way to destroy this type is calling `publish_message` with /// a fee to emit a `WormholeMessage` with the unpacked members of this /// struct. - struct MessageTicket { + public struct MessageTicket { /// `EmitterCap` object ID. sender: ID, /// From `EmitterCap`. @@ -188,7 +187,7 @@ module wormhole::publish_message_tests { use wormhole::publish_message::{prepare_message, publish_message}; let user = person(); - let my_scenario = test_scenario::begin(user); + let mut my_scenario = test_scenario::begin(user); let scenario = &mut my_scenario; let wormhole_message_fee = 100000000; @@ -197,22 +196,22 @@ module wormhole::publish_message_tests { set_up_wormhole(scenario, wormhole_message_fee); // Next transaction should be conducted as an ordinary user. - test_scenario::next_tx(scenario, user); + scenario.next_tx(user); { - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // User needs an `EmitterCap` so he can send a message. - let emitter_cap = + let mut emitter_cap = wormhole::emitter::new( &worm_state, test_scenario::ctx(scenario) ); // Check for event corresponding to new emitter. - let effects = test_scenario::next_tx(scenario, user); - assert!(test_scenario::num_user_events(&effects) == 1, 0); + let effects = scenario.next_tx(user); + assert!(effects.num_user_events() == 1, 0); // Prepare message. let msg = @@ -259,17 +258,17 @@ module wormhole::publish_message_tests { // Clean up. return_state(worm_state); return_clock(the_clock); - sui::transfer::public_transfer(emitter_cap, user); + transfer::public_transfer(emitter_cap, user); }; // Grab the `TransactionEffects` of the previous transaction. - let effects = test_scenario::next_tx(scenario, user); + let effects = scenario.next_tx(user); // We expect two events (the Wormhole messages). `test_scenario` does // not give us an in-depth view of the event specifically. But we can // check that there was an event associated with the previous // transaction. - assert!(test_scenario::num_user_events(&effects) == 2, 0); + assert!(effects.num_user_events() == 2, 0); // Simulate upgrade and confirm that publish message still works. { @@ -278,9 +277,9 @@ module wormhole::publish_message_tests { // Ignore effects from upgrade. test_scenario::next_tx(scenario, user); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); - let emitter_cap = + let mut emitter_cap = test_scenario::take_from_sender(scenario); let msg = @@ -303,13 +302,13 @@ module wormhole::publish_message_tests { assert!(sequence == 2, 0); // Clean up. - test_scenario::return_to_sender(scenario, emitter_cap); + scenario.return_to_sender(emitter_cap); return_state(worm_state); return_clock(the_clock); }; // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -320,7 +319,7 @@ module wormhole::publish_message_tests { use wormhole::publish_message::{prepare_message, publish_message}; let user = person(); - let my_scenario = test_scenario::begin(user); + let mut my_scenario = test_scenario::begin(user); let scenario = &mut my_scenario; let wormhole_message_fee = 100000000; @@ -332,11 +331,11 @@ module wormhole::publish_message_tests { // Next transaction should be conducted as an ordinary user. test_scenario::next_tx(scenario, user); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // User needs an `EmitterCap` so he can send a message. - let emitter_cap = + let mut emitter_cap = emitter::new(&worm_state, test_scenario::ctx(scenario)); let msg = @@ -357,7 +356,7 @@ module wormhole::publish_message_tests { ); // Clean up. - emitter::destroy_test_only(emitter_cap); + emitter_cap.destroy_test_only(); abort 42 } @@ -370,7 +369,7 @@ module wormhole::publish_message_tests { use wormhole::publish_message::{prepare_message, publish_message}; let user = person(); - let my_scenario = test_scenario::begin(user); + let mut my_scenario = test_scenario::begin(user); let scenario = &mut my_scenario; let wormhole_message_fee = 100000000; @@ -379,13 +378,13 @@ module wormhole::publish_message_tests { set_up_wormhole(scenario, wormhole_message_fee); // Next transaction should be conducted as an ordinary user. - test_scenario::next_tx(scenario, user); + scenario.next_tx(user); - let worm_state = take_state(scenario); + let mut worm_state = take_state(scenario); let the_clock = take_clock(scenario); // User needs an `EmitterCap` so he can send a message. - let emitter_cap = + let mut emitter_cap = emitter::new(&worm_state, test_scenario::ctx(scenario)); // Conveniently roll version back. @@ -419,7 +418,7 @@ module wormhole::publish_message_tests { ); // Clean up. - emitter::destroy_test_only(emitter_cap); + emitter_cap.destroy_test_only(); abort 42 } diff --git a/sui/wormhole/sources/resources/consumed_vaas.move b/sui/wormhole/sources/resources/consumed_vaas.move index a09327cf7e..fef240ea4e 100644 --- a/sui/wormhole/sources/resources/consumed_vaas.move +++ b/sui/wormhole/sources/resources/consumed_vaas.move @@ -1,5 +1,4 @@ module wormhole::consumed_vaas { - use sui::tx_context::{TxContext}; use wormhole::bytes32::{Bytes32}; use wormhole::set::{Self, Set}; @@ -9,7 +8,7 @@ module wormhole::consumed_vaas { /// is up to the integrator to have this container live in his contract /// in order to take advantage of this no-replay protection. Or an /// integrator can implement his own method to prevent replay. - struct ConsumedVAAs has store { + public struct ConsumedVAAs has store { hashes: Set } diff --git a/sui/wormhole/sources/resources/fee_collector.move b/sui/wormhole/sources/resources/fee_collector.move index f75ab49719..d03b7349a2 100644 --- a/sui/wormhole/sources/resources/fee_collector.move +++ b/sui/wormhole/sources/resources/fee_collector.move @@ -7,13 +7,12 @@ module wormhole::fee_collector { use sui::balance::{Self, Balance}; use sui::coin::{Self, Coin}; use sui::sui::{SUI}; - use sui::tx_context::{TxContext}; /// Amount deposited is not exactly the amount configured. const E_INCORRECT_FEE: u64 = 0; /// Container for configured `fee_amount` and `balance` of SUI collected. - struct FeeCollector has store { + public struct FeeCollector has store { fee_amount: u64, balance: Balance } @@ -77,7 +76,6 @@ module wormhole::fee_collector { #[test_only] module wormhole::fee_collector_tests { use sui::coin::{Self}; - use sui::tx_context::{Self}; use wormhole::fee_collector::{Self}; @@ -86,7 +84,7 @@ module wormhole::fee_collector_tests { let ctx = &mut tx_context::dummy(); let fee_amount = 350; - let collector = fee_collector::new(fee_amount); + let mut collector = fee_collector::new(fee_amount); // We expect the fee_amount to be the same as what we specified and // no balance on `FeeCollector` yet. @@ -95,39 +93,39 @@ module wormhole::fee_collector_tests { // Deposit fee once. let fee = coin::mint_for_testing(fee_amount, ctx); - fee_collector::deposit(&mut collector, fee); - assert!(fee_collector::balance_value(&collector) == fee_amount, 0); + collector.deposit(fee); + assert!(collector.balance_value() == fee_amount, 0); // Now deposit nine more times and check the aggregate balance. - let i = 0; + let mut i = 0; while (i < 9) { let fee = coin::mint_for_testing(fee_amount, ctx); - fee_collector::deposit(&mut collector, fee); + collector.deposit(fee); i = i + 1; }; - let total = fee_collector::balance_value(&collector); + let total = collector.balance_value(); assert!(total == 10 * fee_amount, 0); // Withdraw a fifth. let withdraw_amount = total / 5; let withdrawn = - fee_collector::withdraw(&mut collector, withdraw_amount, ctx); - assert!(coin::value(&withdrawn) == withdraw_amount, 0); - coin::burn_for_testing(withdrawn); + collector.withdraw(withdraw_amount, ctx); + assert!(withdrawn.value() == withdraw_amount, 0); + withdrawn.burn_for_testing(); - let remaining = fee_collector::balance_value(&collector); + let remaining = collector.balance_value(); assert!(remaining == total - withdraw_amount, 0); // Withdraw remaining. - let withdrawn = fee_collector::withdraw(&mut collector, remaining, ctx); - assert!(coin::value(&withdrawn) == remaining, 0); - coin::burn_for_testing(withdrawn); + let withdrawn = collector.withdraw(remaining, ctx); + assert!(withdrawn.value() == remaining, 0); + withdrawn.burn_for_testing(); // There shouldn't be anything left in `FeeCollector`. - assert!(fee_collector::balance_value(&collector) == 0, 0); + assert!(collector.balance_value() == 0, 0); // Done. - fee_collector::destroy(collector); + collector.destroy(); } #[test] @@ -136,11 +134,11 @@ module wormhole::fee_collector_tests { let ctx = &mut tx_context::dummy(); let fee_amount = 350; - let collector = fee_collector::new(fee_amount); + let mut collector = fee_collector::new(fee_amount); // You shall not pass! let fee = coin::mint_for_testing(fee_amount + 1, ctx); - fee_collector::deposit(&mut collector, fee); + collector.deposit(fee); abort 42 } @@ -151,19 +149,19 @@ module wormhole::fee_collector_tests { let ctx = &mut tx_context::dummy(); let fee_amount = 350; - let collector = fee_collector::new(fee_amount); + let mut collector = fee_collector::new(fee_amount); // Deposit once. let fee = coin::mint_for_testing(fee_amount, ctx); - fee_collector::deposit(&mut collector, fee); + collector.deposit(fee); // Attempt to withdraw more than the balance. - let bal = fee_collector::balance_value(&collector); + let bal = collector.balance_value(); let withdrawn = - fee_collector::withdraw(&mut collector, bal + 1, ctx); + collector.withdraw(bal + 1, ctx); // Shouldn't get here. But we need to clean up anyway. - coin::burn_for_testing(withdrawn); + withdrawn.burn_for_testing(); abort 42 } diff --git a/sui/wormhole/sources/resources/guardian.move b/sui/wormhole/sources/resources/guardian.move index 84c6a48eb1..b1d62b6216 100644 --- a/sui/wormhole/sources/resources/guardian.move +++ b/sui/wormhole/sources/resources/guardian.move @@ -2,7 +2,6 @@ /// This module implements a `Guardian` that warehouses a 20-byte public key. module wormhole::guardian { - use std::vector::{Self}; use sui::hash::{Self}; use sui::ecdsa_k1::{Self}; @@ -13,7 +12,7 @@ module wormhole::guardian { const E_ZERO_ADDRESS: u64 = 1; /// Container for 20-byte Guardian public key. - struct Guardian has store { + public struct Guardian has store { pubkey: Bytes20 } @@ -48,24 +47,23 @@ module wormhole::guardian { /// Same as 'ecrecover' in EVM. fun ecrecover(message: vector, sig: vector): vector { - let pubkey = + let mut pubkey = ecdsa_k1::decompress_pubkey(&ecdsa_k1::secp256k1_ecrecover(&sig, &message, 0)); // `decompress_pubkey` returns 65 bytes. The last 64 bytes are what we // need to compute the Guardian's public key. - vector::remove(&mut pubkey, 0); + pubkey.remove(0); - let hash = hash::keccak256(&pubkey); - let guardian_pubkey = vector::empty(); - let (i, n) = (0, bytes20::length()); + let mut hash = hash::keccak256(&pubkey); + let mut guardian_pubkey = vector::empty(); + let (mut i, n) = (0, bytes20::length()); while (i < n) { - vector::push_back( - &mut guardian_pubkey, - vector::pop_back(&mut hash) + guardian_pubkey.push_back( + hash.pop_back() ); i = i + 1; }; - vector::reverse(&mut guardian_pubkey); + guardian_pubkey.reverse(); guardian_pubkey } diff --git a/sui/wormhole/sources/resources/guardian_set.move b/sui/wormhole/sources/resources/guardian_set.move index e55ccd3758..ef5156a784 100644 --- a/sui/wormhole/sources/resources/guardian_set.move +++ b/sui/wormhole/sources/resources/guardian_set.move @@ -8,20 +8,17 @@ /// If the current Guardian set is not the latest one, its `expiration_time` is /// configured, which defines how long the past Guardian set can be active. module wormhole::guardian_set { - use std::vector::{Self}; use sui::clock::{Self, Clock}; use wormhole::guardian::{Self, Guardian}; - // Needs `set_expiration`. - friend wormhole::state; /// Found duplicate public key. const E_DUPLICATE_GUARDIAN: u64 = 0; /// Container for the list of Guardian public keys, its index value and at /// what point in time the Guardian set is configured to expire. - struct GuardianSet has store { + public struct GuardianSet has store { /// A.K.A. Guardian set index. index: u32, @@ -35,12 +32,12 @@ module wormhole::guardian_set { /// Create new `GuardianSet`. public fun new(index: u32, guardians: vector): GuardianSet { // Ensure that there are no duplicate guardians. - let (i, n) = (0, vector::length(&guardians)); + let (mut i, n) = (0, guardians.length()); while (i < n - 1) { - let left = guardian::pubkey(vector::borrow(&guardians, i)); - let j = i + 1; + let left = guardian::pubkey(guardians.borrow(i)); + let mut j = i + 1; while (j < n) { - let right = guardian::pubkey(vector::borrow(&guardians, j)); + let right = guardian::pubkey(guardians.borrow(j)); assert!(left != right, E_DUPLICATE_GUARDIAN); j = j + 1; }; @@ -100,7 +97,7 @@ module wormhole::guardian_set { /// /// NOTE: `time_to_live` is in units of seconds while `Clock` uses /// milliseconds. - public(friend) fun set_expiration( + public(package) fun set_expiration( self: &mut GuardianSet, seconds_to_live: u32, the_clock: &Clock @@ -111,33 +108,29 @@ module wormhole::guardian_set { #[test_only] public fun destroy(set: GuardianSet) { - use wormhole::guardian::{Self}; - let GuardianSet { index: _, - guardians, + mut guardians, expiration_timestamp_ms: _ } = set; - while (!vector::is_empty(&guardians)) { - guardian::destroy(vector::pop_back(&mut guardians)); + while (!guardians.is_empty()) { + guardians.pop_back().destroy(); }; - vector::destroy_empty(guardians); + guardians.destroy_empty(); } } #[test_only] module wormhole::guardian_set_tests { - use std::vector::{Self}; - use wormhole::guardian::{Self}; use wormhole::guardian_set::{Self}; #[test] fun test_new() { - let guardians = vector::empty(); + let mut guardians = vector::empty(); - let pubkeys = vector[ + let mut pubkeys = vector[ x"8888888888888888888888888888888888888888", x"9999999999999999999999999999999999999999", x"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", @@ -147,25 +140,24 @@ module wormhole::guardian_set_tests { x"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", x"ffffffffffffffffffffffffffffffffffffffff" ]; - while (!vector::is_empty(&pubkeys)) { - vector::push_back( - &mut guardians, - guardian::new(vector::pop_back(&mut pubkeys)) + while (!pubkeys.is_empty()) { + guardians.push_back( + guardian::new(pubkeys.pop_back()) ); }; let set = guardian_set::new(69, guardians); // Clean up. - guardian_set::destroy(set); + set.destroy(); } #[test] #[expected_failure(abort_code = guardian_set::E_DUPLICATE_GUARDIAN)] fun test_cannot_new_duplicate_guardian() { - let guardians = vector::empty(); + let mut guardians = vector::empty(); - let pubkeys = vector[ + let mut pubkeys = vector[ x"8888888888888888888888888888888888888888", x"9999999999999999999999999999999999999999", x"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", @@ -176,17 +168,16 @@ module wormhole::guardian_set_tests { x"ffffffffffffffffffffffffffffffffffffffff", x"cccccccccccccccccccccccccccccccccccccccc", ]; - while (!vector::is_empty(&pubkeys)) { - vector::push_back( - &mut guardians, - guardian::new(vector::pop_back(&mut pubkeys)) + while (!pubkeys.is_empty()) { + guardians.push_back( + guardian::new(pubkeys.pop_back()) ); }; let set = guardian_set::new(69, guardians); // Clean up. - guardian_set::destroy(set); + set.destroy(); abort 42 } diff --git a/sui/wormhole/sources/resources/set.move b/sui/wormhole/sources/resources/set.move index bb52326489..788c8f5763 100644 --- a/sui/wormhole/sources/resources/set.move +++ b/sui/wormhole/sources/resources/set.move @@ -6,7 +6,6 @@ /// NOTE: Items added to this data structure cannot be removed. module wormhole::set { use sui::table::{Self, Table}; - use sui::tx_context::{TxContext}; /// Explicit error if key already exists in `Set`. const E_KEY_ALREADY_EXISTS: u64 = 0; @@ -14,11 +13,11 @@ module wormhole::set { const E_KEY_NONEXISTENT: u64 = 1; /// Empty struct. Used as the value type in mappings to encode a set - struct Empty has store, drop {} + public struct Empty has store, drop {} /// A set containing elements of type `T` with support for membership /// checking. - struct Set has store { + public struct Set has store { items: Table } @@ -54,35 +53,33 @@ module wormhole::set { #[test_only] module wormhole::set_tests { - use sui::tx_context::{Self}; - use wormhole::set::{Self}; #[test] public fun test_add_and_contains() { let ctx = &mut tx_context::dummy(); - let my_set = set::new(ctx); + let mut my_set = set::new(ctx); - let (i, n) = (0, 256); + let (mut i, n) = (0, 256); while (i < n) { - set::add(&mut my_set, i); + my_set.add( i); i = i + 1; }; // Check that the set has the values just added. - let i = 0; + let mut i = 0; while (i < n) { - assert!(set::contains(&my_set, i), 0); + assert!(my_set.contains(i), 0); i = i + 1; }; // Check that these values that were not added are not in the set. while (i < 2 * n) { - assert!(!set::contains(&my_set, i), 0); + assert!(!my_set.contains(i), 0); i = i + 1; }; - set::destroy(my_set); + my_set.destroy(); } } diff --git a/sui/wormhole/sources/setup.move b/sui/wormhole/sources/setup.move index c7f233e102..23c79a5e76 100644 --- a/sui/wormhole/sources/setup.move +++ b/sui/wormhole/sources/setup.move @@ -3,11 +3,7 @@ /// This module implements the mechanism to publish the Wormhole contract and /// initialize `State` as a shared object. module wormhole::setup { - use std::vector::{Self}; - use sui::object::{Self, UID}; use sui::package::{Self, UpgradeCap}; - use sui::transfer::{Self}; - use sui::tx_context::{Self, TxContext}; use wormhole::cursor::{Self}; use wormhole::state::{Self}; @@ -15,7 +11,7 @@ module wormhole::setup { /// Capability created at `init`, which will be destroyed once /// `init_and_share_state` is called. This ensures only the deployer can /// create the shared `State`. - struct DeployerCap has key, store { + public struct DeployerCap has key, store { id: UID } @@ -65,8 +61,8 @@ module wormhole::setup { object::delete(id); let guardians = { - let out = vector::empty(); - let cur = cursor::new(initial_guardians); + let mut out = vector::empty(); + let mut cur = cursor::new(initial_guardians); while (!cursor::is_empty(&cur)) { vector::push_back( &mut out, @@ -97,10 +93,7 @@ module wormhole::setup { #[test_only] module wormhole::setup_tests { - use std::option::{Self}; - use std::vector::{Self}; use sui::package::{Self}; - use sui::object::{Self}; use sui::test_scenario::{Self}; use wormhole::bytes32::{Self}; @@ -109,29 +102,28 @@ module wormhole::setup_tests { use wormhole::guardian::{Self}; use wormhole::guardian_set::{Self}; use wormhole::setup::{Self, DeployerCap}; - use wormhole::state::{Self, State}; + use wormhole::state::{State}; use wormhole::wormhole_scenario::{person}; #[test] fun test_init() { let deployer = person(); - let my_scenario = test_scenario::begin(deployer); + let mut my_scenario = test_scenario::begin(deployer); let scenario = &mut my_scenario; // Initialize Wormhole smart contract. - setup::init_test_only(test_scenario::ctx(scenario)); + setup::init_test_only(scenario.ctx()); // Process effects of `init`. - let effects = test_scenario::next_tx(scenario, deployer); + let effects = scenario.next_tx(deployer); // We expect two objects to be created: `DeployerCap` and `UpgradeCap`. - assert!(vector::length(&test_scenario::created(&effects)) == 2, 0); + assert!(&effects.created().length() == 2, 0); // We should be able to take the `DeployerCap` from the sender // of the transaction. let cap = - test_scenario::take_from_address( - scenario, + scenario.take_from_address( deployer ); @@ -139,20 +131,20 @@ module wormhole::setup_tests { test_scenario::return_to_address(deployer, cap); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] fun test_complete() { let deployer = person(); - let my_scenario = test_scenario::begin(deployer); + let mut my_scenario = test_scenario::begin(deployer); let scenario = &mut my_scenario; // Initialize Wormhole smart contract. - setup::init_test_only(test_scenario::ctx(scenario)); + setup::init_test_only(scenario.ctx()); // Ignore effects. - test_scenario::next_tx(scenario, deployer); + scenario.next_tx(deployer); let governance_chain = 1234; let governance_contract = @@ -169,8 +161,7 @@ module wormhole::setup_tests { // Take the `DeployerCap` and move it to `init_and_share_state`. let deployer_cap = - test_scenario::take_from_address( - scenario, + scenario.take_from_address( deployer ); let deployer_cap_id = object::id(&deployer_cap); @@ -181,7 +172,7 @@ module wormhole::setup_tests { let upgrade_cap = package::test_publish( object::id_from_address(@wormhole), - test_scenario::ctx(scenario) + scenario.ctx() ); setup::complete( @@ -193,59 +184,59 @@ module wormhole::setup_tests { initial_guardians, guardian_set_seconds_to_live, message_fee, - test_scenario::ctx(scenario) + scenario.ctx() ); // Process effects. - let effects = test_scenario::next_tx(scenario, deployer); + let effects = scenario.next_tx(deployer); // We expect one object to be created: `State`. And it is shared. - let created = test_scenario::created(&effects); - let shared = test_scenario::shared(&effects); - assert!(vector::length(&created) == 1, 0); - assert!(vector::length(&shared) == 1, 0); + let created = effects.created(); + let shared = effects.shared(); + assert!(created.length() == 1, 0); + assert!(shared.length() == 1, 0); assert!( - vector::borrow(&created, 0) == vector::borrow(&shared, 0), + created.borrow(0) == shared.borrow(0), 0 ); // Verify `State`. Ideally we compare structs, but we will check each // element. - let worm_state = test_scenario::take_shared(scenario); + let worm_state = scenario.take_shared(); - assert!(state::governance_chain(&worm_state) == governance_chain, 0); + assert!(worm_state.governance_chain() == governance_chain, 0); let expected_governance_contract = external_address::new_nonzero( bytes32::from_bytes(governance_contract) ); assert!( - state::governance_contract(&worm_state) == expected_governance_contract, + worm_state.governance_contract() == expected_governance_contract, 0 ); - assert!(state::guardian_set_index(&worm_state) == 0, 0); + assert!(worm_state.guardian_set_index() == 0, 0); assert!( - state::guardian_set_seconds_to_live(&worm_state) == guardian_set_seconds_to_live, + worm_state.guardian_set_seconds_to_live() == guardian_set_seconds_to_live, 0 ); let guardians = guardian_set::guardians( - state::guardian_set_at(&worm_state, 0) + worm_state.guardian_set_at(0) ); - let num_guardians = vector::length(guardians); - assert!(num_guardians == vector::length(&initial_guardians), 0); + let num_guardians = guardians.length(); + assert!(num_guardians == initial_guardians.length(), 0); - let i = 0; + let mut i = 0; while (i < num_guardians) { - let left = guardian::as_bytes(vector::borrow(guardians, i)); - let right = *vector::borrow(&initial_guardians, i); + let left = guardian::as_bytes(guardians.borrow(i)); + let right = *initial_guardians.borrow(i); assert!(left == right, 0); i = i + 1; }; - assert!(state::message_fee(&worm_state) == message_fee, 0); + assert!(worm_state.message_fee() == message_fee, 0); // Clean up. test_scenario::return_shared(worm_state); @@ -253,8 +244,8 @@ module wormhole::setup_tests { // We expect `DeployerCap` to be destroyed. There are other // objects deleted, but we only care about the deployer cap for this // test. - let deleted = cursor::new(test_scenario::deleted(&effects)); - let found = option::none(); + let mut deleted = cursor::new(effects.deleted()); + let mut found = option::none(); while (!cursor::is_empty(&deleted)) { let id = cursor::poke(&mut deleted); if (id == deployer_cap_id) { @@ -267,7 +258,7 @@ module wormhole::setup_tests { assert!(!option::is_none(&found), 0); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -276,14 +267,14 @@ module wormhole::setup_tests { )] fun test_cannot_complete_invalid_upgrade_cap() { let deployer = person(); - let my_scenario = test_scenario::begin(deployer); + let mut my_scenario = test_scenario::begin(deployer); let scenario = &mut my_scenario; // Initialize Wormhole smart contract. - setup::init_test_only(test_scenario::ctx(scenario)); + setup::init_test_only(scenario.ctx()); // Ignore effects. - test_scenario::next_tx(scenario, deployer); + scenario.next_tx(deployer); let governance_chain = 1234; let governance_contract = @@ -296,8 +287,7 @@ module wormhole::setup_tests { // Take the `DeployerCap` and move it to `init_and_share_state`. let deployer_cap = - test_scenario::take_from_address( - scenario, + scenario.take_from_address( deployer ); @@ -307,7 +297,7 @@ module wormhole::setup_tests { let upgrade_cap = package::test_publish( object::id_from_address(@0xbadc0de), - test_scenario::ctx(scenario) + scenario.ctx() ); setup::complete( @@ -319,7 +309,7 @@ module wormhole::setup_tests { initial_guardians, guardian_set_seconds_to_live, message_fee, - test_scenario::ctx(scenario) + scenario.ctx() ); abort 42 diff --git a/sui/wormhole/sources/state.move b/sui/wormhole/sources/state.move index 8b19cf1946..7e938a86e1 100644 --- a/sui/wormhole/sources/state.move +++ b/sui/wormhole/sources/state.move @@ -7,14 +7,11 @@ /// checking signatures versus an existing Guardian set, and generating new /// emitters for Wormhole integrators. module wormhole::state { - use std::vector::{Self}; use sui::balance::{Balance}; use sui::clock::{Clock}; - use sui::object::{Self, ID, UID}; use sui::package::{UpgradeCap, UpgradeReceipt, UpgradeTicket}; use sui::sui::{SUI}; use sui::table::{Self, Table}; - use sui::tx_context::{TxContext}; use wormhole::bytes32::{Self, Bytes32}; use wormhole::consumed_vaas::{Self, ConsumedVAAs}; @@ -25,16 +22,6 @@ module wormhole::state { use wormhole::package_utils::{Self}; use wormhole::version_control::{Self}; - friend wormhole::emitter; - friend wormhole::governance_message; - friend wormhole::migrate; - friend wormhole::publish_message; - friend wormhole::set_fee; - friend wormhole::setup; - friend wormhole::transfer_fee; - friend wormhole::update_guardian_set; - friend wormhole::upgrade_contract; - friend wormhole::vaa; /// Cannot initialize state with zero guardians. const E_ZERO_GUARDIANS: u64 = 0; @@ -46,10 +33,10 @@ module wormhole::state { /// Capability reflecting that the current build version is used to invoke /// state methods. - struct LatestOnly has drop {} + public struct LatestOnly has drop {} /// Container for all state variables for Wormhole. - struct State has key, store { + public struct State has key, store { id: UID, /// Governance chain ID. @@ -83,7 +70,7 @@ module wormhole::state { } /// Create new `State`. This is only executed using the `setup` module. - public(friend) fun new( + public(package) fun new( upgrade_cap: UpgradeCap, governance_chain: u16, governance_contract: ExternalAddress, @@ -96,7 +83,7 @@ module wormhole::state { // We need at least one guardian. assert!(vector::length(&initial_guardians) > 0, E_ZERO_GUARDIANS); - let state = State { + let mut state = State { id: object::new(ctx), governance_chain, governance_contract, @@ -220,7 +207,7 @@ module wormhole::state { public fun test_upgrade(self: &mut State) { let test_digest = bytes32::from_bytes(b"new build"); let ticket = authorize_upgrade(self, test_digest); - let receipt = sui::package::test_upgrade(ticket); + let receipt = ticket.test_upgrade(); commit_upgrade(self, receipt); } @@ -241,8 +228,8 @@ module wormhole::state { // within the Wormhole package. This capability allows special access to // the `State` object. // - // NOTE: A lot of these methods are still marked as `(friend)` as a safety - // precaution. When a package is upgraded, friend modifiers can be + // NOTE: A lot of these methods are still marked as `(package)` as a safety + // precaution. When a package is upgraded, package modifiers can be // removed. // //////////////////////////////////////////////////////////////////////////// @@ -252,7 +239,7 @@ module wormhole::state { /// /// NOTE: This method allows caching the current version check so we avoid /// multiple checks to dynamic fields. - public(friend) fun assert_latest_only(self: &State): LatestOnly { + public(package) fun assert_latest_only(self: &State): LatestOnly { package_utils::assert_version( &self.id, version_control::current_version() @@ -262,12 +249,12 @@ module wormhole::state { } /// Deposit fee when sending Wormhole message. This method does not - /// necessarily have to be a `friend` to `wormhole::publish_message`. But + /// necessarily have to be a `package` to `wormhole::publish_message`. But /// we also do not want an integrator to mistakenly deposit fees outside /// of calling `publish_message`. /// /// See `wormhole::publish_message` for more info. - public(friend) fun deposit_fee( + public(package) fun deposit_fee( _: &LatestOnly, self: &mut State, fee: Balance @@ -279,7 +266,7 @@ module wormhole::state { /// particular recipient. /// /// See `wormhole::transfer_fee` for more info. - public(friend) fun withdraw_fee( + public(package) fun withdraw_fee( _: &LatestOnly, self: &mut State, amount: u64 @@ -290,7 +277,7 @@ module wormhole::state { /// Store `VAA` hash as a way to claim a VAA. This method prevents a VAA /// from being replayed. For Wormhole, the only VAAs that it cares about /// being replayed are its governance actions. - public(friend) fun borrow_mut_consumed_vaas( + public(package) fun borrow_mut_consumed_vaas( _: &LatestOnly, self: &mut State ): &mut ConsumedVAAs { @@ -304,7 +291,7 @@ module wormhole::state { /// NOTE: This method does not require `LatestOnly`. Only methods in the /// `upgrade_contract` module requires this to be unprotected to prevent /// a corrupted upgraded contract from bricking upgradability. - public(friend) fun borrow_mut_consumed_vaas_unchecked( + public(package) fun borrow_mut_consumed_vaas_unchecked( self: &mut State ): &mut ConsumedVAAs { &mut self.consumed_vaas @@ -318,7 +305,7 @@ module wormhole::state { /// long a Guardian set can live for. /// /// See `wormhole::update_guardian_set` for more info. - public(friend) fun expire_guardian_set( + public(package) fun expire_guardian_set( _: &LatestOnly, self: &mut State, the_clock: &Clock @@ -334,7 +321,7 @@ module wormhole::state { /// current guardian set. /// /// See `wormhole::update_guardian_set` for more info. - public(friend) fun add_new_guardian_set( + public(package) fun add_new_guardian_set( _: &LatestOnly, self: &mut State, new_guardian_set: GuardianSet @@ -350,7 +337,7 @@ module wormhole::state { /// Modify the cost to send a Wormhole message via governance. /// /// See `wormhole::set_fee` for more info. - public(friend) fun set_message_fee( + public(package) fun set_message_fee( _: &LatestOnly, self: &mut State, amount: u64 @@ -358,7 +345,7 @@ module wormhole::state { fee_collector::change_fee(&mut self.fee_collector, amount); } - public(friend) fun current_package(_: &LatestOnly, self: &State): ID { + public(package) fun current_package(_: &LatestOnly, self: &State): ID { package_utils::current_package(&self.id) } @@ -382,7 +369,7 @@ module wormhole::state { /// latest published package. If someone were to try to execute this using /// a stale build, the transaction will revert with `PackageUpgradeError`, /// specifically `PackageIDDoesNotMatch`. - public(friend) fun authorize_upgrade( + public(package) fun authorize_upgrade( self: &mut State, package_digest: Bytes32 ): UpgradeTicket { @@ -396,7 +383,7 @@ module wormhole::state { /// latest published package. If someone were to try to execute this using /// a stale build, the transaction will revert with `PackageUpgradeError`, /// specifically `PackageIDDoesNotMatch`. - public(friend) fun commit_upgrade( + public(package) fun commit_upgrade( self: &mut State, receipt: UpgradeReceipt ): (ID, ID) { @@ -406,7 +393,7 @@ module wormhole::state { /// Method executed by the `migrate` module to roll access from one package /// to another. This method will be called from the upgraded package. - public(friend) fun migrate_version(self: &mut State) { + public(package) fun migrate_version(self: &mut State) { package_utils::migrate_version( &mut self.id, version_control::previous_version(), @@ -417,7 +404,7 @@ module wormhole::state { /// As a part of the migration, we verify that the upgrade contract VAA's /// encoded package digest used in `migrate` equals the one used to conduct /// the upgrade. - public(friend) fun assert_authorized_digest( + public(package) fun assert_authorized_digest( _: &LatestOnly, self: &State, digest: Bytes32 @@ -432,7 +419,7 @@ module wormhole::state { // // A VERY special space that manipulates `State` via calling `migrate`. // - // PLEASE KEEP ANY METHODS HERE AS FRIENDS. We want the ability to remove + // PLEASE KEEP ANY METHODS HERE AS `package`. We want the ability to remove // these for future builds. // //////////////////////////////////////////////////////////////////////////// @@ -441,9 +428,9 @@ module wormhole::state { /// called. This method name should change reflecting which version this /// contract is migrating to. /// - /// NOTE: Please keep this method as public(friend) because we never want + /// NOTE: Please keep this method as public(package) because we never want /// to expose this method as a public method. - public(friend) fun migrate__v__0_2_0(_self: &mut State) { + public(package) fun migrate__v__0_2_0(_self: &mut State) { // Intentionally do nothing. } diff --git a/sui/wormhole/sources/test/wormhole_scenario.move b/sui/wormhole/sources/test/wormhole_scenario.move index f587778e4c..3281e3501f 100644 --- a/sui/wormhole/sources/test/wormhole_scenario.move +++ b/sui/wormhole/sources/test/wormhole_scenario.move @@ -8,7 +8,6 @@ /// for the key), which allows an integrator to generate his own VAAs and /// validate them with this test-only Wormhole instance. module wormhole::wormhole_scenario { - use std::vector::{Self}; use sui::clock::{Self, Clock}; use sui::package::{UpgradeCap}; use sui::test_scenario::{Self, Scenario}; @@ -16,7 +15,7 @@ module wormhole::wormhole_scenario { use wormhole::emitter::{EmitterCap}; use wormhole::governance_message::{Self, DecreeTicket, DecreeReceipt}; use wormhole::setup::{Self, DeployerCap}; - use wormhole::state::{Self, State}; + use wormhole::state::{State}; use wormhole::vaa::{Self, VAA}; const DEPLOYER: address = @0xDEADBEEF; @@ -85,10 +84,9 @@ module wormhole::wormhole_scenario { /// Set up Wormhole with only the first devnet guardian. public fun set_up_wormhole(scenario: &mut Scenario, message_fee: u64) { - let initial_guardians = vector::empty(); - vector::push_back( - &mut initial_guardians, - *vector::borrow(&guardians(), 0) + let mut initial_guardians = vector::empty(); + initial_guardians.push_back( + *guardians().borrow(0) ); set_up_wormhole_with_guardians(scenario, message_fee, initial_guardians) @@ -98,10 +96,10 @@ module wormhole::wormhole_scenario { /// `State` believes is true). public fun upgrade_wormhole(scenario: &mut Scenario) { // Clean up from activity prior. - test_scenario::next_tx(scenario, person()); + scenario.next_tx(person()); - let worm_state = take_state(scenario); - state::test_upgrade(&mut worm_state); + let mut worm_state = take_state(scenario); + worm_state.test_upgrade(); // Clean up. return_state(worm_state); @@ -150,7 +148,7 @@ module wormhole::wormhole_scenario { } public fun take_state(scenario: &Scenario): State { - test_scenario::take_shared(scenario) + scenario.take_shared() } public fun return_state(wormhole_state: State) { @@ -161,7 +159,7 @@ module wormhole::wormhole_scenario { scenario: &mut Scenario, vaa_buf: vector ): VAA { - test_scenario::next_tx(scenario, VAA_VERIFIER); + scenario.next_tx(VAA_VERIFIER); let the_clock = take_clock(scenario); let worm_state = take_state(scenario); @@ -185,7 +183,7 @@ module wormhole::wormhole_scenario { verified_vaa: VAA, ticket: DecreeTicket ): DecreeReceipt { - test_scenario::next_tx(scenario, VAA_VERIFIER); + scenario.next_tx(VAA_VERIFIER); let worm_state = take_state(scenario); @@ -201,7 +199,7 @@ module wormhole::wormhole_scenario { public fun new_emitter( scenario: &mut Scenario ): EmitterCap { - test_scenario::next_tx(scenario, EMITTER_MAKER); + scenario.next_tx(EMITTER_MAKER); let worm_state = take_state(scenario); @@ -215,7 +213,7 @@ module wormhole::wormhole_scenario { } public fun take_clock(scenario: &mut Scenario): Clock { - clock::create_for_testing(test_scenario::ctx(scenario)) + clock::create_for_testing(scenario.ctx()) } public fun return_clock(the_clock: Clock) { diff --git a/sui/wormhole/sources/utils/bytes.move b/sui/wormhole/sources/utils/bytes.move index 0d181f6775..6d260aa7f0 100644 --- a/sui/wormhole/sources/utils/bytes.move +++ b/sui/wormhole/sources/utils/bytes.move @@ -6,12 +6,11 @@ /// argument will be of `&mut Cursor` (see `wormhole::cursor` for more /// details). module wormhole::bytes { - use std::vector::{Self}; use std::bcs::{Self}; use wormhole::cursor::{Self, Cursor}; public fun push_u8(buf: &mut vector, v: u8) { - vector::push_back(buf, v); + buf.push_back(v); } public fun push_u16_be(buf: &mut vector, value: u16) { @@ -39,8 +38,8 @@ module wormhole::bytes { } public fun take_u16_be(cur: &mut Cursor): u16 { - let out = 0; - let i = 0; + let mut out = 0; + let mut i = 0; while (i < 2) { out = (out << 8) + (cursor::poke(cur) as u16); i = i + 1; @@ -49,8 +48,8 @@ module wormhole::bytes { } public fun take_u32_be(cur: &mut Cursor): u32 { - let out = 0; - let i = 0; + let mut out = 0; + let mut i = 0; while (i < 4) { out = (out << 8) + (cursor::poke(cur) as u32); i = i + 1; @@ -59,8 +58,8 @@ module wormhole::bytes { } public fun take_u64_be(cur: &mut Cursor): u64 { - let out = 0; - let i = 0; + let mut out = 0; + let mut i = 0; while (i < 8) { out = (out << 8) + (cursor::poke(cur) as u64); i = i + 1; @@ -69,8 +68,8 @@ module wormhole::bytes { } public fun take_u128_be(cur: &mut Cursor): u128 { - let out = 0; - let i = 0; + let mut out = 0; + let mut i = 0; while (i < 16) { out = (out << 8) + (cursor::poke(cur) as u128); i = i + 1; @@ -79,8 +78,8 @@ module wormhole::bytes { } public fun take_u256_be(cur: &mut Cursor): u256 { - let out = 0; - let i = 0; + let mut out = 0; + let mut i = 0; while (i < 32) { out = (out << 8) + (cursor::poke(cur) as u256); i = i + 1; @@ -89,80 +88,79 @@ module wormhole::bytes { } public fun take_bytes(cur: &mut Cursor, num_bytes: u64): vector { - let out = vector::empty(); - let i = 0; + let mut out = vector::empty(); + let mut i = 0; while (i < num_bytes) { - vector::push_back(&mut out, cursor::poke(cur)); + out.push_back(cursor::poke(cur)); i = i + 1; }; out } fun push_reverse(buf: &mut vector, v: T) { - let data = bcs::to_bytes(&v); - vector::reverse(&mut data); - vector::append(buf, data); + let mut data = bcs::to_bytes(&v); + data.reverse(); + buf.append(data); } } #[test_only] module wormhole::bytes_tests { - use std::vector::{Self}; use wormhole::bytes::{Self}; use wormhole::cursor::{Self}; #[test] fun test_push_u8(){ let u = 0x12; - let s = vector::empty(); + let mut s = vector::empty(); bytes::push_u8(&mut s, u); - let cur = cursor::new(s); + let mut cur = cursor::new(s); let p = bytes::take_u8(&mut cur); - cursor::destroy_empty(cur); + cur.destroy_empty(); assert!(p==u, 0); } #[test] fun test_push_u16_be(){ let u = 0x1234; - let s = vector::empty(); + let mut s = vector::empty(); bytes::push_u16_be(&mut s, u); - let cur = cursor::new(s); + let mut cur = cursor::new(s); let p = bytes::take_u16_be(&mut cur); - cursor::destroy_empty(cur); + cur.destroy_empty(); assert!(p==u, 0); } #[test] fun test_push_u32_be(){ let u = 0x12345678; - let s = vector::empty(); + let mut s = vector::empty(); bytes::push_u32_be(&mut s, u); - let cur = cursor::new(s); + let mut cur = cursor::new(s); let p = bytes::take_u32_be(&mut cur); - cursor::destroy_empty(cur); + cur.destroy_empty(); assert!(p==u, 0); } #[test] fun test_push_u64_be(){ let u = 0x1234567812345678; - let s = vector::empty(); + let mut s = vector::empty(); bytes::push_u64_be(&mut s, u); - let cur = cursor::new(s); + let mut cur = cursor::new(s); let p = bytes::take_u64_be(&mut cur); - cursor::destroy_empty(cur); + cur.destroy_empty(); assert!(p==u, 0); } #[test] fun test_push_u128_be(){ let u = 0x12345678123456781234567812345678; - let s = vector::empty(); + let mut s = vector::empty(); bytes::push_u128_be(&mut s, u); - let cur = cursor::new(s); + let mut cur = cursor::new(s); let p = bytes::take_u128_be(&mut cur); - cursor::destroy_empty(cur); + cur.destroy_empty(); assert!(p==u, 0); } @@ -170,7 +168,7 @@ module wormhole::bytes_tests { fun test_push_u256_be(){ let u = 0x4738691759099793746170047375612500000000000000000000000000009876; - let s = vector::empty(); + let mut s = vector::empty(); bytes::push_u256_be(&mut s, u); assert!( s == x"4738691759099793746170047375612500000000000000000000000000009876", @@ -180,53 +178,53 @@ module wormhole::bytes_tests { #[test] fun test_take_u8() { - let cursor = cursor::new(x"99"); + let mut cursor = cursor::new(x"99"); let byte = bytes::take_u8(&mut cursor); assert!(byte==0x99, 0); - cursor::destroy_empty(cursor); + cursor.destroy_empty(); } #[test] fun test_take_u16_be() { - let cursor = cursor::new(x"9987"); + let mut cursor = cursor::new(x"9987"); let u = bytes::take_u16_be(&mut cursor); assert!(u == 0x9987, 0); - cursor::destroy_empty(cursor); + cursor.destroy_empty(); } #[test] fun test_take_u32_be() { - let cursor = cursor::new(x"99876543"); + let mut cursor = cursor::new(x"99876543"); let u = bytes::take_u32_be(&mut cursor); assert!(u == 0x99876543, 0); - cursor::destroy_empty(cursor); + cursor.destroy_empty(); } #[test] fun test_take_u64_be() { - let cursor = cursor::new(x"1300000025000001"); + let mut cursor = cursor::new(x"1300000025000001"); let u = bytes::take_u64_be(&mut cursor); assert!(u == 0x1300000025000001, 0); - cursor::destroy_empty(cursor); + cursor.destroy_empty(); } #[test] fun test_take_u128_be() { - let cursor = cursor::new(x"130209AB2500FA0113CD00AE25000001"); + let mut cursor = cursor::new(x"130209AB2500FA0113CD00AE25000001"); let u = bytes::take_u128_be(&mut cursor); assert!(u == 0x130209AB2500FA0113CD00AE25000001, 0); - cursor::destroy_empty(cursor); + cursor.destroy_empty(); } #[test] fun test_to_bytes() { - let cursor = cursor::new(b"hello world"); + let mut cursor = cursor::new(b"hello world"); let hello = bytes::take_bytes(&mut cursor, 5); bytes::take_u8(&mut cursor); let world = bytes::take_bytes(&mut cursor, 5); assert!(hello == b"hello", 0); assert!(world == b"world", 0); - cursor::destroy_empty(cursor); + cursor.destroy_empty(); } } diff --git a/sui/wormhole/sources/utils/cursor.move b/sui/wormhole/sources/utils/cursor.move index 73a96ebea0..1a8dc94a3c 100644 --- a/sui/wormhole/sources/utils/cursor.move +++ b/sui/wormhole/sources/utils/cursor.move @@ -8,17 +8,16 @@ /// This setup statically guarantees that the parsing methods consume the full /// input. module wormhole::cursor { - use std::vector::{Self}; /// Container for the underlying `vector` data to be consumed. - struct Cursor { + public struct Cursor { data: vector, } /// Initialises a cursor from a vector. - public fun new(data: vector): Cursor { + public fun new(mut data: vector): Cursor { // reverse the array so we have access to the first element easily - vector::reverse(&mut data); + data.reverse(); Cursor { data } } @@ -30,13 +29,13 @@ module wormhole::cursor { /// Check whether the underlying data is empty. This method is useful for /// iterating over a `Cursor` to exhaust its contents. public fun is_empty(self: &Cursor): bool { - vector::is_empty(&self.data) + self.data.is_empty() } /// Destroys an empty cursor. This method aborts if the cursor is not empty. public fun destroy_empty(cursor: Cursor) { let Cursor { data } = cursor; - vector::destroy_empty(data); + data.destroy_empty(); } /// Consumes the rest of the cursor (thus destroying it) and returns the @@ -46,15 +45,15 @@ module wormhole::cursor { /// bytes. Since the result is a vector, which can be dropped, it is not /// possible to statically guarantee that the rest will be used. public fun take_rest(cursor: Cursor): vector { - let Cursor { data } = cursor; + let Cursor { mut data } = cursor; // Because the data was reversed in initialization, we need to reverse // again so it is in the same order as the original input. - vector::reverse(&mut data); + data.reverse(); data } /// Retrieve the first element of the cursor and advances it. public fun poke(self: &mut Cursor): T { - vector::pop_back(&mut self.data) + self.data.pop_back() } } diff --git a/sui/wormhole/sources/utils/package_utils.move b/sui/wormhole/sources/utils/package_utils.move index 12dcfde91a..fd856acfe5 100644 --- a/sui/wormhole/sources/utils/package_utils.move +++ b/sui/wormhole/sources/utils/package_utils.move @@ -5,7 +5,6 @@ module wormhole::package_utils { use std::type_name::{Self, TypeName}; use sui::dynamic_field::{Self as field}; - use sui::object::{Self, ID, UID}; use sui::package::{Self, UpgradeCap, UpgradeTicket, UpgradeReceipt}; use wormhole::bytes32::{Self, Bytes32}; @@ -22,14 +21,14 @@ module wormhole::package_utils { const E_TYPE_NOT_ALLOWED: u64 = 4; /// Key for version dynamic fields. - struct CurrentVersion has store, drop, copy {} + public struct CurrentVersion has store, drop, copy {} /// Key for dynamic field reflecting current package info. Its value is /// `PackageInfo`. - struct CurrentPackage has store, drop, copy {} - struct PendingPackage has store, drop, copy {} + public struct CurrentPackage has store, drop, copy {} + public struct PendingPackage has store, drop, copy {} - struct PackageInfo has store, drop, copy { + public struct PackageInfo has store, drop, copy { package: ID, digest: Bytes32 } @@ -165,14 +164,13 @@ module wormhole::package_utils { upgrade_cap: &mut UpgradeCap, package_digest: Bytes32 ): UpgradeTicket { - let policy = package::upgrade_policy(upgrade_cap); + let policy = upgrade_cap.upgrade_policy(); // Manage saving the current digest. set_authorized_digest(id, package_digest); // Finally authorize upgrade. - package::authorize_upgrade( - upgrade_cap, + upgrade_cap.authorize_upgrade( policy, bytes32::to_bytes(package_digest), ) @@ -276,22 +274,19 @@ module wormhole::package_utils { #[test_only] module wormhole::package_utils_tests { - use sui::object::{Self, UID}; - use sui::tx_context::{Self}; - use wormhole::package_utils::{Self}; use wormhole::version_control::{Self}; - struct State has key { + public struct State has key { id: UID } - struct V_DUMMY has store, drop, copy {} + public struct V_DUMMY has store, drop, copy {} #[test] fun test_assert_current() { // Create dummy state. - let state = State { id: object::new(&mut tx_context::dummy()) }; + let mut state = State { id: object::new(&mut tx_context::dummy()) }; package_utils::init_version( &mut state.id, version_control::current_version() @@ -311,7 +306,7 @@ module wormhole::package_utils_tests { #[expected_failure(abort_code = package_utils::E_INCORRECT_OLD_VERSION)] fun test_cannot_update_incorrect_old_version() { // Create dummy state. - let state = State { id: object::new(&mut tx_context::dummy()) }; + let mut state = State { id: object::new(&mut tx_context::dummy()) }; package_utils::init_version( &mut state.id, version_control::current_version() @@ -336,7 +331,7 @@ module wormhole::package_utils_tests { #[expected_failure(abort_code = package_utils::E_SAME_VERSION)] fun test_cannot_update_same_version() { // Create dummy state. - let state = State { id: object::new(&mut tx_context::dummy()) }; + let mut state = State { id: object::new(&mut tx_context::dummy()) }; package_utils::init_version( &mut state.id, version_control::current_version() @@ -361,7 +356,7 @@ module wormhole::package_utils_tests { #[expected_failure(abort_code = package_utils::E_NOT_CURRENT_VERSION)] fun test_cannot_assert_current_outdated_version() { // Create dummy state. - let state = State { id: object::new(&mut tx_context::dummy()) }; + let mut state = State { id: object::new(&mut tx_context::dummy()) }; package_utils::init_version( &mut state.id, version_control::current_version() @@ -392,7 +387,7 @@ module wormhole::package_utils_tests { #[expected_failure(abort_code = package_utils::E_TYPE_NOT_ALLOWED)] fun test_cannot_update_type_not_allowed() { // Create dummy state. - let state = State { id: object::new(&mut tx_context::dummy()) }; + let mut state = State { id: object::new(&mut tx_context::dummy()) }; package_utils::init_version( &mut state.id, version_control::current_version() diff --git a/sui/wormhole/sources/vaa.move b/sui/wormhole/sources/vaa.move index 03528351d4..5accc4f076 100644 --- a/sui/wormhole/sources/vaa.move +++ b/sui/wormhole/sources/vaa.move @@ -20,8 +20,6 @@ /// A good example of how this methodology is implemented is how the Token /// Bridge contract redeems its VAAs. module wormhole::vaa { - use std::option::{Self}; - use std::vector::{Self}; use sui::clock::{Clock}; use sui::hash::{keccak256}; @@ -33,7 +31,7 @@ module wormhole::vaa { use wormhole::guardian::{Self}; use wormhole::guardian_set::{Self, GuardianSet}; use wormhole::guardian_signature::{Self, GuardianSignature}; - use wormhole::state::{Self, State}; + use wormhole::state::{State}; /// Incorrect VAA version. const E_WRONG_VERSION: u64 = 0; @@ -50,7 +48,7 @@ module wormhole::vaa { /// Container storing verified Wormhole message info. This struct also /// caches the digest, which is a double Keccak256 hash of the message body. - struct VAA { + public struct VAA { /// Guardian set index of Guardians that attested to observing the /// Wormhole message. guardian_set_index: u32, @@ -124,7 +122,7 @@ module wormhole::vaa { /// Destroy the `VAA` and take the Wormhole message payload. public fun take_payload(vaa: VAA): vector { - let (_, _, payload) = take_emitter_info_and_payload(vaa); + let (_, _, payload) = vaa.take_emitter_info_and_payload(); payload } @@ -158,7 +156,7 @@ module wormhole::vaa { buf: vector, the_clock: &Clock ): VAA { - state::assert_latest_only(wormhole_state); + wormhole_state.assert_latest_only(); // Deserialize VAA buffer (and return `VAA` after verifying signatures). let (signatures, vaa) = parse(buf); @@ -166,8 +164,7 @@ module wormhole::vaa { // Fetch the guardian set which this VAA was supposedly signed with and // verify signatures using guardian set. verify_signatures( - state::guardian_set_at( - wormhole_state, + wormhole_state.guardian_set_at( vaa.guardian_set_index ), signatures, @@ -184,18 +181,17 @@ module wormhole::vaa { } public fun compute_message_hash(parsed: &VAA): Bytes32 { - let buf = vector::empty(); + let mut buf = vector[]; bytes::push_u32_be(&mut buf, parsed.timestamp); bytes::push_u32_be(&mut buf, parsed.nonce); bytes::push_u16_be(&mut buf, parsed.emitter_chain); - vector::append( - &mut buf, + buf.append( external_address::to_bytes(parsed.emitter_address) ); bytes::push_u64_be(&mut buf, parsed.sequence); bytes::push_u8(&mut buf, parsed.consistency_level); - vector::append(&mut buf, parsed.payload); + buf.append(parsed.payload); // Return hash. bytes32::new(keccak256(&buf)) @@ -208,7 +204,7 @@ module wormhole::vaa { /// signatures must have been verified, because the only public function /// that returns a `VAA` is `parse_and_verify`. fun parse(buf: vector): (vector, VAA) { - let cur = cursor::new(buf); + let mut cur = cursor::new(buf); // Check VAA version. assert!( @@ -220,15 +216,14 @@ module wormhole::vaa { // Deserialize guardian signatures. let num_signatures = bytes::take_u8(&mut cur); - let signatures = vector::empty(); - let i = 0; + let mut signatures = vector[]; + let mut i = 0; while (i < num_signatures) { let guardian_index = bytes::take_u8(&mut cur); let r = bytes32::take_bytes(&mut cur); let s = bytes32::take_bytes(&mut cur); let recovery_id = bytes::take_u8(&mut cur); - vector::push_back( - &mut signatures, + signatures.push_back( guardian_signature::new(r, s, recovery_id, guardian_index) ); i = i + 1; @@ -237,7 +232,7 @@ module wormhole::vaa { // Deserialize message body. let body_buf = cursor::take_rest(cur); - let cur = cursor::new(body_buf); + let mut cur = cursor::new(body_buf); let timestamp = bytes::take_u32_be(&mut cur); let nonce = bytes::take_u32_be(&mut cur); let emitter_chain = bytes::take_u16_be(&mut cur); @@ -262,8 +257,6 @@ module wormhole::vaa { } fun double_keccak256(buf: vector): Bytes32 { - use sui::hash::{keccak256}; - bytes32::new(keccak256(&keccak256(&buf))) } @@ -290,13 +283,13 @@ module wormhole::vaa { // Number of signatures must be at least quorum. assert!( - vector::length(&signatures) >= guardian_set::quorum(set), + signatures.length() >= guardian_set::quorum(set), E_NO_QUORUM ); // Drain `Cursor` by checking each signature. - let cur = cursor::new(signatures); - let last_guardian_index = option::none(); + let mut cur = cursor::new(signatures); + let mut last_guardian_index = option::none(); while (!cursor::is_empty(&cur)) { let signature = cursor::poke(&mut cur); let guardian_index = guardian_signature::index_as_u64(&signature); @@ -325,7 +318,7 @@ module wormhole::vaa { ); // Continue. - option::swap_or_fill(&mut last_guardian_index, guardian_index); + last_guardian_index.swap_or_fill(guardian_index); }; // Done. @@ -347,17 +340,17 @@ module wormhole::vaa { #[test_only] public fun peel_payload_from_vaa(buf: &vector): vector { // Just make sure that we are passing version 1 VAAs to this method. - assert!(*vector::borrow(buf, 0) == VERSION_VAA, E_WRONG_VERSION); + assert!(*buf.borrow(0) == VERSION_VAA, E_WRONG_VERSION); // Find the location of the payload. - let num_signatures = (*vector::borrow(buf, 5) as u64); - let i = 57 + num_signatures * 66; + let num_signatures = (*buf.borrow(5) as u64); + let mut i = 57 + num_signatures * 66; // Push the payload bytes to `out` and return. - let out = vector::empty(); - let len = vector::length(buf); + let mut out = vector[]; + let len = buf.length(); while (i < len) { - vector::push_back(&mut out, *vector::borrow(buf, i)); + out.push_back(*buf.borrow(i)); i = i + 1; }; @@ -368,7 +361,6 @@ module wormhole::vaa { #[test_only] module wormhole::vaa_tests { - use std::vector::{Self}; use sui::test_scenario::{Self}; use wormhole::bytes32::{Self}; @@ -534,25 +526,25 @@ module wormhole::vaa_tests { ) ]; assert!( - vector::length(&signatures) == vector::length(&expected_signatures), + signatures.length() == expected_signatures.length(), 0 ); - let left = cursor::new(signatures); - let right = cursor::new(expected_signatures); - while (!cursor::is_empty(&left)) { - assert!(cursor::poke(&mut left) == cursor::poke(&mut right), 0); + let mut left = cursor::new(signatures); + let mut right = cursor::new(expected_signatures); + while (!left.is_empty()) { + assert!(left.poke() == right.poke(), 0); }; - cursor::destroy_empty(left); - cursor::destroy_empty(right); + left.destroy_empty(); + right.destroy_empty(); - assert!(vaa::guardian_set_index(&parsed) == 0, 0); - assert!(vaa::timestamp(&parsed) == 9000, 0); + assert!(parsed.guardian_set_index() == 0, 0); + assert!(parsed.timestamp() == 9000, 0); let expected_batch_id = 12; - assert!(vaa::batch_id(&parsed) == expected_batch_id, 0); - assert!(vaa::nonce(&parsed) == expected_batch_id, 0); + assert!(parsed.batch_id() == expected_batch_id, 0); + assert!(parsed.nonce() == expected_batch_id, 0); - assert!(vaa::emitter_chain(&parsed) == 42, 0); + assert!(parsed.emitter_chain() == 42, 0); let expected_emitter_address = external_address::from_address( @@ -571,33 +563,32 @@ module wormhole::vaa_tests { let body_buf = { use wormhole::bytes::{Self}; - let buf = vector::empty(); + let mut buf = vector[]; bytes::push_u32_be(&mut buf, vaa::timestamp(&parsed)); bytes::push_u32_be(&mut buf, vaa::nonce(&parsed)); bytes::push_u16_be(&mut buf, vaa::emitter_chain(&parsed)); - vector::append( - &mut buf, + buf.append( external_address::to_bytes(vaa::emitter_address(&parsed)) ); bytes::push_u64_be(&mut buf, vaa::sequence(&parsed)); bytes::push_u8(&mut buf, vaa::consistency_level(&parsed)); - vector::append(&mut buf, vaa::payload(&parsed)); + buf.append(vaa::payload(&parsed)); buf }; let expected_message_hash = bytes32::new(sui::hash::keccak256(&body_buf)); - assert!(vaa::compute_message_hash(&parsed) == expected_message_hash, 0); + assert!(parsed.compute_message_hash() == expected_message_hash, 0); let expected_digest = bytes32::new( sui::hash::keccak256(&sui::hash::keccak256(&body_buf)) ); - assert!(vaa::digest(&parsed) == expected_digest, 0); + assert!(parsed.digest() == expected_digest, 0); assert!( - vaa::take_payload(parsed) == b"All your base are belong to us", + parsed.take_payload() == b"All your base are belong to us", 0 ); } @@ -609,7 +600,7 @@ module wormhole::vaa_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; // Initialize Wormhole with 19 guardians. @@ -617,7 +608,7 @@ module wormhole::vaa_tests { set_up_wormhole_with_guardians(scenario, wormhole_fee, guardians()); // Prepare test to execute `parse_and_verify`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); let worm_state = take_state(scenario); let the_clock = take_clock(scenario); @@ -636,7 +627,7 @@ module wormhole::vaa_tests { return_clock(the_clock); // Done. - test_scenario::end(my_scenario); + my_scenario.end(); } #[test] @@ -647,7 +638,7 @@ module wormhole::vaa_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; // Initialize Wormhole with 19 guardians. @@ -655,7 +646,7 @@ module wormhole::vaa_tests { set_up_wormhole_with_guardians(scenario, wormhole_fee, guardians()); // Prepare test to execute `parse_and_verify`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); let worm_state = take_state(scenario); let the_clock = take_clock(scenario); @@ -677,7 +668,7 @@ module wormhole::vaa_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; // Initialize Wormhole with 19 guardians. @@ -685,7 +676,7 @@ module wormhole::vaa_tests { set_up_wormhole_with_guardians(scenario, wormhole_fee, guardians()); // Prepare test to execute `parse_and_verify`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); let worm_state = take_state(scenario); let the_clock = take_clock(scenario); @@ -708,13 +699,13 @@ module wormhole::vaa_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); + let mut my_scenario = test_scenario::begin(caller); let scenario = &mut my_scenario; // Initialize Wormhole with 19 guardians. But reverse the order so the // signatures will not match. - let initial_guardians = guardians(); - std::vector::reverse(&mut initial_guardians); + let mut initial_guardians = guardians(); + initial_guardians.reverse(); let wormhole_fee = 350; set_up_wormhole_with_guardians( @@ -724,7 +715,7 @@ module wormhole::vaa_tests { ); // Prepare test to execute `parse_and_verify`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); let worm_state = take_state(scenario); let the_clock = take_clock(scenario); @@ -733,7 +724,7 @@ module wormhole::vaa_tests { let verified_vaa = parse_and_verify(&worm_state, VAA_1, &the_clock); // Clean up. - vaa::destroy(verified_vaa); + verified_vaa.destroy(); abort 42 } @@ -746,21 +737,20 @@ module wormhole::vaa_tests { // Set up. let caller = person(); - let my_scenario = test_scenario::begin(caller); - let scenario = &mut my_scenario; + let mut scenario = test_scenario::begin(caller); // Initialize Wormhole with 19 guardians. let wormhole_fee = 350; - set_up_wormhole_with_guardians(scenario, wormhole_fee, guardians()); + set_up_wormhole_with_guardians(&mut scenario, wormhole_fee, guardians()); // Prepare test to execute `parse_and_verify`. - test_scenario::next_tx(scenario, caller); + scenario.next_tx(caller); - let worm_state = take_state(scenario); - let the_clock = take_clock(scenario); + let mut worm_state = take_state(&scenario); + let the_clock = take_clock(&mut scenario); // Conveniently roll version back. - state::reverse_migrate_version(&mut worm_state); + worm_state.reverse_migrate_version(); // Simulate executing with an outdated build by upticking the minimum // required version for `publish_message` to something greater than @@ -775,7 +765,7 @@ module wormhole::vaa_tests { let verified_vaa = parse_and_verify(&worm_state, VAA_1, &the_clock); // Clean up. - vaa::destroy(verified_vaa); + verified_vaa.destroy(); abort 42 } diff --git a/sui/wormhole/sources/version_control.move b/sui/wormhole/sources/version_control.move index 13ee6106df..8d336b5f70 100644 --- a/sui/wormhole/sources/version_control.move +++ b/sui/wormhole/sources/version_control.move @@ -16,11 +16,11 @@ module wormhole::version_control { // //////////////////////////////////////////////////////////////////////////// - public(friend) fun current_version(): V__0_2_0 { + public(package) fun current_version(): V__0_2_0 { V__0_2_0 {} } - public(friend) fun previous_version(): V__DUMMY { + public(package) fun previous_version(): V__DUMMY { V__DUMMY {} } @@ -39,10 +39,10 @@ module wormhole::version_control { //////////////////////////////////////////////////////////////////////////// /// First published package on Sui mainnet. - struct V__0_2_0 has store, drop, copy {} + public struct V__0_2_0 has store, drop, copy {} // Dummy. - struct V__DUMMY has store, drop, copy {} + public struct V__DUMMY has store, drop, copy {} //////////////////////////////////////////////////////////////////////////// // @@ -50,10 +50,6 @@ module wormhole::version_control { // //////////////////////////////////////////////////////////////////////////// - friend wormhole::state; - - #[test_only] - friend wormhole::package_utils_tests; #[test_only] public fun dummy(): V__DUMMY { @@ -61,7 +57,7 @@ module wormhole::version_control { } #[test_only] - struct V__MIGRATED has store, drop, copy {} + public struct V__MIGRATED has store, drop, copy {} #[test_only] public fun next_version(): V__MIGRATED {