From 0c6ea74992cee01e15e9719679a961de59bf55d8 Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Wed, 13 Sep 2023 13:46:54 +0000 Subject: [PATCH] Add init verification (#797) --- .../init_function/init_function_invalid.exp | 121 ++++++++++++++++++ .../init_function/init_function_invalid.move | 107 ++++++++++++++++ .../init_function/init_function_valid.exp | 13 ++ .../init_function/init_function_valid.move | 34 +++++ 4 files changed, 275 insertions(+) create mode 100644 crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.exp create mode 100644 crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.move create mode 100644 crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.exp create mode 100644 crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.move diff --git a/crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.exp b/crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.exp new file mode 100644 index 0000000000..5e28b70a54 --- /dev/null +++ b/crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.exp @@ -0,0 +1,121 @@ +processed 13 tasks + +task 1 'publish'. lines 3-9: +Error: error: module init function should not have a primitive type other than a signer + ┌─ /tmp/tempfile:5:5 + │ +5 │ ╭ fun init( _: u8 ){ +6 │ │ } + │ ╰─────^ + + + +task 2 'publish'. lines 11-17: +Error: error: module init function should not have a primitive type other than a signer + ┌─ /tmp/tempfile:13:5 + │ +13 │ ╭ fun init( _: u16 ){ +14 │ │ } + │ ╰─────^ + + + +task 3 'publish'. lines 19-25: +Error: error: module init function should not have a primitive type other than a signer + ┌─ /tmp/tempfile:21:5 + │ +21 │ ╭ fun init( _: u32 ){ +22 │ │ } + │ ╰─────^ + + + +task 4 'publish'. lines 27-33: +Error: error: module init function should not have a primitive type other than a signer + ┌─ /tmp/tempfile:29:5 + │ +29 │ ╭ fun init( _: u64 ){ +30 │ │ } + │ ╰─────^ + + + +task 5 'publish'. lines 35-41: +Error: error: module init function should not have a primitive type other than a signer + ┌─ /tmp/tempfile:37:5 + │ +37 │ ╭ fun init( _: u128 ){ +38 │ │ } + │ ╰─────^ + + + +task 6 'publish'. lines 43-49: +Error: error: module init function should not have a primitive type other than a signer + ┌─ /tmp/tempfile:45:5 + │ +45 │ ╭ fun init( _: u256 ){ +46 │ │ } + │ ╰─────^ + + + +task 7 'publish'. lines 52-62: +Error: error: module init function only should have two parameter types with signer or storageContext + ┌─ /tmp/tempfile:57:5 + │ +57 │ ╭ fun init( _foo: Foo ){ +58 │ │ } + │ ╰─────^ + + + +task 8 'publish'. lines 64-71: +Error: error: module init function only should have two parameter types with signer or storageContext + ┌─ /tmp/tempfile:67:5 + │ +67 │ ╭ fun init( _: object_id::ObjectID ){ +68 │ │ } + │ ╰─────^ + + + +task 9 'publish'. lines 73-80: +Error: error: module init function only should have two parameter types with signer or storageContext + ┌─ /tmp/tempfile:76:5 + │ +76 │ ╭ fun init( _: string::String ){ +77 │ │ } + │ ╰─────^ + + + +task 10 'publish'. lines 82-89: +Error: error: module init function only should have two parameter types with signer or storageContext + ┌─ /tmp/tempfile:85:5 + │ +85 │ ╭ fun init( _: string::String ){ +86 │ │ } + │ ╰─────^ + + + +task 11 'publish'. lines 91-98: +Error: error: module init function only should have two parameter types with signer or storageContext + ┌─ /tmp/tempfile:94:5 + │ +94 │ ╭ fun init( _: ascii::String ){ +95 │ │ } + │ ╰─────^ + + + +task 12 'publish'. lines 100-107: +Error: error: module init function should not have a reference primitive type other than a signer + ┌─ /tmp/tempfile:103:5 + │ +103 │ ╭ fun init( _ : & storage_context::StorageContext){ +104 │ │ } + │ ╰─────^ + + diff --git a/crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.move b/crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.move new file mode 100644 index 0000000000..cc948d537d --- /dev/null +++ b/crates/rooch-framework-tests/tests/cases/init_function/init_function_invalid.move @@ -0,0 +1,107 @@ +//# init --addresses creator=0x42 + +//# publish +module creator::test { + + fun init( _: u8 ){ + + } +} + +//# publish +module creator::test { + + fun init( _: u16 ){ + + } +} + +//# publish +module creator::test { + + fun init( _: u32 ){ + + } +} + +//# publish +module creator::test { + + fun init( _: u64 ){ + + } +} + +//# publish +module creator::test { + + fun init( _: u128 ){ + + } +} + +//# publish +module creator::test { + + fun init( _: u256 ){ + + } +} + + +//# publish +module creator::test { + + struct Foo has copy, drop { + x: u64, + } + + fun init( _foo: Foo ){ + + } +} + +//# publish +module creator::test { + use moveos_std::object_id; + + fun init( _: object_id::ObjectID ){ + + } +} + +//# publish +module creator::test { + use std::string; + + fun init( _: string::String ){ + + } +} + +//# publish +module creator::test { + use std::string; + + fun init( _: string::String ){ + + } +} + +//# publish +module creator::test { + use std::ascii; + + fun init( _: ascii::String ){ + + } +} + +//# publish +module creator::test { + use moveos_std::storage_context; + + fun init( _ : & storage_context::StorageContext){ + + } +} \ No newline at end of file diff --git a/crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.exp b/crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.exp new file mode 100644 index 0000000000..4e74d71349 --- /dev/null +++ b/crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.exp @@ -0,0 +1,13 @@ +processed 5 tasks + +task 1 'publish'. lines 3-9: +status EXECUTED + +task 2 'publish'. lines 11-18: +status EXECUTED + +task 3 'publish'. lines 20-26: +status EXECUTED + +task 4 'publish'. lines 28-34: +status EXECUTED diff --git a/crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.move b/crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.move new file mode 100644 index 0000000000..8d86352171 --- /dev/null +++ b/crates/rooch-framework-tests/tests/cases/init_function/init_function_valid.move @@ -0,0 +1,34 @@ +//# init --addresses creator=0x42 + +//# publish +module creator::test { + + fun init( _ : & signer){ + + } +} + +//# publish +module creator::test_mut_ref_storage_context { + use moveos_std::storage_context; + + fun init( _ : &mut storage_context::StorageContext){ + + } +} + +//# publish +module creator::test_signer { + + fun init( _ : signer){ + + } +} + +//# publish +module creator::test_ref_signer { + + fun init( _ : & signer){ + + } +} \ No newline at end of file