Skip to content

Commit

Permalink
[move] sui framework cleanup
Browse files Browse the repository at this point in the history
- Moving `collection`, `bag`, `object_basics` to examples
- Deleting redundant implementations of `transfer` on types with `store`
- Fixing the numerous tests that expect object_basics to be part of the framework :/
  • Loading branch information
sblackshear committed Aug 22, 2022
1 parent cda512a commit 4d3b15d
Show file tree
Hide file tree
Showing 56 changed files with 786 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ Child Count: None
Contents: sui::coin::Coin<sui::sui::SUI> {id: sui::object::UID {id: sui::object::ID {bytes: fake(106)}}, balance: sui::balance::Balance<sui::sui::SUI> {value: 10u64}}

task 5 'run'. lines 16-16:
created: object(108)
written: object(100), object(107)

task 6 'view-object'. lines 18-18:
Owner: Account Address ( C )
Owner: Account Address ( A )
Version: 2
Child Count: None
Contents: sui::coin::Coin<sui::sui::SUI> {id: sui::object::UID {id: sui::object::ID {bytes: fake(100)}}, balance: sui::balance::Balance<sui::sui::SUI> {value: 99990u64}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

//# view-object 106

//# run sui::coin::transfer --type-args sui::sui::SUI --args object(100) @C --sender B
//# run sui::coin::split_and_transfer --type-args sui::sui::SUI --args object(100) 0 @C --sender B

//# view-object 100
16 changes: 10 additions & 6 deletions crates/sui-adapter-transactional-tests/tests/sui/freeze.exp
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
processed 5 tasks
processed 6 tasks

init:
A: object(100)

task 1 'run'. lines 8-8:
task 1 'publish'. lines 8-70:
created: object(104)
written: object(103)

task 2 'run'. lines 10-10:
written: object(104), object(105)
task 2 'run'. lines 72-72:
created: object(106)
written: object(105)

task 3 'run'. lines 12-12:
task 3 'run'. lines 74-74:
written: object(106), object(107)

task 4 'run'. lines 76-76:
Error: Transaction Effects Status: Entry Argument Type Error. Error for argument at index 0: Immutable and shared objects cannot be passed by-value.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: EntryArgumentError(EntryArgumentError { argument_idx: 0, kind: InvalidObjectByValue }), source: Some("Immutable and shared objects cannot be passed by-value, violation found in argument 0") } }

task 4 'run'. lines 14-14:
task 5 'run'. lines 78-78:
Error: Transaction Effects Status: Entry Argument Type Error. Error for argument at index 0: Immutable objects cannot be passed by mutable reference, &mut.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: EntryArgumentError(EntryArgumentError { argument_idx: 0, kind: InvalidObjectByMuteRef }), source: Some("Argument 0 is expected to be mutable, immutable object found") } }
74 changes: 69 additions & 5 deletions crates/sui-adapter-transactional-tests/tests/sui/freeze.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,76 @@

// test that freezing prevents transfers/mutations

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

//# run sui::object_basics::create --args 10 @A
//# publish

//# run sui::object_basics::freeze_object --args object(104)
module test::object_basics {
use sui::event;
use sui::object::{Self, UID};
use sui::tx_context::{Self, TxContext};
use sui::transfer;

//# run sui::object_basics::transfer --args object(104) @A
struct Object has key, store {
id: UID,
value: u64,
}

//# run sui::object_basics::set_value --args object(104) 1
struct Wrapper has key {
id: UID,
o: Object
}

struct NewValueEvent has copy, drop {
new_value: u64
}

public entry fun create(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::transfer(
Object { id: object::new(ctx), value },
recipient
)
}

public entry fun transfer(o: Object, recipient: address) {
transfer::transfer(o, recipient)
}

public entry fun freeze_object(o: Object) {
transfer::freeze_object(o)
}

public entry fun set_value(o: &mut Object, value: u64) {
o.value = value;
}

// test that reading o2 and updating o1 works
public entry fun update(o1: &mut Object, o2: &Object) {
o1.value = o2.value;
// emit an event so the world can see the new value
event::emit(NewValueEvent { new_value: o2.value })
}

public entry fun delete(o: Object) {
let Object { id, value: _ } = o;
object::delete(id);
}

public entry fun wrap(o: Object, ctx: &mut TxContext) {
transfer::transfer(Wrapper { id: object::new(ctx), o }, tx_context::sender(ctx))
}

public entry fun unwrap(w: Wrapper, ctx: &mut TxContext) {
let Wrapper { id, o } = w;
object::delete(id);
transfer::transfer(o, tx_context::sender(ctx))
}
}

//# run test::object_basics::create --args 10 @A

//# run test::object_basics::freeze_object --args object(106)

//# run test::object_basics::transfer --args object(106) @A

//# run test::object_basics::set_value --args object(106) 1
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
processed 2 tasks
processed 4 tasks

task 0 'run'. lines 7-9:
task 1 'publish'. lines 8-15:
created: object(103)
written: object(102)

task 2 'run'. lines 16-18:
Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: LINKER_ERROR, sub_status: None, message: Some("Cannot find ModuleId { address: _, name: Identifier(\"object_basics\") } in data cache"), exec_state: None, location: Undefined, indices: [], offsets: [] }) } }
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: LINKER_ERROR, sub_status: None, message: Some("Cannot find ModuleId { address: _, name: Identifier(\"M\") } in data cache"), exec_state: None, location: Undefined, indices: [], offsets: [] }) } }

task 1 'run'. lines 10-10:
task 3 'run'. lines 19-19:
Error: Transaction Effects Status: Function Not Found.
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: FunctionNotFound, source: Some("Could not resolve function 'foo' in module sui::object_basics") } }
Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: FunctionNotFound, source: Some("Could not resolve function 'foo' in module Test::M") } }
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

// These functions do not exist

// Instead of calling on the Sui package, we are calling a non-existant package
//# run 0x242::object_basics::create
//# init --addresses Test=0x0

// Calling a non-existant function.
//# run sui::object_basics::foo
//# publish

module Test::M {
public entry fun create(_value: u64, _recipient: address) {}

}

// Instead of calling on the Test package, we are calling a non-existant package
//# run 0x242::M::create

// Calling a non-existent function.
//# run Test::M::foo
38 changes: 21 additions & 17 deletions crates/sui-adapter-transactional-tests/tests/sui/object_basics.exp
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
processed 8 tasks
processed 9 tasks

init:
A: object(100), B: object(101)

task 1 'run'. lines 8-8:
task 1 'publish'. lines 8-70:
created: object(105)
written: object(104)

task 2 'view-object'. lines 10-10:
task 2 'run'. lines 72-72:
created: object(107)
written: object(106)

task 3 'view-object'. lines 74-74:
Owner: Account Address ( A )
Version: 1
Child Count: None
Contents: sui::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(105)}}, value: 10u64}
Contents: test::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(107)}}, value: 10u64}

task 3 'run'. lines 12-12:
written: object(105), object(106)
task 4 'run'. lines 76-76:
written: object(107), object(108)

task 4 'view-object'. lines 14-14:
task 5 'view-object'. lines 78-78:
Owner: Account Address ( B )
Version: 2
Child Count: None
Contents: sui::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(105)}}, value: 10u64}
Contents: test::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(107)}}, value: 10u64}

task 5 'run'. lines 16-16:
created: object(108)
written: object(107)
task 6 'run'. lines 80-80:
created: object(110)
written: object(109)

task 6 'run'. lines 18-18:
events: MoveEvent { package_id: sui, transaction_module: Identifier("object_basics"), sender: B, type_: StructTag { address: sui, module: Identifier("object_basics"), name: Identifier("NewValueEvent"), type_params: [] }, contents: [20, 0, 0, 0, 0, 0, 0, 0] }
written: object(105), object(108), object(109)
task 7 'run'. lines 82-82:
events: MoveEvent { package_id: test, transaction_module: Identifier("object_basics"), sender: B, type_: StructTag { address: test, module: Identifier("object_basics"), name: Identifier("NewValueEvent"), type_params: [] }, contents: [20, 0, 0, 0, 0, 0, 0, 0] }
written: object(107), object(110), object(111)

task 7 'run'. lines 20-20:
written: object(110)
deleted: object(105)
task 8 'run'. lines 84-84:
written: object(112)
deleted: object(107)
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,82 @@

// Exercise test functions that create, transfer, read, update, and delete objects

//# init --accounts A B
//# init --addresses test=0x0 --accounts A B

//# run sui::object_basics::create --sender A --args 10 @A
//# publish

//# view-object 105
module test::object_basics {
use sui::event;
use sui::object::{Self, UID};
use sui::tx_context::{Self, TxContext};
use sui::transfer;

//# run sui::object_basics::transfer --sender A --args object(105) @B
struct Object has key, store {
id: UID,
value: u64,
}

//# view-object 105
struct Wrapper has key {
id: UID,
o: Object
}

//# run sui::object_basics::create --sender B --args 20 @B
struct NewValueEvent has copy, drop {
new_value: u64
}

//# run sui::object_basics::update --sender B --args object(105) object(108) --view-events
public entry fun create(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::transfer(
Object { id: object::new(ctx), value },
recipient
)
}

//# run sui::object_basics::delete --sender B --args object(105)
public entry fun transfer(o: Object, recipient: address) {
transfer::transfer(o, recipient)
}

public entry fun freeze_object(o: Object) {
transfer::freeze_object(o)
}

public entry fun set_value(o: &mut Object, value: u64) {
o.value = value;
}

// test that reading o2 and updating o1 works
public entry fun update(o1: &mut Object, o2: &Object) {
o1.value = o2.value;
// emit an event so the world can see the new value
event::emit(NewValueEvent { new_value: o2.value })
}

public entry fun delete(o: Object) {
let Object { id, value: _ } = o;
object::delete(id);
}

public entry fun wrap(o: Object, ctx: &mut TxContext) {
transfer::transfer(Wrapper { id: object::new(ctx), o }, tx_context::sender(ctx))
}

public entry fun unwrap(w: Wrapper, ctx: &mut TxContext) {
let Wrapper { id, o } = w;
object::delete(id);
transfer::transfer(o, tx_context::sender(ctx))
}
}

//# run test::object_basics::create --sender A --args 10 @A

//# view-object 107

//# run test::object_basics::transfer --sender A --args object(107) @B

//# view-object 107

//# run test::object_basics::create --sender B --args 20 @B

//# run test::object_basics::update --sender B --args object(107) object(110) --view-events

//# run test::object_basics::delete --sender B --args object(107)
30 changes: 17 additions & 13 deletions crates/sui-adapter-transactional-tests/tests/sui/unwrap.exp
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
processed 6 tasks
processed 7 tasks

init:
A: object(100)

task 1 'run'. lines 9-9:
task 1 'publish'. lines 9-71:
created: object(104)
written: object(103)

task 2 'view-object'. lines 11-11:
task 2 'run'. lines 73-73:
created: object(106)
written: object(105)

task 3 'view-object'. lines 75-75:
Owner: Account Address ( A )
Version: 1
Child Count: None
Contents: sui::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(104)}}, value: 10u64}
Contents: test::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(106)}}, value: 10u64}

task 3 'run'. lines 13-13:
created: object(106)
written: object(105)
deleted: object(104)

task 4 'run'. lines 15-15:
written: object(104), object(107)
task 4 'run'. lines 77-77:
created: object(108)
written: object(107)
deleted: object(106)

task 5 'view-object'. lines 17-17:
task 5 'run'. lines 79-79:
written: object(106), object(109)
deleted: object(108)

task 6 'view-object'. lines 81-81:
Owner: Account Address ( A )
Version: 2
Child Count: None
Contents: sui::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(104)}}, value: 10u64}
Contents: test::object_basics::Object {id: sui::object::UID {id: sui::object::ID {bytes: fake(106)}}, value: 10u64}
Loading

0 comments on commit 4d3b15d

Please sign in to comment.