Skip to content

Commit

Permalink
fix tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Oct 11, 2023
1 parent 5e9e1fa commit 595201e
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 210 deletions.
7 changes: 2 additions & 5 deletions crates/rooch-framework-tests/tests/cases/object/basic.move
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ module test::m {

public entry fun move_s_to_global(ctx: &mut Context, sender: signer, object_id: ObjectID) {
debug::print(&object_id);
let obj = context::remove_object<S>(ctx, object_id);
debug::print(&obj);
let (_id, _owner, value) = object::unpack(obj);
let (_id, _owner, value) = context::remove_object<S>(ctx, object_id);
account_storage::global_move_to(ctx, &sender, value);
}

Expand All @@ -35,9 +33,8 @@ module test::m {
}

public entry fun move_cup_to_global<T:store>(ctx: &mut Context, sender: signer, object_id: ObjectID) {
let obj = context::remove_object<Cup<S>>(ctx, object_id);
let (_id,_owner,value) = context::remove_object<Cup<S>>(ctx, object_id);
debug::print(&obj);
let (_id,_owner,value) = object::unpack(obj);
account_storage::global_move_to(ctx, &sender, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ script {
fun main(ctx: &mut Context) {
let object = m::new_test_object(12);
let obj_ref = context::new_object<TestObject>(ctx, object);
let context::remove_object<TestObject>(ctx, object_ref::id(&obj_ref));
let (_id, _owner, test_object) = object::unpack(obj);
let (_id, _owner, test_object) = context::remove_object<TestObject>(ctx, object_ref::id(&obj_ref));
m::destroy_test_object(test_object);
}
}
Expand Down
66 changes: 3 additions & 63 deletions crates/rooch-framework-tests/tests/cases/table/basic.exp
Original file line number Diff line number Diff line change
@@ -1,70 +1,10 @@
processed 4 tasks

task 1 'publish'. lines 3-42:
Error: warning: unused alias
┌─ /tmp/tempfile:10:21
10 │ use moveos_std::object_ref::{Self, ObjectRef};
│ ^^^^^^^^^^ Unused 'use' of alias 'object_ref'. Consider removing it

warning[W09001]: unused alias
┌─ /tmp/tempfile:10:21
10 │ use moveos_std::object_ref::{Self, ObjectRef};
│ ^^^^^^^^^^ Unused 'use' of alias 'object_ref'. Consider removing it


status EXECUTED

task 2 'run'. lines 44-56:
Error: error[E03002]: unbound module
┌─ /tmp/tempfile:48:9
48 │ use test::m;
│ ^^^^^^^ Invalid 'use'. Unbound module: '(test=0x42)::m'

error[E03002]: unbound module
┌─ /tmp/tempfile:50:18
50 │ let kv = m::make_kv_store(ctx);
│ ^ Unbound module alias 'm'

error[E03002]: unbound module
┌─ /tmp/tempfile:51:9
51 │ m::add(&mut kv, string::utf8(b"test"), b"value");
│ ^ Unbound module alias 'm'

error[E03002]: unbound module
┌─ /tmp/tempfile:52:26
52 │ let object_ref = m::save_to_object_storage(ctx, kv);
│ ^ Unbound module alias 'm'


status EXECUTED

task 3 'run'. lines 58-71:
Error: error[E03002]: unbound module
┌─ /tmp/tempfile:63:9
63 │ use test::m;
│ ^^^^^^^ Invalid 'use'. Unbound module: '(test=0x42)::m'

error[E03002]: unbound module
┌─ /tmp/tempfile:65:18
65 │ let kv = m::borrow_from_object_storage(ctx, object_id);
│ ^ Unbound module alias 'm'

error[E03002]: unbound module
┌─ /tmp/tempfile:66:17
66 │ assert!(m::contains(kv, string::utf8(b"test")), 1000);
│ ^ Unbound module alias 'm'

error[E03002]: unbound module
┌─ /tmp/tempfile:67:17
67 │ let v = m::borrow(kv, string::utf8(b"test"));
│ ^ Unbound module alias 'm'


status EXECUTED
4 changes: 2 additions & 2 deletions crates/rooch-framework-tests/tests/cases/table/basic.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module test::m {
use moveos_std::context::{Self, Context};
use moveos_std::object;
use moveos_std::object_id::{ObjectID};
use moveos_std::object_ref::{Self, ObjectRef};
use moveos_std::object_ref::{ObjectRef};

struct KVStore has store, key {
table: Table<String,vector<u8>>,
Expand Down Expand Up @@ -55,7 +55,7 @@ script {
}
}

//# run --signers test --args @0x67aa19f0f97630ffdbdee1014c35a70f0de510847212c3b29fa755ab53ca254f
//# run --signers test --args @0xcc48c91b1a0f15813bed988390a2794660ae5dadcd86fdb1b55d4a28d0f74c4d
script {
use std::string;
use moveos_std::context::{Context};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ module creator::test {

public fun call_moveos_std<T: store>(ctx: &mut Context, sender: &signer, object_id: ObjectID) {
debug::print(&object_id);
let obj = context::remove_object<Foo>(ctx, object_id);
let (_id,_owner,value) = context::remove_object<Foo>(ctx, object_id);
debug::print(&obj);
let (_id,_owner,value) = object::unpack(obj);
account_storage::global_move_to<Foo>(ctx, sender, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ module creator::test {

public fun call_moveos_std<T:store>(ctx: &mut Context, sender: &signer, object_id: ObjectID) {
debug::print(&object_id);
let obj = context::remove_object<KeyStruct>(ctx, object_id);
debug::print(&obj);
let (_id,_owner,value) = object::unpack(obj);
let (_id,_owner,value) = context::remove_object<KeyStruct>(ctx, object_id);
account_storage::global_move_to(ctx, sender, value);
}
}
44 changes: 24 additions & 20 deletions examples/basic_object/sources/something.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

module rooch_examples::something {
use std::string::String;

use moveos_std::event;
use moveos_std::object::{Self, Object};
use moveos_std::object_id::ObjectID;
use moveos_std::object_ref::{Self, ObjectRef};
use moveos_std::context::{Self, Context};
use moveos_std::table::{Self, Table};

Expand All @@ -21,26 +20,26 @@ module rooch_examples::something {
}

/// get object id
public fun id(obj: &Object<SomethingProperties>): ObjectID {
object::id(obj)
public fun id(obj: &ObjectRef<SomethingProperties>): ObjectID {
object_ref::id(obj)
}

/// get property 'i' from object
public fun i(obj: &Object<SomethingProperties>): u32 {
object::borrow(obj).i
public fun i(obj: &ObjectRef<SomethingProperties>): u32 {
object_ref::borrow(obj).i
}

/// set property 'i' of object
public(friend) fun set_i(obj: &mut Object<SomethingProperties>, i: u32) {
object::borrow_mut(obj).i = i;
public(friend) fun set_i(obj: &mut ObjectRef<SomethingProperties>, i: u32) {
object_ref::borrow_mut(obj).i = i;
}

public fun j(obj: &Object<SomethingProperties>): u128 {
object::borrow(obj).j
public fun j(obj: &ObjectRef<SomethingProperties>): u128 {
object_ref::borrow(obj).j
}

public(friend) fun set_j(obj: &mut Object<SomethingProperties>, j: u128) {
object::borrow_mut(obj).j = j;
public(friend) fun set_j(obj: &mut ObjectRef<SomethingProperties>, j: u128) {
object_ref::borrow_mut(obj).j = j;
}

struct SomethingCreated {
Expand All @@ -66,14 +65,14 @@ module rooch_examples::something {
ctx: &mut Context,
i: u32,
j: u128,
): Object<SomethingProperties> {
): ObjectRef<SomethingProperties> {
let value = new_something_properties(ctx, i, j);
let obj = context::new_object(
ctx,
value,
);
event::emit(ctx, SomethingCreated {
obj_id: object::id(&obj),
obj_id: object_ref::id(&obj),
i,
j,
});
Expand Down Expand Up @@ -113,11 +112,11 @@ module rooch_examples::something {

public(friend) fun add_foo_table_item(
ctx: &mut Context,
obj: &mut Object<SomethingProperties>,
obj: &mut ObjectRef<SomethingProperties>,
key: String,
val: String
) {
table::add(&mut object::borrow_mut(obj).fooTable, key, val);
table::add(&mut object_ref::borrow_mut(obj).fooTable, key, val);
event::emit(ctx, FooTableItemAdded {
item: KeyValuePair {
key,
Expand All @@ -126,14 +125,19 @@ module rooch_examples::something {
});
}

public(friend) fun add_something(ctx: &mut Context, obj: Object<SomethingProperties>) {
context::add_object(ctx, obj);
public(friend) fun get_something(
ctx: &mut Context,
obj_id: ObjectID
): ObjectRef<SomethingProperties> {
let obj = context::borrow_object_mut<SomethingProperties>(ctx, obj_id);
object_ref::new(obj)
}

public(friend) fun remove_something(
ctx: &mut Context,
obj_id: ObjectID
): Object<SomethingProperties> {
context::remove_object<SomethingProperties>(ctx, obj_id)
): SomethingProperties {
let (_id, _owner, value) = context::remove_object<SomethingProperties>(ctx, obj_id);
value
}
}
13 changes: 5 additions & 8 deletions examples/basic_object/sources/something_aggregate.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module rooch_examples::something_aggregate {
i: u32,
j: u128,
) {
let obj = something::create_something(stoage_ctx, i, j);
something::add_something(stoage_ctx, obj);
something::create_something(stoage_ctx, i, j);
}

public entry fun add_foo_table_item(
Expand All @@ -24,17 +23,15 @@ module rooch_examples::something_aggregate {
key: String,
val: String,
) {
let obj = something::remove_something(ctx, object_id);
let update_obj = something_do_logic::add_foo_table_item(ctx, obj, key, val);
something::add_something(ctx, update_obj);
let obj = something::get_something(ctx, object_id);
something_do_logic::add_foo_table_item(ctx, obj, key, val);
}

public entry fun remove_do_something_add(
ctx: &mut Context,
object_id: ObjectID,
) {
let obj = something::remove_something(ctx, object_id);
let update_obj = something_do_logic::do_something(obj);
something::add_something(ctx, update_obj);
let obj = something::get_something(ctx, object_id);
something_do_logic::do_something(obj);
}
}
9 changes: 4 additions & 5 deletions examples/basic_object/sources/something_do_logic.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

module rooch_examples::something_do_logic {
use std::string::String;

use moveos_std::object::Object;
use moveos_std::object_ref::ObjectRef;
use moveos_std::context::Context;
use rooch_examples::something::{Self, SomethingProperties};

friend rooch_examples::something_aggregate;

public(friend) fun do_something(obj: Object<SomethingProperties>): Object<SomethingProperties> {
public(friend) fun do_something(obj: ObjectRef<SomethingProperties>): ObjectRef<SomethingProperties> {
let i = something::i(&obj) + 1;
something::set_i(&mut obj, i);
let j = something::j(&obj) + 1;
Expand All @@ -20,10 +19,10 @@ module rooch_examples::something_do_logic {

public(friend) fun add_foo_table_item(
ctx: &mut Context,
obj: Object<SomethingProperties>,
obj: ObjectRef<SomethingProperties>,
key: String,
val: String
): Object<SomethingProperties> {
): ObjectRef<SomethingProperties> {
something::add_foo_table_item(ctx, &mut obj, key, val);
obj
}
Expand Down
Loading

0 comments on commit 595201e

Please sign in to comment.