Skip to content

Commit

Permalink
[test] Fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Jul 7, 2024
1 parent 25db745 commit 756ed38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
39 changes: 20 additions & 19 deletions crates/testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ Feature: Rooch CLI integration tests
Scenario: rooch rpc test
Given a server for rooch_rpc_test
Then cmd: "rpc request --method rooch_getStates --params '["/resource/0x3/0x3::account_coin_store::AutoAcceptCoins",{"decode":true}]' --json"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x3::account_coin_store::AutoAcceptCoins'"
#The object_type contians blank space, so, we should quote it
Then assert: "'{{$.rpc[-1][0].object_type}}' == '0x2::object::DynamicField<0x1::string::String, 0x3::account_coin_store::AutoAcceptCoins>'"
Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3",{"decode":true}]' --json"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::account::Account>'"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::account::Account'"
Then cmd: "rpc request --method rooch_listStates --params '["/resource/0x3", null, null, {"decode":true}]' --json"
Then assert: "'{{$.rpc[-1]}}' contains '0x3::account_coin_store::AutoAcceptCoins'"
Then cmd: "rpc request --method rooch_getStates --params '["/object/0x5921974509dbe44ab84328a625f4a6580a5f89dff3e4e2dec448cb2b1c7f5b9",{"decode":true}]' --json"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::object::Timestamp>'"
Then assert: "{{$.rpc[-1][0].decoded_value.value.value.value.milliseconds}} == 0"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::object::Timestamp'"
Then assert: "{{$.rpc[-1][0].decoded_value.value.milliseconds}} == 0"
Then cmd: "rpc request --method rooch_getStates --params '["/object/0x2::object::Timestamp",{"decode":true}]' --json"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::object::Timestamp>'"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::object::Timestamp'"
Then cmd: "rpc request --method rooch_getObjectStates --params '["0x5921974509dbe44ab84328a625f4a6580a5f89dff3e4e2dec448cb2b1c7f5b9", {"decode":false}]' --json"
Then cmd: "rpc request --method rooch_getObjectStates --params '["0x5921974509dbe44ab84328a625f4a6580a5f89dff3e4e2dec448cb2b1c7f5b9", {"decode":true}]' --json"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::object::Timestamp'"
Then assert: "{{$.rpc[-1][0].value}} == {{$.rpc[-2][0].value}}"
Then cmd: "rpc request --method rooch_getFieldStates --params '["0x2214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb", ["0x41022214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb8238d4e7553801ebf92b4311e16bbeb26eec676fd5bcbb31dcc59610148d90c8070000000000000000000000000000000000000000000000000000000000000002066f626a656374084f626a656374494400"], {"decode": true, "showDisplay": true}]' --json"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::module_store::Package>'"
Then cmd: "rpc request --method rooch_getFieldStates --params '["0x2214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb", ["0x337bf72017d07657344a29fff043e10db11eb2e0c8c3ea8e2b6ed36e44ea9c9d"], {"decode": true, "showDisplay": true}]' --json"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::module_store::Package'"
Then cmd: "rpc request --method rooch_listFieldStates --params '["0x2214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb", null, "2", {"decode": false, "showDisplay": false}]' --json"
Then assert: "{{$.rpc[-1].has_next_page}} == true"
Then stop the server
Expand All @@ -42,9 +43,9 @@ Feature: Rooch CLI integration tests
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

Then cmd: "rpc request --method rooch_getStates --params '["/object/0x5921974509dbe44ab84328a625f4a6580a5f89dff3e4e2dec448cb2b1c7f5b9",{"decode":true}]' --json"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::object::Timestamp>'"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::object::Timestamp'"
# ensure the tx_timestamp update the global timestamp
Then assert: "{{$.rpc[-1][0].decoded_value.value.value.value.milliseconds}} != 0"
Then assert: "{{$.rpc[-1][0].decoded_value.value.milliseconds}} != 0"

# session key
Then cmd: "session-key create --app-name test --app-url https:://test.rooch.network --scope 0x3::empty::empty"
Expand All @@ -69,14 +70,14 @@ Feature: Rooch CLI integration tests
Then cmd: "object -i 0x3"
Then cmd: "object -i 0x2::object::Timestamp"
Then cmd: "state --access-path /object/0x2::object::Timestamp"
Then assert: "{{$.state[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::object::Timestamp>'"
Then assert: "{{$.state[-1][0].object_type}} == '0x2::object::Timestamp'"
Then cmd: "state --access-path /object/0x3::chain_id::ChainID"
Then assert: "{{$.state[-1][0].value_type}} == '0x2::object::ObjectEntity<0x3::chain_id::ChainID>'"
Then assert: "{{$.state[-1][0].decoded_value.value.value.value.id}} == 4"
Then assert: "{{$.state[-1][0].object_type}} == '0x3::chain_id::ChainID'"
Then assert: "{{$.state[-1][0].decoded_value.value.id}} == 4"
Then cmd: "state --access-path /object/0x3::address_mapping::RoochToBitcoinAddressMapping"
Then assert: "{{$.state[-1][0].value_type}} == '0x2::object::ObjectEntity<0x3::address_mapping::RoochToBitcoinAddressMapping>'"
Then assert: "{{$.state[-1][0].object_type}} == '0x3::address_mapping::RoochToBitcoinAddressMapping'"
Then cmd: "state --access-path /object/0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>"
Then assert: "{{$.state[-1][0].value_type}} == '0x2::object::ObjectEntity<0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>>'"
Then assert: "{{$.state[-1][0].object_type}} == '0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>'"
Then stop the server

@serial
Expand Down Expand Up @@ -160,8 +161,8 @@ Feature: Rooch CLI integration tests
Then assert: "{{$.move[-1].return_values[0].decoded_value}} == value1"
#the access-path argument do not support named address yet, so, we use `{{$.address_mapping.default}}` template var to repleace it.
Then cmd: "state --access-path /resource/{{$.address_mapping.default}}/{{$.address_mapping.default}}::kv_store::KVStore"
Then cmd: "state --access-path /fields/{{$.state[-1][0].decoded_value.value.table.value.handle.value.id}}/key1"
Then assert: "{{$.state[-1][0].decoded_value}} == value1"
Then cmd: "state --access-path /fields/{{$.state[-1][0].decoded_value.value.value.value.table.value.handle.value.id}}/key1"
Then assert: "{{$.state[-1][0].decoded_value.value.value}} == value1"


Then stop the server
Expand Down Expand Up @@ -300,13 +301,13 @@ Feature: Rooch CLI integration tests

Then cmd: "event get-events-by-event-handle -t default::child_object::NewChildEvent"
Then cmd: "state --access-path /object/{{$.event[-1].data[0].decoded_event_data.value.id}}"
Then assert: "{{$.state[-1][0].decoded_value.value.value.value.name}} == alice"
Then assert: "{{$.state[-1][0].decoded_value.value.name}} == alice"

Then cmd: "move run --function default::third_party_module_for_child_object::update_child_name --args object:{{$.event[-1].data[0].decoded_event_data.value.id}} --args string:bob"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

Then cmd: "state --access-path /object/{{$.event[-1].data[0].decoded_event_data.value.id}}"
Then assert: "{{$.state[-1][0].decoded_value.value.value.value.name}} == bob"
Then assert: "{{$.state[-1][0].decoded_value.value.name}} == bob"

# because the indexer is async update, so sleep 2 seconds to wait indexer update.
Then sleep: "2"
Expand Down Expand Up @@ -337,7 +338,7 @@ Feature: Rooch CLI integration tests

Then cmd: "event get-events-by-event-handle -t default::display::NewObjectEvent"
Then cmd: "state --access-path /object/{{$.event[-1].data[0].decoded_event_data.value.id}}"
Then assert: "{{$.state[-1][0].decoded_value.value.value.type}} == '{{$.address_mapping.default}}::display::ObjectType'"
Then assert: "{{$.state[-1][0].object_type}} == '{{$.address_mapping.default}}::display::ObjectType'"

Then cmd: "rpc request --method rooch_getStates --params '["/object/{{$.event[-1].data[0].decoded_event_data.value.id}}", {"decode": false, "showDisplay": true}]' --json"
Then assert: "{{$.rpc[-1][0].display_fields.fields.name}} == test_object"
Expand Down
9 changes: 6 additions & 3 deletions examples/display/sources/display.move
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module display::display{
fun init(){
// Template syntax

//TODO after https://github.com/rooch-network/rooch/pull/2066
// The object meta fields is not in MoveStruct, how to display them?

// - `{var_name}`, no space between `{` with `var_name` and `var_name` with `}`.
// - There are two types of template:
// - for object meta fields. Availabel fields: {id}, {owner}, {flag}, {state_root}, {size}
Expand All @@ -37,10 +40,10 @@ module display::display{
// so you can use templates: {value.name}, {value.creator}, {value.description} respectively.
// - Supported type for object instance fields: primitive types, `0x1::string::String`, `0x2::ObjectID`. Other custom Move structs are not supported.
let display_obj = display::object_display<ObjectType>();
display::set_value(display_obj, string::utf8(b"name"), string::utf8(b"{value.name}"));
display::set_value(display_obj, string::utf8(b"name"), string::utf8(b"{name}"));
display::set_value(display_obj, string::utf8(b"uri"), string::utf8(b"https:://{owner}/{id}"));
display::set_value(display_obj, string::utf8(b"description"), string::utf8(b"{value.description}"));
display::set_value(display_obj, string::utf8(b"creator"), string::utf8(b"{value.creator}"));
display::set_value(display_obj, string::utf8(b"description"), string::utf8(b"{description}"));
display::set_value(display_obj, string::utf8(b"creator"), string::utf8(b"{creator}"));

// For resource display templates:
// - there are no object meta fields. {id}, {owner}, {flag}, {state_root}, {size} are not available.
Expand Down
2 changes: 1 addition & 1 deletion moveos/moveos-types/src/moveos_std/object/dynamic_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub fn construct_dynamic_field_struct_tag(name_tag: TypeTag, value_tag: TypeTag)
mod tests {
use super::*;
use crate::{move_std::string::MoveString, state::MoveType};
use move_core_types::account_address::AccountAddress;
use move_core_types::{account_address::AccountAddress, value::MoveTypeLayout};

#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize)]
struct TestStruct {
Expand Down

0 comments on commit 756ed38

Please sign in to comment.