From 336b4f42db827761a478ab5f3f17ddc5999bd2e6 Mon Sep 17 00:00:00 2001 From: Feliciss <10203-feliciss@users.noreply.0xacab.org> Date: Sun, 25 Jun 2023 14:33:48 -0600 Subject: [PATCH] [integration-test-runner] private_generics tests. --- .../cases/private_generics_direct_call.exp | 12 +++++ .../cases/private_generics_direct_call.move | 49 +++++++++++++++++++ .../cases/private_generics_indirect_call.exp | 22 ++++++--- .../cases/private_generics_indirect_call.move | 31 +++++------- 4 files changed, 88 insertions(+), 26 deletions(-) create mode 100644 crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.exp create mode 100644 crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.move diff --git a/crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.exp b/crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.exp new file mode 100644 index 0000000000..21c886b326 --- /dev/null +++ b/crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.exp @@ -0,0 +1,12 @@ +processed 4 tasks + +task 1 'publish'. lines 3-35: +status EXECUTED + +task 2 'run'. lines 37-45: +status EXECUTED + +task 3 'view'. lines 47-49: +store key 0x42::test::Foo { + x: 500 +} diff --git a/crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.move b/crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.move new file mode 100644 index 0000000000..e242acb270 --- /dev/null +++ b/crates/rooch-integration-test-runner/tests/cases/private_generics_direct_call.move @@ -0,0 +1,49 @@ +//# init --addresses creator=0x42 + +//# publish +module creator::test { + use std::string; + use moveos_std::account_storage; + use moveos_std::storage_context::{Self, StorageContext}; + use moveos_std::object; + use moveos_std::object_id::ObjectID; + use moveos_std::object_storage; + use std::debug; + + struct Foo has key, store { + x: u64, + } + + #[private_generics(T1)] + fun publish_foo(ctx: &mut StorageContext, s: &signer) { + account_storage::global_move_to(ctx, s, Foo { x: 500 }) + } + + public fun run(ctx: &mut StorageContext, s: &signer) { + let _ = string::utf8(b"account_storage"); + publish_foo(ctx, s) + } + + public fun call_moveos_std(ctx: &mut StorageContext, sender: &signer, object_id: ObjectID) { + let object_storage = storage_context::object_storage_mut(ctx); + debug::print(&object_id); + let obj = object_storage::remove(object_storage, object_id); + debug::print(&obj); + let (_id,_owner,value) = object::unpack(obj); + account_storage::global_move_to(ctx, sender, value); + } +} + +//# run --signers creator +script { + use creator::test; + use moveos_std::storage_context::StorageContext; + + fun main(ctx: &mut StorageContext, s: &signer) { + test::run(ctx, s); + } +} + +//# view +//# --address 0x42 +//# --resource 0x42::test::Foo diff --git a/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.exp b/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.exp index 2b0ab1c6fa..0fcdf56311 100644 --- a/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.exp +++ b/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.exp @@ -3,23 +3,29 @@ processed 3 tasks task 1 'publish'. lines 3-8: status EXECUTED -task 2 'publish'. lines 10-48: +task 2 'publish'. lines 10-43: Error: error: resource type "KeyStruct" in function "0x2::object_storage::remove" not defined in current module or not allowed - ┌─ /tmp/tempfile:37:19 + ┌─ /tmp/tempfile:34:19 │ -37 │ let obj = object_storage::remove(object_storage, object_id); +34 │ let obj = object_storage::remove(object_storage, object_id); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: resource type "KeyStruct" in function "0x2::object::unpack" not defined in current module or not allowed - ┌─ /tmp/tempfile:39:34 + ┌─ /tmp/tempfile:36:34 │ -39 │ let (_id,_owner,value) = object::unpack(obj); +36 │ let (_id,_owner,value) = object::unpack(obj); │ ^^^^^^^^^^^^^^^^^^^ error: resource type "KeyStruct" in function "0x2::account_storage::global_move_to" not defined in current module or not allowed - ┌─ /tmp/tempfile:40:9 + ┌─ /tmp/tempfile:37:9 │ -40 │ account_storage::global_move_to(ctx, &sender, value); - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +37 │ account_storage::global_move_to(ctx, sender, value); + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: resource type "KeyStruct" in function "0x42::test::publish_foo" not defined in current module or not allowed + ┌─ /tmp/tempfile:29:9 + │ +29 │ publish_foo(ctx, s) + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.move b/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.move index 805595d5a0..789bbdb6c1 100644 --- a/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.move +++ b/crates/rooch-integration-test-runner/tests/cases/private_generics_indirect_call.move @@ -9,40 +9,35 @@ module creator::test0 { //# publish module creator::test { + use std::string; + use std::debug; + use creator::test0::KeyStruct; + use moveos_std::account_storage; + use moveos_std::storage_context::{Self, StorageContext}; + use moveos_std::object; + use moveos_std::object_id::ObjectID; + use moveos_std::object_storage; + struct Foo has key { x: u64, } - use std::string::{Self}; - use moveos_std::account_storage; #[private_generics(T1)] public fun publish_foo(ctx: &mut StorageContext, s: &signer) { account_storage::global_move_to(ctx, s, Foo { x: 500 }) } - use creator::test0::KeyStruct; - // use moveos_std::account_storage::AccountStorage; - public fun run(ctx: &mut StorageContext, s: &signer) { let _ = string::utf8(b"account_storage"); - publish_foo(ctx, s) + publish_foo(ctx, s) } - use moveos_std::storage_context::{Self, StorageContext}; - use moveos_std::object; - use moveos_std::object_id::ObjectID; - use moveos_std::object_storage; - use std::debug; - - struct S has store, key { v: u8 } - struct Cup has store, key { v: u8 } - - public fun call_moveos_std(ctx: &mut StorageContext, sender: signer, object_id: ObjectID) { + public fun call_moveos_std(ctx: &mut StorageContext, sender: &signer, object_id: ObjectID) { let object_storage = storage_context::object_storage_mut(ctx); - //let obj = object_storage::remove>(object_storage, object_id); + debug::print(&object_id); let obj = object_storage::remove(object_storage, object_id); debug::print(&obj); let (_id,_owner,value) = object::unpack(obj); - account_storage::global_move_to(ctx, &sender, value); + account_storage::global_move_to(ctx, sender, value); } }