Skip to content

Commit

Permalink
[6/n][enums/Sui] Sui types, protocol config, and misc changes for enu…
Browse files Browse the repository at this point in the history
…ms (#17247)

## Description 

This PR contains the changes needed for Move enums in sui-types, the
protocol config changes (except for bumping the bytecode version), along
with other misc/smaller changes that are not easily categorized.

This PR is meant to be a logically-reviewable portion but is not
land-able on its own. It must be merged in with the changes in the rest
of this stack to be landed.

## Stack:
* #17245
* #17246 
* #17247 **<< You are here**
* #17248 
* #17249 
* #17250 
* #17251 

## Test plan 

Tests are in the top commit in this stack here:
  • Loading branch information
tzakian authored May 24, 2024
1 parent f076f43 commit e7d9e8a
Show file tree
Hide file tree
Showing 505 changed files with 8,483 additions and 1,569 deletions.
41 changes: 41 additions & 0 deletions crates/sui-adapter-transactional-tests/tests/enums/basic_enums.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
processed 6 tasks

task 1 'publish'. lines 6-31:
created: object(1,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 6262400, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'run'. lines 33-33:
created: object(2,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 2204000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 3 'view-object'. lines 35-35:
Owner: Account Address ( _ )
Version: 3
Contents: Test::f::S {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,0),
},
},
data: Test::f::F::V1{},
}

task 4 'run'. lines 37-37:
mutated: object(0,0), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2264800, storage_rebate: 2181960, non_refundable_storage_fee: 22040

task 5 'view-object'. lines 39-39:
Owner: Account Address ( _ )
Version: 4
Contents: Test::f::S {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,0),
},
},
data: Test::f::F::V4{
x: 42u64,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --addresses Test=0x0

//# publish
module Test::f {
public enum F has drop, store {
V1,
V2(u64),
V3(u64, u64),
V4 { x: u64 },
}

public struct S has key {
id: UID,
data: F,
}

public fun create_and_test(ctx: &mut TxContext) {
let s = S {
id: object::new(ctx),
data: F::V1,
};
transfer::transfer(s, ctx.sender());
}

public fun update_inner(s: &mut S) {
s.data = F::V4 { x: 42 };
}
}

//# run Test::f::create_and_test

//# view-object 2,0

//# run Test::f::update_inner --args object(2,0)

//# view-object 2,0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
processed 3 tasks

init:
A: object(0,0)

task 1 'publish'. lines 6-48:
created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 9492400, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'programmable'. lines 50-52:
created: object(2,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 2576400, storage_rebate: 978120, non_refundable_storage_fee: 9880
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --addresses Test=0x0 --accounts A

//# publish --upgradeable --sender A
module Test::f {
use sui::coin::Coin;
use sui::sui::SUI;

public struct Other { }

public enum CoinWrapper has store {
Sui(Coin<SUI>),
Other(Coin<Other>),
}

public struct CoinObject has key, store {
id: UID,
coin: CoinWrapper,
}

public fun split_off(coin: &mut CoinObject, amount: u64, ctx: &mut TxContext): CoinObject {
match (&mut coin.coin) {
CoinWrapper::Sui(c) => {
let new_coin = CoinObject {
id: object::new(ctx),
coin: CoinWrapper::Sui(c.split(amount, ctx)),
};
new_coin
},
CoinWrapper::Other(c) => {
let new_coin = CoinObject {
id: object::new(ctx),
coin: CoinWrapper::Other(c.split(amount, ctx)),
};
new_coin
},
}
}

public fun create_sui(coin: &mut Coin<SUI>, amount: u64, ctx: &mut TxContext): CoinObject {
CoinObject {
id: object::new(ctx),
coin: CoinWrapper::Sui(coin.split(amount, ctx)),
}
}
}

//# programmable --sender A --inputs 10 @A
//> 0: Test::f::create_sui(Gas, Input(0));
//> 1: TransferObjects([Result(0)], Input(1))
26 changes: 26 additions & 0 deletions crates/sui-adapter-transactional-tests/tests/enums/enum_events.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
processed 6 tasks

task 1 'publish'. lines 6-32:
created: object(1,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 5213600, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'run'. lines 34-34:
events: Event { package_id: Test, transaction_module: Identifier("f"), sender: _, type_: StructTag { address: Test, module: Identifier("f"), name: Identifier("F"), type_params: [] }, contents: [0] }
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 3 'run'. lines 36-36:
events: Event { package_id: Test, transaction_module: Identifier("f"), sender: _, type_: StructTag { address: Test, module: Identifier("f"), name: Identifier("F"), type_params: [] }, contents: [1, 42, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'run'. lines 38-38:
events: Event { package_id: Test, transaction_module: Identifier("f"), sender: _, type_: StructTag { address: Test, module: Identifier("f"), name: Identifier("F"), type_params: [] }, contents: [2, 42, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'run'. lines 40-40:
events: Event { package_id: Test, transaction_module: Identifier("f"), sender: _, type_: StructTag { address: Test, module: Identifier("f"), name: Identifier("F"), type_params: [] }, contents: [3, 42, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --addresses Test=0x0

//# publish
module Test::f {
use sui::event;

public enum F has copy, drop {
V1,
V2(u64),
V3(u64, u64),
V4 { x: u64 },
}

public fun f1() {
event::emit(F::V1);
}

public fun f2(x: u64) {
event::emit(F::V2(x));
}

public fun f3(x: u64, y: u64) {
event::emit(F::V3(x, y));
}

public fun f4(x: u64) {
event::emit(F::V4 { x });
}
}

//# run Test::f::f1

//# run Test::f::f2 --args 42

//# run Test::f::f3 --args 42 43

//# run Test::f::f4 --args 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
processed 3 tasks

task 1 'publish'. lines 6-15:
created: object(1,0)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 4636000, storage_rebate: 0, non_refundable_storage_fee: 0

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

//# init --addresses Test=0x0

//# publish
module Test::f {
public enum F has drop {
V,
}

public fun test() {
assert!(!sui::types::is_one_time_witness(&F::V));
}
}

//# run Test::f::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
processed 10 tasks

init:
A: object(0,0)

task 1 'publish'. lines 6-31:
created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 7896400, storage_rebate: 0, non_refundable_storage_fee: 0

task 2 'run'. lines 33-33:
created: object(2,0)
mutated: object(0,1)
gas summary: computation_cost: 1000000, storage_cost: 2204000, storage_rebate: 0, non_refundable_storage_fee: 0

task 3 'view-object'. lines 35-35:
Owner: Account Address ( _ )
Version: 2
Contents: Test::f::S {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,0),
},
},
data: Test::f::F::V1{},
}

task 4 'run'. lines 37-37:
mutated: object(0,1), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2264800, storage_rebate: 2181960, non_refundable_storage_fee: 22040

task 5 'view-object'. lines 39-39:
Owner: Account Address ( _ )
Version: 3
Contents: Test::f::S {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,0),
},
},
data: Test::f::F::V4{
x: 42u64,
},
}

task 6 'upgrade'. lines 41-70:
created: object(6,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 8314400, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 7 'view-object'. lines 72-72:
Owner: Account Address ( _ )
Version: 3
Contents: fake(1,0)::f::S {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,0),
},
},
data: fake(1,0)::f::F::V4{
x: 42u64,
},
}

task 8 'run'. lines 74-74:
mutated: object(0,1), object(2,0)
gas summary: computation_cost: 1000000, storage_cost: 2325600, storage_rebate: 2242152, non_refundable_storage_fee: 22648

task 9 'view-object'. lines 76-76:
Owner: Account Address ( _ )
Version: 4
Contents: fake(1,0)::f::S {
id: sui::object::UID {
id: sui::object::ID {
bytes: fake(2,0),
},
},
data: fake(1,0)::f::F::V3{
pos0: 42u64,
pos1: 43u64,
},
}
Loading

0 comments on commit e7d9e8a

Please sign in to comment.