rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

Verify and publish modules in Move #392

Closed pause125 closed 9 months ago

pause125 commented 10 months ago

This PR is trying to verify modules in native functions. But I got a runtime error:

thread '<unnamed>' panicked at 'extension unknown', /home/joker/.cargo/git/checkouts/move-d59e49550a684528/5597bcf/language/move-vm/runtime/src/native_extensions.rs:32:14

The error is triggered where getting the NativeContextExtensions here and here.

I can't figure out why. Help please @jolestar

vercel[bot] commented 10 months ago

@pause125 is attempting to deploy a commit to the Rooch Team on Vercel.

A member of the Team first needs to authorize it.

jolestar commented 9 months ago

It is strange, the native context has added when the session creating. Please rebase the branch with the man branch, I need to do some debug.

jolestar commented 9 months ago

@pause125

If the unit test triggers the error, you need to init the native context in the unit test command.

https://github.com/pause125/rooch/blob/65c6c016455a6095f31250b2ed0ea1b8432abaa4/crates/rooch/src/commands/move_cli/commands/unit_test.rs#L50-L56

pause125 commented 9 months ago

@pause125

If the unit test triggers the error, you need to init the native context in the unit test command.

https://github.com/pause125/rooch/blob/65c6c016455a6095f31250b2ed0ea1b8432abaa4/crates/rooch/src/commands/move_cli/commands/unit_test.rs#L50-L56

It should be this case. Thanks very much!

vercel[bot] commented 9 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **rooch** | ⬜️ Ignored ([Inspect](https://vercel.com/rooch/rooch/AoetAtUPmTgyrUU6VhmY6b1uu1dQ)) | [Visit Preview](https://rooch-git-fork-pause125-moduleverifyinmove-rooch.vercel.app) | | Aug 12, 2023 3:07pm |
pause125 commented 9 months ago

The PR is ready. For now, I have not found a suitable way to auto test. Now you can test this PR in terminal as follows:

Init and start

  1. clean db and start a server

    rm -r ~/.rooch/roochdb/
    rooch server start
  2. Open a new terminal, publish the examples/publish_modules example. This module provide a entry function to publish a single module.

    rooch move publish -p examples/publish_modules/ --named-addresses rooch_examples=default

Test modules with init function

Note: Remember replacing the address 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8 with your local active account address.

  1. Get the example/counter module bytes

    module_bytes=$(hex=$(xxd -p -c 99999 examples/counter/build/counter/bytecode_modules/counter.mv);decimal_array=(); for ((i=0; i<${#hex}; i+=2)); do hex_element="${hex:i:2}"; decimal_element=$((16#$hex_element)); decimal_array+=("$decimal_element"); done; echo $(IFS=','; echo "${decimal_array[*]}"))
  2. Call move entry function to publish example/counter.

    rooch move run --function 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::publish::publish_modules_entry --args "vector<u8>:$module_bytes" --sender-account default
  3. Check the Counter resource. Replace the addresses with your local active account address.

    rooch resource --address 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8 --resource 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::counter::Counter

you will see the output:

{
  "state": {
    "value": "0x0000000000000000",
    "value_type": "0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::counter::Counter"
  },
  "move_value": {
    "abilities": 12,
    "type": "0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::counter::Counter",
    "value": {
      "value": "0"
    }
  }
}
  1. Call entry function of examples/counter

    rooch move run --function 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::counter::increase --sender-account default
  2. check the resource again

    {
    "state": {
    "value": "0x0100000000000000",
    "value_type": "0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::counter::Counter"
    },
    "move_value": {
    "abilities": 12,
    "type": "0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::counter::Counter",
    "value": {
      "value": "1"
    }
    }
    }

Test modules without init function:

Note: Remember replacing the address 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8 with your local active account address.

  1. Get module bytes of examples/entry_function_arguments

    entry_bytes=$(hex=$(xxd -p -c 99999 examples/entry_function_arguments/build/entry_function_arguments/bytecode_modules/entry_function.mv);decimal_array=(); for ((i=0; i<${#hex}; i+=2)); do hex_element="${hex:i:2}"; decimal_element=$((16#$hex_element)); decimal_array+=("$decimal_element"); done; echo $(IFS=','; echo "${decimal_array[*]}"))
  2. Call move entry function to publish examples/entry_function_arguments

rooch move run --function 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::publish::publish_modules_entry --args "vector<u8>:$entry_bytes" --sender-account default
  1. Call entry function of examples/entry_function_arguments
    rooch move run --function 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8::entry_function::emit_u8 --args u8:3 --sender-account 0x5f5c82f7895b07f2cb8751b2001fb7e80f94845f9915bbd56e112af0f68148c8

All the transactions above should be executed.

TODO:

jolestar commented 9 months ago

Maybe we can support a new command, rooch move publish_in_move to test this feature?

jolestar commented 9 months ago

I merge this PR first.