-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0/n][enums] Move enums implementation (#17245)
## Description This adds the enums implementation for Move. This PR only contains the changes for enums within `external-crates/move` and nowhere else. This PR _does not_ contain any tests. The tests for these changes can be found in the PR above in the stack. Note that individual commits are cut out within this PR to (hopefully) make the review process a bit easier. ## Stack: * #17245 **<< You are here** * #17246 * #17247 * #17248 * #17249 * #17250 * #17251 ## Test plan Tested in the PR above this. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [X] Protocol: Adds a new protocol version, and enables Move enums on devnet. - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [X] JSON-RPC: Adds support for Move enum values in returned json-rpc results. - [X] GraphQL: Adds support for Move enum values and types to GraphQL. - [ ] CLI: - [ ] Rust SDK:
- Loading branch information
Showing
1,082 changed files
with
29,807 additions
and
5,191 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
crates/sui-adapter-transactional-tests/tests/enums/basic_enums.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}, | ||
} |
39 changes: 39 additions & 0 deletions
39
crates/sui-adapter-transactional-tests/tests/enums/basic_enums.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
14 changes: 14 additions & 0 deletions
14
crates/sui-adapter-transactional-tests/tests/enums/coin_wrapper.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
52 changes: 52 additions & 0 deletions
52
crates/sui-adapter-transactional-tests/tests/enums/coin_wrapper.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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
26
crates/sui-adapter-transactional-tests/tests/enums/enum_events.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
40 changes: 40 additions & 0 deletions
40
crates/sui-adapter-transactional-tests/tests/enums/enum_events.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
10 changes: 10 additions & 0 deletions
10
crates/sui-adapter-transactional-tests/tests/enums/enum_otw_check.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
17 changes: 17 additions & 0 deletions
17
crates/sui-adapter-transactional-tests/tests/enums/enum_otw_check.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
82 changes: 82 additions & 0 deletions
82
crates/sui-adapter-transactional-tests/tests/enums/enums_upgrade.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}, | ||
} |
Oops, something went wrong.