Skip to content

Commit

Permalink
add integration test for showDisplay option
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed Jun 10, 2024
1 parent d9e45bb commit 6bb8243
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
35 changes: 32 additions & 3 deletions crates/testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Rooch CLI integration tests
Then cmd: "rpc request --method rooch_getStates --params '["/object/0x2::object::Timestamp",{"decode":true}]'"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::object::Timestamp>'"
Then cmd: "rpc request --method rooch_getObjectStates --params '["0x5921974509dbe44ab84328a625f4a6580a5f89dff3e4e2dec448cb2b1c7f5b9"]'"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::Timestamp'"
Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::object::Timestamp'"
Then cmd: "rpc request --method rooch_getFieldStates --params '["0x2214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb", ["0x41022214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb8238d4e7553801ebf92b4311e16bbeb26eec676fd5bcbb31dcc59610148d90c8070000000000000000000000000000000000000000000000000000000000000002066f626a656374084f626a656374494400"], {"decode": true, "showDisplay": true}]'"
Then assert: "{{$.rpc[-1][0].value_type}} == '0x2::object::ObjectEntity<0x2::module_store::Package>'"
Then cmd: "rpc request --method rooch_listFieldStates --params '["0x2214495c6abca5dd5a2bf0f2a28a74541ff10c89818a1244af24c4874325ebdb", null, "2", {"decode": false, "showDisplay": false}]'"
Expand Down Expand Up @@ -315,8 +315,37 @@ Feature: Rooch CLI integration tests
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

Then stop the server

@serial

@serial
Scenario: object display example
Given a server for object_display
Then cmd: "account create"
Then cmd: "move publish -p ../../examples/display --named-addresses display=default"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

Then cmd: "move run --function default::display::create_object --sender default --args 'string:test_object' --args 'address:default' --args 'string:test object description'"

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 cmd: "rpc request --method rooch_getStates --params '["/object/{{$.event[-1].data[0].decoded_event_data.value.id}}", {"decode": false, "showDisplay": true}]'"
Then assert: "{{$.rpc[-1][0].display_fields.fields.name}} == test_object"

# because the indexer is async update, so sleep 2 seconds to wait indexer update.
Then sleep: "2"

Then cmd: "rpc request --method rooch_queryObjectStates --params '[{"object_type":"{{$.address_mapping.default}}::display::ObjectType"}, null, "10", {"descending": false,"showDisplay":true}]'"
Then assert: "{{$.rpc[-1].data[0].object_id}} == {{$.event[-1].data[0].decoded_event_data.value.id}}"
Then assert: "{{$.rpc[-1].data[0].display_fields.fields.name}} == test_object"

Then cmd: "rpc request --method rooch_getObjectStates --params '["{{$.event[-1].data[0].decoded_event_data.value.id}}", {"decode": false, "showDisplay": true}]'"
Then assert: "{{$.rpc[-1][0].display_fields.fields.name}} == test_object"


Then stop the server

@serial
Scenario: wasm test
# prepare servers
Given a server for wasm_test
Expand Down
8 changes: 7 additions & 1 deletion examples/display/sources/display.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module display::display{
use std::string::{Self, String};
use moveos_std::display;

use moveos_std::object;
use moveos_std::object::{Self, ObjectID};
use moveos_std::account;

struct ResourceType has key {
Expand All @@ -22,6 +22,10 @@ module display::display{
description: String,
}

struct NewObjectEvent has copy, drop{
id: ObjectID,
}

fun init(){
// Template syntax

Expand Down Expand Up @@ -65,9 +69,11 @@ module display::display{

obj_type
);
let id = object::id(&obj);

let sender = moveos_std::tx_context::sender();
object::transfer(obj, sender);
moveos_std::event::emit(NewObjectEvent{id:id});
}

/// Create a new ResourceType
Expand Down

0 comments on commit 6bb8243

Please sign in to comment.