Skip to content

Commit

Permalink
New tests for TransferObject (MystenLabs#2828)
Browse files Browse the repository at this point in the history
- Added new tests for TransferObject
- Fixed bug in owner logic for TransferObject
  • Loading branch information
tnowacki authored Jun 29, 2022
1 parent e979052 commit cae031c
Show file tree
Hide file tree
Showing 18 changed files with 458 additions and 9 deletions.
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}}
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
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}}
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
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}}
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
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
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
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}}
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
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}}
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
Loading

0 comments on commit cae031c

Please sign in to comment.