Skip to content

Commit

Permalink
Make event::emit's generic private. Fix private transfer. Add tests (M…
Browse files Browse the repository at this point in the history
…ystenLabs#2875)

* Make event::emit's generic private. Fix private transfer. Add tests

- Make event::emit's generic require a struct private
- Fix bug in the "private transfer" check
- Added tests for transfer and event
  • Loading branch information
tnowacki authored Jul 6, 2022
1 parent 3364f0f commit 7daeab4
Show file tree
Hide file tree
Showing 17 changed files with 850 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
processed 11 tasks

task 1 'publish'. lines 8-11:
created: object(103)
written: object(102)

task 2 'publish'. lines 13-18:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 3 'publish'. lines 20-29:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer_to_object_id' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 4 'publish'. lines 31-36:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::freeze_object' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 5 'publish'. lines 38-43:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::share_object' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 6 'publish'. lines 45-51:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer_to_object' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 7 'publish'. lines 53-59:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer_to_object' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 8 'publish'. lines 61-69:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::transfer_child_to_object. Invalid call to 'sui::transfer::transfer_child_to_object' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 9 'publish'. lines 71-79:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::transfer_child_to_object. Invalid call to 'sui::transfer::transfer_child_to_object' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 10 'publish'. lines 81-89:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::transfer_child_to_object. Invalid call to 'sui::transfer::transfer_child_to_address' on an object of type 'a::m::S'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// tests modules cannot use transfer functions outside of the defining module

//# init --addresses a=0x0 test=0x0

//# publish
module a::m {
struct S has key { id: sui::id::VersionedID }
}

//# publish
module test::m {
fun t(s: a::m::S) {
sui::transfer::transfer(s, @100)
}
}

//# publish
module test::m {
fun t(
s: a::m::S,
owner_id: sui::id::VersionedID,
ctx: &mut sui::tx_context::TxContext,
): (sui::id::VersionedID, sui::transfer::ChildRef<a::m::S>) {
sui::transfer::transfer_to_object_id(s, owner_id)
}
}

//# publish
module test::m {
fun t(s: a::m::S) {
sui::transfer::freeze_object(s)
}
}

//# publish
module test::m {
fun t(s: a::m::S) {
sui::transfer::share_object(s)
}
}

//# publish
module test::m {
struct R has key { id: sui::id::VersionedID }
fun t(child: a::m::S, owner: &mut R): sui::transfer::ChildRef<a::m::S> {
sui::transfer::transfer_to_object(child, owner)
}
}

//# publish
module test::m {
struct R has key { id: sui::id::VersionedID }
fun t(child: R, owner: &mut a::m::S): sui::transfer::ChildRef<R> {
sui::transfer::transfer_to_object(child, owner)
}
}

//# publish
module test::m {
use sui::transfer::ChildRef;
use a::m::S;
struct R has key { id: sui::id::VersionedID }
fun transfer_child_to_object(child: S, c: ChildRef<S>, owner: &mut R): ChildRef<S> {
sui::transfer::transfer_child_to_object(child, c, owner)
}
}

//# publish
module test::m {
use sui::transfer::ChildRef;
use a::m::S;
struct R has key { id: sui::id::VersionedID }
fun transfer_child_to_object(child: R, c: ChildRef<R>, owner: &mut S): ChildRef<R> {
sui::transfer::transfer_child_to_object(child, c, owner)
}
}

//# publish
module test::m {
use sui::transfer::ChildRef;
use a::m::S;
struct R has key { id: sui::id::VersionedID }
fun transfer_child_to_object(s: S, c: ChildRef<S>) {
sui::transfer::transfer_child_to_address(s, c, @0x100)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
processed 10 tasks

task 1 'publish'. lines 10-15:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 2 'publish'. lines 17-26:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer_to_object_id' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 3 'publish'. lines 28-33:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::freeze_object' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 4 'publish'. lines 35-40:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::share_object' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 5 'publish'. lines 42-48:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer_to_object' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 6 'publish'. lines 50-56:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::transfer::transfer_to_object' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 7 'publish'. lines 58-65:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::transfer_child_to_object. Invalid call to 'sui::transfer::transfer_child_to_object' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 8 'publish'. lines 67-74:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::transfer_child_to_object. Invalid call to 'sui::transfer::transfer_child_to_object' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }

task 9 'publish'. lines 76-83:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::transfer_child_to_object. Invalid call to 'sui::transfer::transfer_child_to_address' on an object of type 'T0'. The transferred object's type must be defined in the current module, or must have the 'store' type ability") } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// tests modules cannot use transfer functions outside of the defining module
// Note: it is not possible to make a generic type `T<...> has key, store`
// where a given instantiation`T<...>` has key but does _not_ have store

//# init --addresses test=0x0

//# publish
module test::m {
fun t<T: key>(s: T) {
sui::transfer::transfer(s, @100)
}
}

//# publish
module test::m {
fun t<T: key>(
s: T,
owner_id: sui::id::VersionedID,
ctx: &mut sui::tx_context::TxContext,
): (sui::id::VersionedID, sui::transfer::ChildRef<T>) {
sui::transfer::transfer_to_object_id(s, owner_id)
}
}

//# publish
module test::m {
fun t<T: key>(s: T) {
sui::transfer::freeze_object(s)
}
}

//# publish
module test::m {
fun t<T: key>(s: T) {
sui::transfer::share_object(s)
}
}

//# publish
module test::m {
struct R has key { id: sui::id::VersionedID }
fun t<T: key>(child: T, owner: &mut R): sui::transfer::ChildRef<T> {
sui::transfer::transfer_to_object(child, owner)
}
}

//# publish
module test::m {
struct R has key { id: sui::id::VersionedID }
fun t<T: key>(child: R, owner: &mut T): sui::transfer::ChildRef<R> {
sui::transfer::transfer_to_object(child, owner)
}
}

//# publish
module test::m {
use sui::transfer::ChildRef;
struct R has key { id: sui::id::VersionedID }
fun transfer_child_to_object<T: key>(child: T, c: ChildRef<T>, owner: &mut R): ChildRef<T> {
sui::transfer::transfer_child_to_object(child, c, owner)
}
}

//# publish
module test::m {
use sui::transfer::ChildRef;
struct R has key { id: sui::id::VersionedID }
fun transfer_child_to_object<T: key>(child: R, c: ChildRef<R>, owner: &mut T): ChildRef<R> {
sui::transfer::transfer_child_to_object(child, c, owner)
}
}

//# publish
module test::m {
use sui::transfer::ChildRef;
struct R has key { id: sui::id::VersionedID }
fun transfer_child_to_object<T: key>(s: T, c: ChildRef<T>) {
sui::transfer::transfer_child_to_address(s, c, @0x100)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
processed 6 tasks

task 1 'publish'. lines 8-11:
created: object(103)
written: object(102)

task 2 'publish'. lines 13-18:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::event::emit' with an event type 'a::m::S'. The event's type must be defined in the current module") } }

task 3 'publish'. lines 20-25:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::event::emit' with an event type 'T0'. The event's type must be defined in the current module") } }

task 4 'publish'. lines 27-32:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::event::emit' with an event type 'u64'. The event's type must be defined in the current module") } }

task 5 'publish'. lines 34-40:
Error: Transaction Effects Status: MiscellaneousError
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: ModuleVerificationFailure, source: Some("_::m::t. Invalid call to 'sui::event::emit' with an event type 'vector<_::m::X>'. The event's type must be defined in the current module") } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// tests modules cannot emit events for types not defined in the current module

//# init --addresses a=0x0 test=0x0

//# publish
module a::m {
struct S has copy, drop {}
}

//# publish
module test::m {
fun t(s: a::m::S) {
sui::event::emit(s)
}
}

//# publish
module test::m {
fun t<T: copy + drop>(x: T) {
sui::event::emit(x)
}
}

//# publish
module test::m {
fun t(x: u64) {
sui::event::emit(x)
}
}

//# publish
module test::m {
struct X has copy, drop {}
fun t(x: vector<X>) {
sui::event::emit(x)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
processed 4 tasks

task 1 'publish'. lines 8-11:
created: object(103)
written: object(102)

task 2 'publish'. lines 13-23:
created: object(105)
written: object(104)

task 3 'publish'. lines 25-35:
created: object(107)
written: object(106)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// tests modules can use child ref functions, even with a type that does not have store

//# init --addresses a=0x0 t1=0x0 t2=0x0

//# publish
module a::m {
struct S has key { id: sui::id::VersionedID }
}

//# publish
module t1::m {
use a::m::S;
use sui::transfer::ChildRef;
fun t(c: &ChildRef<S>, child: &S): bool {
sui::transfer::is_child(c, child)
}
fun t_gen<T: key>(c: &ChildRef<T>, child: &T): bool {
sui::transfer::is_child(c, child)
}
}

//# publish
module t2::m {
use a::m::S;
use sui::transfer::ChildRef;
fun t(id: sui::id::VersionedID, c: ChildRef<S>) {
sui::transfer::delete_child_object(id, c)
}
fun t_gen<T: key>(id: sui::id::VersionedID, c: ChildRef<T>) {
sui::transfer::delete_child_object(id, c)
}
}
Loading

0 comments on commit 7daeab4

Please sign in to comment.