From a9f26c06df7dbb9b6725c1f15bb27bed2b493d3a Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Fri, 12 Jan 2024 00:24:30 +0000 Subject: [PATCH] [GraphQL/E2E][EASY] Finish porting variables to interpolation (#15529) ## Description Replace all remaining instances of GraphQL variable-based binding to interpolation-based binding (which is more general), so that we can clean-up the code in the E2E test runner that deals with GraphQL variable substitution and printing. ## Test Plan ``` sui-graphql-e2e-tests$ cargo nextest run -j 1 --features pg_integration ``` ## Stack - #15467 - #15470 - #15471 - #15472 - #15473 - #15474 - #15475 - #15484 - #15485 - #15519 - #15520 - #15521 - #15522 - #15523 - #15524 - #15525 - #15526 - #15527 - #15625 - #15528 --- .../tests/call/dynamic_fields.move | 20 +-- .../tests/call/simple.exp | 137 +++--------------- .../tests/call/simple.move | 28 ++-- .../sui-transactional-test-runner/src/args.rs | 4 - .../src/test_adapter.rs | 85 +---------- 5 files changed, 41 insertions(+), 233 deletions(-) diff --git a/crates/sui-graphql-e2e-tests/tests/call/dynamic_fields.move b/crates/sui-graphql-e2e-tests/tests/call/dynamic_fields.move index 027c117596877..74ca68a13f837 100644 --- a/crates/sui-graphql-e2e-tests/tests/call/dynamic_fields.move +++ b/crates/sui-graphql-e2e-tests/tests/call/dynamic_fields.move @@ -61,9 +61,9 @@ module Test::m { //# create-checkpoint -//# run-graphql --variables obj_2_0 +//# run-graphql { - object(address: $obj_2_0) { + object(address: "@{obj_2_0}") { dynamicFieldConnection { nodes { name { @@ -90,9 +90,9 @@ module Test::m { //# create-checkpoint -//# run-graphql --variables obj_2_0 +//# run-graphql { - object(address: $obj_2_0) { + object(address: "@{obj_2_0}") { dynamicFieldConnection { nodes { name { @@ -115,9 +115,9 @@ module Test::m { } } -//# run-graphql --variables obj_2_0 +//# run-graphql { - owner(address: $obj_2_0) { + owner(address: "@{obj_2_0}") { dynamicFieldConnection { nodes { name { @@ -142,9 +142,9 @@ module Test::m { } } -//# run-graphql --variables obj_2_0 +//# run-graphql { - owner(address: $obj_2_0) { + owner(address: "@{obj_2_0}") { dynamicField(name: {type: "u64", bcs: "AAAAAAAAAAA="}) { name { type { @@ -164,9 +164,9 @@ module Test::m { } } -//# run-graphql --variables obj_2_0 +//# run-graphql { - owner(address: $obj_2_0) { + owner(address: "@{obj_2_0}") { dynamicObjectField(name: {type: "u64", bcs: "AAAAAAAAAAA="}) { value { ... on MoveObject { diff --git a/crates/sui-graphql-e2e-tests/tests/call/simple.exp b/crates/sui-graphql-e2e-tests/tests/call/simple.exp index 963d951e83c8e..ccf407cff5a78 100644 --- a/crates/sui-graphql-e2e-tests/tests/call/simple.exp +++ b/crates/sui-graphql-e2e-tests/tests/call/simple.exp @@ -1,4 +1,4 @@ -processed 26 tasks +processed 25 tasks init: validator_0: object(0,0) @@ -40,14 +40,14 @@ task 8 'view-checkpoint'. lines 42-42: CheckpointSummary { epoch: 0, seq: 4, content_digest: D3oWLCcqoa1D15gxzvMaDemNNY8YYVspAkYkcmtQKWRt, epoch_rolling_gas_cost_summary: GasCostSummary { computation_cost: 3000000, storage_cost: 10176400, storage_rebate: 1956240, non_refundable_storage_fee: 19760 }} -task 9 'advance-epoch'. lines 45-45: +task 9 'advance-epoch'. lines 44-44: Epoch advanced: 5 -task 10 'view-checkpoint'. lines 47-47: +task 10 'view-checkpoint'. lines 46-46: CheckpointSummary { epoch: 5, seq: 10, content_digest: B5upjfaYHdtnxEmH68QF7iQC5PcqZFDuCEJgfZGuX7Nt, epoch_rolling_gas_cost_summary: GasCostSummary { computation_cost: 0, storage_cost: 0, storage_rebate: 0, non_refundable_storage_fee: 0 }} -task 11 'run-graphql'. lines 49-55: +task 11 'run-graphql'. lines 48-53: Response: { "data": { "checkpoint": { @@ -56,14 +56,14 @@ Response: { } } -task 12 'create-checkpoint'. lines 56-56: +task 12 'create-checkpoint'. lines 55-55: Checkpoint created: 11 -task 13 'view-checkpoint'. lines 58-58: +task 13 'view-checkpoint'. lines 57-57: CheckpointSummary { epoch: 6, seq: 11, content_digest: D3oWLCcqoa1D15gxzvMaDemNNY8YYVspAkYkcmtQKWRt, epoch_rolling_gas_cost_summary: GasCostSummary { computation_cost: 0, storage_cost: 0, storage_rebate: 0, non_refundable_storage_fee: 0 }} -task 14 'run-graphql'. lines 60-66: +task 14 'run-graphql'. lines 59-64: Response: { "data": { "checkpoint": { @@ -72,7 +72,7 @@ Response: { } } -task 15 'run-graphql'. lines 68-74: +task 15 'run-graphql'. lines 66-71: Headers: { "content-type": "application/json", "content-length": "157", @@ -97,14 +97,14 @@ Response: { } } -task 16 'view-checkpoint'. lines 76-76: +task 16 'view-checkpoint'. lines 73-73: CheckpointSummary { epoch: 6, seq: 11, content_digest: D3oWLCcqoa1D15gxzvMaDemNNY8YYVspAkYkcmtQKWRt, epoch_rolling_gas_cost_summary: GasCostSummary { computation_cost: 0, storage_cost: 0, storage_rebate: 0, non_refundable_storage_fee: 0 }} -task 17 'advance-epoch'. lines 78-81: +task 17 'advance-epoch'. lines 75-78: Epoch advanced: 6 -task 18 'run-graphql'. lines 83-98: +task 18 'run-graphql'. lines 80-95: Response: { "data": { "address": { @@ -125,7 +125,7 @@ Response: { } } -task 19 'run-graphql'. lines 100-155: +task 19 'run-graphql'. lines 97-152: Response: { "data": { "address": { @@ -220,104 +220,7 @@ Response: { } } -task 20 'view-graphql-variables'. lines 158-159: -Name: A -Type: SuiAddress! -Value: "0x42" - -Name: A_opt -Type: SuiAddress -Value: "0x42" - -Name: Test -Type: SuiAddress! -Value: "0xdc7a6a72118903b903eb2a890903e0a4290e16cdd995e63b6a88491d231ab41f" - -Name: Test_opt -Type: SuiAddress -Value: "0xdc7a6a72118903b903eb2a890903e0a4290e16cdd995e63b6a88491d231ab41f" - -Name: deepbook -Type: SuiAddress! -Value: "0xdee9" - -Name: deepbook_opt -Type: SuiAddress -Value: "0xdee9" - -Name: obj_0_0 -Type: SuiAddress! -Value: "0x15185c3222855fbd3dedb8d89302127683df515a5180ca6b8c2d1d469c5419a8" - -Name: obj_0_0_opt -Type: SuiAddress -Value: "0x15185c3222855fbd3dedb8d89302127683df515a5180ca6b8c2d1d469c5419a8" - -Name: obj_0_1 -Type: SuiAddress! -Value: "0x2fbcf16a09621693013ade94d19616a74d4ce9f8338d5cf0a3f2d041d1f3d694" - -Name: obj_0_1_opt -Type: SuiAddress -Value: "0x2fbcf16a09621693013ade94d19616a74d4ce9f8338d5cf0a3f2d041d1f3d694" - -Name: obj_1_0 -Type: SuiAddress! -Value: "0xdc7a6a72118903b903eb2a890903e0a4290e16cdd995e63b6a88491d231ab41f" - -Name: obj_1_0_opt -Type: SuiAddress -Value: "0xdc7a6a72118903b903eb2a890903e0a4290e16cdd995e63b6a88491d231ab41f" - -Name: obj_2_0 -Type: SuiAddress! -Value: "0x8e9a6c3b9d73fec551cb042c7283de0076fbdb60b8b2c41f6f916f9b1d11a114" - -Name: obj_2_0_opt -Type: SuiAddress -Value: "0x8e9a6c3b9d73fec551cb042c7283de0076fbdb60b8b2c41f6f916f9b1d11a114" - -Name: obj_3_0 -Type: SuiAddress! -Value: "0x5421f975384c0c0a3a22ce771dd616bde2acbb6ffc16a8a8b4595e33f79d2aa5" - -Name: obj_3_0_opt -Type: SuiAddress -Value: "0x5421f975384c0c0a3a22ce771dd616bde2acbb6ffc16a8a8b4595e33f79d2aa5" - -Name: std -Type: SuiAddress! -Value: "0x1" - -Name: std_opt -Type: SuiAddress -Value: "0x1" - -Name: sui -Type: SuiAddress! -Value: "0x2" - -Name: sui_opt -Type: SuiAddress -Value: "0x2" - -Name: sui_system -Type: SuiAddress! -Value: "0x3" - -Name: sui_system_opt -Type: SuiAddress -Value: "0x3" - -Name: validator_0 -Type: SuiAddress! -Value: "0xa7b032703878aa74c3126935789fd1d4d7e111d5911b09247d6963061c312b5a" - -Name: validator_0_opt -Type: SuiAddress -Value: "0xa7b032703878aa74c3126935789fd1d4d7e111d5911b09247d6963061c312b5a" - -task 21 'run-graphql'. lines 162-176: +task 20 'run-graphql'. lines 154-168: Response: { "data": { "epoch": { @@ -337,7 +240,7 @@ Response: { } } -task 22 'run-graphql'. lines 178-184: +task 21 'run-graphql'. lines 170-176: Response: { "data": { "epoch": { @@ -346,17 +249,17 @@ Response: { } } -task 23 'run'. lines 186-186: -created: object(23,0) +task 22 'run'. lines 178-178: +created: object(22,0) mutated: object(0,1) gas summary: computation_cost: 999000, storage_cost: 2302800, storage_rebate: 978120, non_refundable_storage_fee: 9880 -task 24 'run'. lines 188-188: -created: object(24,0) +task 23 'run'. lines 180-180: +created: object(23,0) mutated: object(0,1) gas summary: computation_cost: 1000000, storage_cost: 2302800, storage_rebate: 978120, non_refundable_storage_fee: 9880 -task 25 'run'. lines 190-190: -created: object(25,0) +task 24 'run'. lines 182-182: +created: object(24,0) mutated: object(0,1) gas summary: computation_cost: 235000, storage_cost: 2302800, storage_rebate: 978120, non_refundable_storage_fee: 9880 diff --git a/crates/sui-graphql-e2e-tests/tests/call/simple.move b/crates/sui-graphql-e2e-tests/tests/call/simple.move index 3726882a0819b..89e0838c33d29 100644 --- a/crates/sui-graphql-e2e-tests/tests/call/simple.move +++ b/crates/sui-graphql-e2e-tests/tests/call/simple.move @@ -41,24 +41,22 @@ module Test::M1 { //# view-checkpoint - //# advance-epoch 6 //# view-checkpoint //# run-graphql - { checkpoint { sequenceNumber } } + //# create-checkpoint //# view-checkpoint //# run-graphql - { checkpoint { sequenceNumber @@ -66,7 +64,6 @@ module Test::M1 { } //# run-graphql --show-usage --show-headers --show-service-version - { checkpoint { sequenceNumber @@ -80,9 +77,9 @@ module Test::M1 { // Demonstrates using variables // If the variable ends in _opt, this is the optional variant -//# run-graphql --variables A +//# run-graphql { - address(address: $A) { + address(address: "@{A}") { objectConnection{ edges { node { @@ -97,9 +94,9 @@ module Test::M1 { } } -//# run-graphql --variables Test A obj_2_0 validator_0 +//# run-graphql { - address(address: $Test) { + address(address: "@{Test}") { objectConnection{ edges { node { @@ -112,7 +109,7 @@ module Test::M1 { } } } - second: address(address: $A) { + second: address(address: "@{A}") { objectConnection{ edges { node { @@ -126,7 +123,7 @@ module Test::M1 { } } - val_objs: address(address: $validator_0) { + val_objs: address(address: "@{validator_0}") { objectConnection{ edges { node { @@ -140,7 +137,7 @@ module Test::M1 { } } - object(address: $obj_2_0) { + object(address: "@{obj_2_0}") { version owner { __typename @@ -154,12 +151,7 @@ module Test::M1 { } - -//# view-graphql-variables -// List all the graphql variables - - -//# run-graphql --variables validator_0 +//# run-graphql { epoch { validatorSet { @@ -170,7 +162,7 @@ module Test::M1 { } } } - address(address: $validator_0) { + address(address: "@{validator_0}") { address } } diff --git a/crates/sui-transactional-test-runner/src/args.rs b/crates/sui-transactional-test-runner/src/args.rs index 945d550bb2477..f2071cd673ffa 100644 --- a/crates/sui-transactional-test-runner/src/args.rs +++ b/crates/sui-transactional-test-runner/src/args.rs @@ -157,8 +157,6 @@ pub struct RunGraphqlCommand { #[clap(long = "show-service-version")] pub show_service_version: bool, #[clap(long, num_args(1..))] - pub variables: Vec, - #[clap(long, num_args(1..))] pub cursors: Vec, } @@ -212,8 +210,6 @@ pub enum SuiSubcommand { ViewCheckpoint, #[clap(name = "run-graphql")] RunGraphql(RunGraphqlCommand), - #[clap(name = "view-graphql-variables")] - ViewGraphqlVariables, } #[derive(Clone, Debug)] diff --git a/crates/sui-transactional-test-runner/src/test_adapter.rs b/crates/sui-transactional-test-runner/src/test_adapter.rs index 5a5fc274b71a2..658c57778ba59 100644 --- a/crates/sui-transactional-test-runner/src/test_adapter.rs +++ b/crates/sui-transactional-test-runner/src/test_adapter.rs @@ -47,7 +47,6 @@ use std::{ use sui_core::authority::test_authority_builder::TestAuthorityBuilder; use sui_core::authority::AuthorityState; use sui_framework::DEFAULT_FRAMEWORK_PATH; -use sui_graphql_rpc::client::simple_client::GraphqlQueryVariable; use sui_graphql_rpc::config::ConnectionConfig; use sui_graphql_rpc::test_infra::cluster::serve_executor; use sui_graphql_rpc::test_infra::cluster::ExecutorCluster; @@ -528,24 +527,10 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter<'a> { }}; } match command { - SuiSubcommand::ViewGraphqlVariables => { - let variables = self.graphql_variables(); - let mut res = vec![]; - for (name, value) in variables { - res.push(format!( - "Name: {}\nType: {}\nValue: {}", - name, - value.ty, - serde_json::to_string_pretty(&value.value).unwrap() - )); - } - Ok(Some(res.join("\n\n"))) - } SuiSubcommand::RunGraphql(RunGraphqlCommand { show_usage, show_headers, show_service_version, - variables, cursors, }) => { let file = data.ok_or_else(|| anyhow::anyhow!("Missing GraphQL query"))?; @@ -557,16 +542,9 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter<'a> { .await; let interpolated = self.interpolate_query(&contents, &cursors)?; - - let used_variables = self.resolve_graphql_variables(&variables)?; let resp = cluster .graphql_client - .execute_to_graphql( - interpolated.trim().to_owned(), - show_usage, - used_variables, - vec![], - ) + .execute_to_graphql(interpolated.trim().to_owned(), show_usage, vec![], vec![]) .await?; let mut output = vec![]; @@ -1039,67 +1017,6 @@ impl<'a> SuiTestAdapter<'a> { self.executor } - fn graphql_variables(&self) -> BTreeMap { - let mut variables = BTreeMap::new(); - let named_addrs = self - .compiled_state - .named_address_mapping - .iter() - .map(|(name, addr)| (name.clone(), format!("{:#02x}", addr))); - - let objects = self - .object_enumeration - .iter() - .filter_map(|(oid, fid)| match fid { - FakeID::Known(_) => None, - FakeID::Enumerated(x, y) => Some((format!("obj_{x}_{y}"), oid.to_string())), - }); - - for (name, addr) in named_addrs.chain(objects) { - let addr = addr.to_string(); - - // Required variant - variables.insert( - name.to_owned(), - GraphqlQueryVariable { - name: name.to_string(), - value: serde_json::json!(addr), - ty: "SuiAddress!".to_string(), - }, - ); - // Optional variant - let name = name.to_string() + "_opt"; - variables.insert( - name.clone(), - GraphqlQueryVariable { - name: name.to_string(), - value: serde_json::json!(addr), - ty: "SuiAddress".to_string(), - }, - ); - } - variables - } - fn resolve_graphql_variables( - &self, - declared: &[String], - ) -> anyhow::Result> { - let variables = self.graphql_variables(); - let mut res = vec![]; - for decl in declared { - if let Some(var) = variables.get(decl) { - res.push(var.clone()); - } else { - return Err(anyhow!( - "Unknown variable: {}\nAllowed variable mappings are {:#?}", - decl, - variables - )); - } - } - Ok(res) - } - fn named_variables(&self, cursors: &[String]) -> BTreeMap { let mut variables = BTreeMap::new(); let named_addrs = self