Skip to content

Commit

Permalink
[integration-test-runner] private_generics tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Jun 25, 2023
1 parent 0483b79 commit 336b4f4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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<T1: store>(ctx: &mut StorageContext, s: &signer) {
account_storage::global_move_to<Foo>(ctx, s, Foo { x: 500 })
}

public fun run(ctx: &mut StorageContext, s: &signer) {
let _ = string::utf8(b"account_storage");
publish_foo<Foo>(ctx, s)
}

public fun call_moveos_std<T: store>(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<Foo>(object_storage, object_id);
debug::print(&obj);
let (_id,_owner,value) = object::unpack(obj);
account_storage::global_move_to<Foo>(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
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyStruct>(object_storage, object_id);
34 │ let obj = object_storage::remove<KeyStruct>(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<KeyStruct>(ctx, s)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Original file line number Diff line number Diff line change
Expand Up @@ -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<T1>(ctx: &mut StorageContext, s: &signer) {
account_storage::global_move_to<Foo>(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<Foo>(ctx, s)
publish_foo<KeyStruct>(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<phantom T: store> has store, key { v: u8 }

public fun call_moveos_std<T:store>(ctx: &mut StorageContext, sender: signer, object_id: ObjectID) {
public fun call_moveos_std<T:store>(ctx: &mut StorageContext, sender: &signer, object_id: ObjectID) {
let object_storage = storage_context::object_storage_mut(ctx);
//let obj = object_storage::remove<Cup<S>>(object_storage, object_id);
debug::print(&object_id);
let obj = object_storage::remove<KeyStruct>(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);
}
}

0 comments on commit 336b4f4

Please sign in to comment.