Skip to content

Commit

Permalink
Owen/bitseed validity 4 (#1776)
Browse files Browse the repository at this point in the history
* feat: ok for run_generator_cpp

* feat: run wasm generator ok

* feat: debug mint validity

* feat: remove case call indirect

* feat: build SFT

* feat: test pack_inscribe_output_args

* feat: debug simpleMap to cbor

* feat: rebase from main 1

* feat: rebase from main 2

* feat: rebase from main 3

* feat: fix lint error

* feat: rebase upstream main

* feat: pull bitseed:0.1.6 in github workflows
  • Loading branch information
yubing744 authored Jun 23, 2024
1 parent 62fbbfc commit f24d3c6
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
docker --version
sleep 6
docker images
docker pull bitseed/bitseed:0.1.4
docker pull bitseed/bitseed:0.1.6
- name: Check code format
run: cargo fmt -- --check
Expand Down
Binary file modified crates/testsuite/data/generator.wasm
100644 → 100755
Binary file not shown.
12 changes: 6 additions & 6 deletions crates/testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ Feature: Rooch CLI integration tests
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

# run wasm cpp generator
#Then cmd: "move run --function default::wasm_execution::run_generator_cpp"
#Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function default::wasm_execution::run_generator_cpp"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

# run wasm rust generator
#Then cmd: "move run --function default::wasm_execution::run_generator_rust"
#Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function default::wasm_execution::run_generator_rust"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

# release servers
Then stop the server
Expand Down Expand Up @@ -458,7 +458,7 @@ Feature: Rooch CLI integration tests
Then cmd: "move run --function default::bitseed_runner::run"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

# Check mint deploy validity
# Check deploy validity
Then cmd: "move view --function 0xa::bitseed::view_validity --args string:{{$.deploy[-1].inscriptions[0].Id}} "
Then assert: "{{$.move[-1].vm_status}} == Executed"
Then assert: "{{$.move[-1].return_values[0].decoded_value.value.vec[0].value.is_valid}} == true"
Expand All @@ -477,7 +477,7 @@ Feature: Rooch CLI integration tests
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

# Check mint bits validity
Then cmd: "move view --function 0xa::bitseed::view_validity --args string:{{$.deploy[-1].inscriptions[0].Id}} "
Then cmd: "move view --function 0xa::bitseed::view_validity --args string:{{$.mint[-1].inscriptions[0].Id}} "
Then assert: "{{$.move[-1].vm_status}} == Executed"
Then assert: "{{$.move[-1].return_values[0].decoded_value.value.vec[0].value.is_valid}} == true"

Expand Down
2 changes: 1 addition & 1 deletion crates/testsuite/tests/images/bitseed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use testcontainers::{core::WaitFor, Image, ImageArgs};

const NAME: &str = "bitseed/bitseed";
const TAG: &str = "0.1.4";
const TAG: &str = "0.1.6";

#[derive(Debug, Default, Clone)]
pub struct BitseedImageArgs {
Expand Down
29 changes: 22 additions & 7 deletions examples/wasm_execution/sources/wasm.move
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ module rooch_examples::wasm_execution {

// 2. inscribe_verify
let function_name = b"inscribe_verify";
let deploy_args = x"8178377b22686569676874223a7b2274797065223a2272616e6765222c2264617461223a7b226d696e223a312c226d6178223a313030307d7d7d";
let deploy_args = x"81a166686569676874a264747970656572616e67656464617461a2636d696e01636d61781903e8";
let seed = x"33303765396262353238616132303930343665306230333336316162333461383966633063313233323764393964363239666336396634383232663638376433";
let user_input = x"";
let attributes_output = x"a26668656967687418c56269646d68656c6c6f5f62697473656564";
let user_input = b"123";
let attributes_output = x"a26668656967687418c56269646d68656c6c6f5f62697473656565";

let buffer = pack_inscribe_generate_args(deploy_args, seed, user_input);
std::debug::print(&string::utf8(b"buffer:"));
std::debug::print(&buffer);

let arg_with_length = wasm::add_length_with_data(buffer);

let arg_list = vector::empty<vector<u8>>();
Expand Down Expand Up @@ -150,12 +153,15 @@ module rooch_examples::wasm_execution {

// 2. inscribe_verify
let function_name = b"inscribe_verify";
let deploy_args = x"8178377b22686569676874223a7b2274797065223a2272616e6765222c2264617461223a7b226d696e223a312c226d6178223a313030307d7d7d";
let seed = x"33303765396262353238616132303930343665306230333336316162333461383966633063313233323764393964363239666336396634383232663638376433";
let deploy_args = x"81a166686569676874a264747970656572616e67656464617461a2636d696e01636d61781903e8";
let seed = x"3330376539626235323861613230393034366530623033333631616233346138396663306331323332376439396436323966633639663438323266363837";
let user_input = x"";
let attributes_output = x"a26668656967687418c56269646d68656c6c6f5f62697473656564";

let buffer = pack_inscribe_generate_args(deploy_args, seed, user_input);
std::debug::print(&string::utf8(b"buffer:"));
std::debug::print(&buffer);

let arg_with_length = wasm::add_length_with_data(buffer);

let arg_list = vector::empty<vector<u8>>();
Expand All @@ -178,14 +184,23 @@ module rooch_examples::wasm_execution {

#[data_struct]
struct InscribeGenerateArgs has copy, drop, store {
attrs: vector<u8>,
attrs: vector<u16>,
seed: std::string::String,
user_input: std::string::String,
}

fun pack_inscribe_generate_args(deploy_args: vector<u8>, seed: vector<u8>, user_input: vector<u8>): vector<u8>{
let attrs = vector::empty();

let i=0;
let len = vector::length(&deploy_args);
while (i < len) {
vector::push_back(&mut attrs, (*vector::borrow(&deploy_args, i) as u16));
i = i + 1;
};

let args = InscribeGenerateArgs{
attrs: deploy_args,
attrs: attrs,
seed: string::utf8(seed),
user_input: string::utf8(user_input)
};
Expand Down
13 changes: 13 additions & 0 deletions frameworks/bitcoin-move/doc/bitcoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Function `get_tx_height`](#0x4_bitcoin_get_tx_height)
- [Function `get_block`](#0x4_bitcoin_get_block)
- [Function `get_block_height`](#0x4_bitcoin_get_block_height)
- [Function `get_block_hash_by_height`](#0x4_bitcoin_get_block_hash_by_height)
- [Function `get_block_by_height`](#0x4_bitcoin_get_block_by_height)
- [Function `get_genesis_block`](#0x4_bitcoin_get_genesis_block)
- [Function `get_latest_block`](#0x4_bitcoin_get_latest_block)
Expand Down Expand Up @@ -165,6 +166,18 @@ Get block via block_hash



<a name="0x4_bitcoin_get_block_hash_by_height"></a>

## Function `get_block_hash_by_height`

Get block hash via block_height


<pre><code><b>public</b> <b>fun</b> <a href="bitcoin.md#0x4_bitcoin_get_block_hash_by_height">get_block_hash_by_height</a>(block_height: u64): <a href="_Option">option::Option</a>&lt;<b>address</b>&gt;
</code></pre>



<a name="0x4_bitcoin_get_block_by_height"></a>

## Function `get_block_by_height`
Expand Down
17 changes: 15 additions & 2 deletions frameworks/bitcoin-move/sources/bitcoin.move
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module bitcoin_move::bitcoin{
hash_to_height: Table<address, u64>,
/// tx id -> tx
txs: Table<address, Transaction>,
/// tx id -> tx
/// tx id -> block height
tx_to_height: Table<address, u64>,
/// tx id list, we can use this to scan txs
tx_ids: TableVec<address>,
Expand Down Expand Up @@ -112,6 +112,7 @@ module bitcoin_move::bitcoin{
process_coinbase_utxo(tx, flotsams, block_height);
let txid = types::tx_id(tx);
table::add(&mut btc_block_store.txs, txid, *tx);
table::add(&mut btc_block_store.tx_to_height, txid, block_height);
table_vec::push_back(&mut btc_block_store.tx_ids, txid);
}

Expand Down Expand Up @@ -299,7 +300,7 @@ module bitcoin_move::bitcoin{
public fun get_tx_height(txid: address): Option<u64>{
let btc_block_store_obj = borrow_block_store();
let btc_block_store = object::borrow(btc_block_store_obj);
if(table::contains(&btc_block_store.txs, txid)){
if(table::contains(&btc_block_store.tx_to_height, txid)){
option::some(*table::borrow(&btc_block_store.tx_to_height, txid))
}else{
option::none()
Expand Down Expand Up @@ -327,6 +328,18 @@ module bitcoin_move::bitcoin{
}
}

/// Get block hash via block_height
public fun get_block_hash_by_height(block_height: u64): Option<address>{
let btc_block_store_obj = borrow_block_store();
let btc_block_store = object::borrow(btc_block_store_obj);
if(table::contains(&btc_block_store.height_to_hash, block_height)){
let block_hash = *table::borrow(&btc_block_store.height_to_hash, block_height);
option::some(block_hash)
}else{
option::none()
}
}

/// Get block via block_height
public fun get_block_by_height(block_height: u64): Option<Header>{
let btc_block_store_obj = borrow_block_store();
Expand Down
3 changes: 1 addition & 2 deletions frameworks/moveos-stdlib/doc/cbor.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ If the field type is primitive type, it will be parsed to bytes, array or object
Serialize a value of type T to CBOR bytes.


<pre><code>#[data_struct(#[T])]
<b>public</b> <b>fun</b> <a href="cbor.md#0x2_cbor_to_cbor">to_cbor</a>&lt;T: drop&gt;(value: &T): <a href="">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="cbor.md#0x2_cbor_to_cbor">to_cbor</a>&lt;T&gt;(value: &T): <a href="">vector</a>&lt;u8&gt;
</code></pre>
93 changes: 84 additions & 9 deletions frameworks/moveos-stdlib/sources/cbor.move
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ module moveos_std::cbor {
option::destroy_some(opt_result)
}

#[data_struct(T)]
/// Serialize a value of type T to CBOR bytes.
public fun to_cbor<T: drop>(value: &T): vector<u8> {
public fun to_cbor<T>(value: &T): vector<u8> {
native_to_cbor(value)
}

Expand Down Expand Up @@ -184,7 +183,7 @@ module moveos_std::cbor {

// check address
let account_bytes = simple_map::borrow(&map, &std::string::utf8(b"account"));
let account = moveos_std::address::from_bytes(*account_bytes);
let account = from_cbor<address>(*account_bytes);
assert!(account == @0x42, 7);

// check inner struct
Expand All @@ -193,12 +192,13 @@ module moveos_std::cbor {
assert!(inner.value == 100u64, 8);

// check bytes
let bytes = simple_map::borrow(&map, &std::string::utf8(b"bytes"));
assert!(vector::length(bytes) == 4, 9);
assert!(vector::borrow(bytes, 0) == &3u8, 10);
assert!(vector::borrow(bytes, 1) == &2u8, 11);
assert!(vector::borrow(bytes, 2) == &1u8, 12);
assert!(vector::borrow(bytes, 3) == &0u8, 13);
let bytes_cbor = simple_map::borrow(&map, &std::string::utf8(b"bytes"));
let bytes = from_cbor<vector<u8>>(*bytes_cbor);
assert!(vector::length(&bytes) == 4, 9);
assert!(vector::borrow(&bytes, 0) == &3u8, 10);
assert!(vector::borrow(&bytes, 1) == &2u8, 11);
assert!(vector::borrow(&bytes, 2) == &1u8, 12);
assert!(vector::borrow(&bytes, 3) == &0u8, 13);

// check inner array
let inner_array_bytes = simple_map::borrow(&map, &std::string::utf8(b"inner_array"));
Expand Down Expand Up @@ -235,4 +235,79 @@ module moveos_std::cbor {
let obj = from_cbor_option<Test>(invalid_bytes);
assert!(option::is_none(&obj), 1);
}

#[test]
fun test_struct_to_map_and_map_to_struct() {
let test = Test {
bool_value: true,
age: 30u8,
balance: 170141183460469231731687303715884105728u128,
sig: 1701411834604692317316873037158841057281687303715884105728u256,
ascii_string: std::ascii::string(b"rooch.network"),
utf8_string: std::string::utf8(b"rooch.network"),
null_value: option::none(),
option_string: option::some(std::string::utf8(b"rooch.network")),
inner: Inner {
value: 100u64,
},
inner_option: option::some(Inner {
value: 102u64,
}),
inner_array: std::vector::singleton(Inner {
value: 101u64,
}),
account: @0x42,
bytes: vector<u8>[3u8, 2u8, 1u8, 0u8],
};

let cbor_bytes = to_cbor(&test);

// cbor to map
let test_map = to_map(cbor_bytes);
// map to cbor
let cbor2_bytes = to_cbor(&test_map);
simple_map::drop(test_map);

let obj = from_cbor<Test>(cbor2_bytes);
assert!(obj.balance == 170141183460469231731687303715884105728u128, 1);
assert!(obj.age == 30u8, 2);
assert!(obj.inner.value == 100u64, 3);

// check bytes
assert!(vector::length(&obj.bytes) == 4, 4);
assert!(vector::borrow(&obj.bytes, 0) == &3u8, 5);
assert!(vector::borrow(&obj.bytes, 1) == &2u8, 6);
assert!(vector::borrow(&obj.bytes, 2) == &1u8, 7);
assert!(vector::borrow(&obj.bytes, 3) == &0u8, 8);

// check inner array
assert!(vector::length(&obj.inner_array) == 1, 9);
assert!(vector::borrow(&obj.inner_array, 0).value == 101u64, 10);

// check account
assert!(obj.account == @0x42, 11);

// check ascii string
assert!(obj.ascii_string == std::ascii::string(b"rooch.network"), 12);

// check utf8 string
assert!(obj.utf8_string == std::string::utf8(b"rooch.network"), 13);

// check bool
assert!(obj.bool_value, 14);

// check null
assert!(option::is_none<Inner>(&obj.null_value), 15);

// check inner_option
assert!(option::is_some(&obj.inner_option), 16);
assert!(option::borrow(&obj.inner_option).value == 102u64, 17);

// check u256
assert!(obj.sig == 1701411834604692317316873037158841057281687303715884105728u256, 18);

// check option string
assert!(option::is_some(&obj.option_string), 19);
assert!(option::borrow(&obj.option_string) == &std::string::utf8(b"rooch.network"), 20);
}
}
15 changes: 0 additions & 15 deletions frameworks/moveos-stdlib/sources/wasm.move
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,4 @@ module moveos_std::wasm {
// 3. Release the WASM VM instance (required step)
release_wasm_instance(wasm_instance);
}

#[test]
fun test_call_indirect() {
// Enable all features for testing
features::init_and_enable_all_features_for_test();

// Define WASM code with a CallIndirect instruction
let wasm_code: vector<u8> = b"(module (type $t0 (func (param i32) (result i32))) (table 1 1 funcref) (elem (i32.const 0) $f) (func $f (type $t0) (param $p i32) (result i32) local.get $p) (func (export \"call_indirect_test\") (param i32) (result i32) local.get 0 i32.const 0 call_indirect (type $t0)))";

// 1. Create WASM VM instance (required step)
let wasm_instance_option = create_wasm_instance_option(wasm_code);
assert!(option::is_none(&wasm_instance_option), 1);
option::destroy_none(wasm_instance_option);
}

}
Loading

0 comments on commit f24d3c6

Please sign in to comment.