forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New tests for TransferObject (MystenLabs#2828)
- Added new tests for TransferObject - Fixed bug in owner logic for TransferObject
- Loading branch information
Showing
18 changed files
with
458 additions
and
9 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
crates/sui-adapter-transactional-tests/tests/transfer_object/does_not_have_store.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,40 @@ | ||
processed 10 tasks | ||
|
||
init: | ||
A: object(100), B: object(101) | ||
|
||
task 1 'publish'. lines 8-29: | ||
created: object(105) | ||
written: object(104) | ||
|
||
task 2 'run'. lines 31-31: | ||
created: object(107) | ||
written: object(106) | ||
|
||
task 3 'view-object'. lines 33-33: | ||
Owner: Account Address ( A ) | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 1u64}} | ||
|
||
task 4 'transfer-object'. lines 35-35: | ||
Error: Transaction Effects Status: MiscellaneousError | ||
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: TransferObjectWithoutPublicTransfer, source: None } } | ||
|
||
task 5 'view-object'. lines 37-40: | ||
Owner: Account Address ( A ) | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 2u64}} | ||
|
||
task 6 'run'. lines 42-42: | ||
created: object(110) | ||
written: object(109) | ||
|
||
task 7 'view-object'. lines 44-44: | ||
Owner: Account Address ( A ) | ||
Contents: test::m::Cup<test::m::S> {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(110)}}, version: 1u64}} | ||
|
||
task 8 'transfer-object'. lines 46-46: | ||
Error: Transaction Effects Status: MiscellaneousError | ||
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: TransferObjectWithoutPublicTransfer, source: None } } | ||
|
||
task 9 'view-object'. lines 48-48: | ||
Owner: Account Address ( A ) | ||
Contents: test::m::Cup<test::m::S> {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(110)}}, version: 2u64}} |
48 changes: 48 additions & 0 deletions
48
crates/sui-adapter-transactional-tests/tests/transfer_object/does_not_have_store.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,48 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// tests TransferObject should fail for an object _without_ public transfer | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish | ||
|
||
module test::m { | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
use sui::id::VersionedID; | ||
|
||
struct S has key { id: VersionedID } | ||
struct Cup<phantom T> has key { id: VersionedID } | ||
|
||
public entry fun mint_s(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::transfer(S { id }, tx_context::sender(ctx)) | ||
} | ||
|
||
public entry fun mint_cup<T>(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::transfer(Cup<T> { id }, tx_context::sender(ctx)) | ||
} | ||
} | ||
|
||
// Mint S to A. Fail to transfer S from A to B, which should fail | ||
|
||
//# run test::m::mint_s --sender A | ||
|
||
//# view-object 107 | ||
|
||
//# transfer-object 107 --sender A --recipient B | ||
|
||
//# view-object 107 | ||
|
||
|
||
// Mint Cup<S> to A. Fail to transfer Cup<S> from A to B | ||
|
||
//# run test::m::mint_cup --type-args test::m::S --sender A | ||
|
||
//# view-object 110 | ||
|
||
//# transfer-object 110 --sender A --recipient B | ||
|
||
//# view-object 110 |
38 changes: 38 additions & 0 deletions
38
crates/sui-adapter-transactional-tests/tests/transfer_object/has_store.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,38 @@ | ||
processed 10 tasks | ||
|
||
init: | ||
A: object(100), B: object(101) | ||
|
||
task 1 'publish'. lines 8-29: | ||
created: object(105) | ||
written: object(104) | ||
|
||
task 2 'run'. lines 31-31: | ||
created: object(107) | ||
written: object(106) | ||
|
||
task 3 'view-object'. lines 33-33: | ||
Owner: Account Address ( A ) | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 1u64}} | ||
|
||
task 4 'transfer-object'. lines 35-35: | ||
written: object(107), object(108) | ||
|
||
task 5 'view-object'. lines 37-40: | ||
Owner: Account Address ( B ) | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 2u64}} | ||
|
||
task 6 'run'. lines 42-42: | ||
created: object(110) | ||
written: object(109) | ||
|
||
task 7 'view-object'. lines 44-44: | ||
Owner: Account Address ( A ) | ||
Contents: test::m::Cup<test::m::S> {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(110)}}, version: 1u64}} | ||
|
||
task 8 'transfer-object'. lines 46-46: | ||
written: object(110), object(111) | ||
|
||
task 9 'view-object'. lines 48-48: | ||
Owner: Account Address ( B ) | ||
Contents: test::m::Cup<test::m::S> {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(110)}}, version: 2u64}} |
48 changes: 48 additions & 0 deletions
48
crates/sui-adapter-transactional-tests/tests/transfer_object/has_store.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,48 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// tests TransferObject with an object with public transfer | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish | ||
|
||
module test::m { | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
use sui::id::VersionedID; | ||
|
||
struct S has store, key { id: VersionedID } | ||
struct Cup<phantom T: store> has store, key { id: VersionedID } | ||
|
||
public entry fun mint_s(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::transfer(S { id }, tx_context::sender(ctx)) | ||
} | ||
|
||
public entry fun mint_cup<T: store>(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::transfer(Cup<T> { id }, tx_context::sender(ctx)) | ||
} | ||
} | ||
|
||
// Mint S to A. Transfer S from A to B | ||
|
||
//# run test::m::mint_s --sender A | ||
|
||
//# view-object 107 | ||
|
||
//# transfer-object 107 --sender A --recipient B | ||
|
||
//# view-object 107 | ||
|
||
|
||
// Mint Cup<S> to A. Transfer Cup<S> from A to B | ||
|
||
//# run test::m::mint_cup --type-args test::m::S --sender A | ||
|
||
//# view-object 110 | ||
|
||
//# transfer-object 110 --sender A --recipient B | ||
|
||
//# view-object 110 |
24 changes: 24 additions & 0 deletions
24
crates/sui-adapter-transactional-tests/tests/transfer_object/immutable.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,24 @@ | ||
processed 6 tasks | ||
|
||
init: | ||
A: object(100), B: object(101) | ||
|
||
task 1 'publish'. lines 8-22: | ||
created: object(105) | ||
written: object(104) | ||
|
||
task 2 'run'. lines 24-24: | ||
created: object(107) | ||
written: object(106) | ||
|
||
task 3 'view-object'. lines 26-26: | ||
Owner: Immutable | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 1u64}} | ||
|
||
task 4 'transfer-object'. lines 28-28: | ||
Error: Transaction Effects Status: MiscellaneousError | ||
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: TransferUnowned, source: None } } | ||
|
||
task 5 'view-object'. lines 30-30: | ||
Owner: Immutable | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 1u64}} |
30 changes: 30 additions & 0 deletions
30
crates/sui-adapter-transactional-tests/tests/transfer_object/immutable.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,30 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// tests TransferObject should fail for an immutable object | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish | ||
|
||
module test::m { | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
use sui::id::VersionedID; | ||
|
||
struct S has store, key { id: VersionedID } | ||
struct Cup<phantom T: store> has store, key { id: VersionedID } | ||
|
||
public entry fun mint_s(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::freeze_object(S { id }) | ||
} | ||
} | ||
|
||
//# run test::m::mint_s --sender A | ||
|
||
//# view-object 107 | ||
|
||
//# transfer-object 107 --sender A --recipient B | ||
|
||
//# view-object 107 |
18 changes: 18 additions & 0 deletions
18
crates/sui-adapter-transactional-tests/tests/transfer_object/package.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,18 @@ | ||
processed 5 tasks | ||
|
||
init: | ||
A: object(100), B: object(101) | ||
|
||
task 1 'publish'. lines 8-10: | ||
created: object(105) | ||
written: object(104) | ||
|
||
task 2 'view-object'. lines 13-13: | ||
105::m | ||
|
||
task 3 'transfer-object'. lines 15-15: | ||
Error: Transaction Effects Status: MiscellaneousError | ||
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: TransferUnowned, source: None } } | ||
|
||
task 4 'view-object'. lines 17-17: | ||
105::m |
17 changes: 17 additions & 0 deletions
17
crates/sui-adapter-transactional-tests/tests/transfer_object/package.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) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// tests TransferObject should fail for a package | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish --sender A | ||
|
||
module test::m {} | ||
|
||
|
||
//# view-object 105 | ||
|
||
//# transfer-object 105 --sender A --recipient B | ||
|
||
//# view-object 105 |
28 changes: 28 additions & 0 deletions
28
crates/sui-adapter-transactional-tests/tests/transfer_object/quasi_shared.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,28 @@ | ||
processed 7 tasks | ||
|
||
init: | ||
A: object(100), B: object(101) | ||
|
||
task 1 'publish'. lines 8-28: | ||
created: object(105) | ||
written: object(104) | ||
|
||
task 2 'run'. lines 30-30: | ||
created: object(107) | ||
written: object(106) | ||
|
||
task 3 'run'. lines 32-32: | ||
created: object(109) | ||
written: object(107), object(108) | ||
|
||
task 4 'view-object'. lines 34-34: | ||
Owner: Object ID: ( fake(107) ) | ||
Contents: test::m::Child {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(109)}}, version: 1u64}} | ||
|
||
task 5 'transfer-object'. lines 36-36: | ||
Error: Transaction Effects Status: MiscellaneousError | ||
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: TransferUnowned, source: None } } | ||
|
||
task 6 'view-object'. lines 38-38: | ||
Owner: Object ID: ( fake(107) ) | ||
Contents: test::m::Child {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(109)}}, version: 2u64}} |
38 changes: 38 additions & 0 deletions
38
crates/sui-adapter-transactional-tests/tests/transfer_object/quasi_shared.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,38 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// tests TransferObject should fail for a quasi-shared object | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish | ||
|
||
module test::m { | ||
use sui::transfer::{Self, ChildRef}; | ||
use sui::tx_context::{Self, TxContext}; | ||
use sui::id::VersionedID; | ||
|
||
struct S has key { id: VersionedID, children: vector<ChildRef<Child>> } | ||
struct Child has key { id: VersionedID } | ||
|
||
public entry fun mint_s(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::share_object(S { id, children: vector[] }) | ||
} | ||
|
||
public entry fun mint_child(s: &mut S, ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
let child = transfer::transfer_to_object(Child { id }, s); | ||
std::vector::push_back(&mut s.children, child) | ||
} | ||
} | ||
|
||
//# run test::m::mint_s | ||
|
||
//# run test::m::mint_child --args object(107) | ||
|
||
//# view-object 109 | ||
|
||
//# transfer-object 109 --sender A --recipient B | ||
|
||
//# view-object 109 |
24 changes: 24 additions & 0 deletions
24
crates/sui-adapter-transactional-tests/tests/transfer_object/shared.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,24 @@ | ||
processed 6 tasks | ||
|
||
init: | ||
A: object(100), B: object(101) | ||
|
||
task 1 'publish'. lines 8-21: | ||
created: object(105) | ||
written: object(104) | ||
|
||
task 2 'run'. lines 23-23: | ||
created: object(107) | ||
written: object(106) | ||
|
||
task 3 'view-object'. lines 25-25: | ||
Owner: Shared | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 1u64}} | ||
|
||
task 4 'transfer-object'. lines 27-27: | ||
Error: Transaction Effects Status: MiscellaneousError | ||
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: TransferUnowned, source: None } } | ||
|
||
task 5 'view-object'. lines 29-29: | ||
Owner: Shared | ||
Contents: test::m::S {id: sui::id::VersionedID {id: sui::id::UniqueID {id: sui::id::ID {bytes: fake(107)}}, version: 2u64}} |
29 changes: 29 additions & 0 deletions
29
crates/sui-adapter-transactional-tests/tests/transfer_object/shared.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,29 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// tests TransferObject should fail for a shared object | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish | ||
|
||
module test::m { | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
use sui::id::VersionedID; | ||
|
||
struct S has key { id: VersionedID } | ||
|
||
public entry fun mint_s(ctx: &mut TxContext) { | ||
let id = tx_context::new_id(ctx); | ||
transfer::share_object(S { id }) | ||
} | ||
} | ||
|
||
//# run test::m::mint_s | ||
|
||
//# view-object 107 | ||
|
||
//# transfer-object 107 --sender A --recipient B | ||
|
||
//# view-object 107 |
Oops, something went wrong.