Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc-alt: e2e tests #20729

Open
wants to merge 4 commits into
base: amnn/rpc-metrics
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ members = [
"crates/sui-graphql-rpc-headers",
"crates/sui-indexer",
"crates/sui-indexer-alt",
"crates/sui-indexer-alt-e2e-tests",
"crates/sui-indexer-alt-framework",
"crates/sui-indexer-alt-jsonrpc",
"crates/sui-indexer-alt-metrics",
Expand Down Expand Up @@ -643,6 +644,7 @@ sui-graphql-rpc-client = { path = "crates/sui-graphql-rpc-client" }
sui-graphql-rpc-headers = { path = "crates/sui-graphql-rpc-headers" }
sui-genesis-builder = { path = "crates/sui-genesis-builder" }
sui-indexer = { path = "crates/sui-indexer" }
sui-indexer-alt = { path = "crates/sui-indexer-alt" }
sui-indexer-alt-framework = { path = "crates/sui-indexer-alt-framework" }
sui-indexer-alt-jsonrpc = { path = "crates/sui-indexer-alt-jsonrpc" }
sui-indexer-alt-metrics = { path = "crates/sui-indexer-alt-metrics" }
Expand Down
1 change: 1 addition & 0 deletions crates/sui-graphql-e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ anyhow.workspace = true
async-trait.workspace = true
telemetry-subscribers.workspace = true
datatest-stable.workspace = true
serde_json.workspace = true
sui-graphql-rpc.workspace = true
sui-transactional-test-runner.workspace = true
tokio.workspace = true
Expand Down
14 changes: 7 additions & 7 deletions crates/sui-graphql-e2e-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#![allow(unused_imports)]
#![allow(unused_variables)]
use anyhow::bail;
use async_trait::async_trait;
use serde_json::Value;
use std::{path::Path, sync::Arc, time::Duration};
use sui_graphql_rpc::test_infra::cluster::{serve_executor, ExecutorCluster};
use sui_transactional_test_runner::{
Expand All @@ -20,12 +22,6 @@ pub struct OffchainReaderForAdapter {

#[async_trait]
impl OffchainStateReader for OffchainReaderForAdapter {
async fn wait_for_objects_snapshot_catchup(&self, base_timeout: Duration) {
self.cluster
.wait_for_objects_snapshot_catchup(base_timeout)
.await
}

async fn wait_for_checkpoint_catchup(&self, checkpoint: u64, base_timeout: Duration) {
self.cluster
.wait_for_checkpoint_catchup(checkpoint, base_timeout)
Expand All @@ -42,7 +38,7 @@ impl OffchainStateReader for OffchainReaderForAdapter {
&self,
query: String,
show_usage: bool,
) -> Result<TestResponse, anyhow::Error> {
) -> anyhow::Result<TestResponse> {
let result = self
.cluster
.graphql_client
Expand All @@ -55,6 +51,10 @@ impl OffchainStateReader for OffchainReaderForAdapter {
service_version: result.graphql_version().ok(),
})
}

async fn execute_jsonrpc(&self, _: String, _: Value) -> anyhow::Result<TestResponse> {
bail!("JSON-RPC queries are not supported in these tests")
}
}

datatest_stable::harness!(
Expand Down
36 changes: 36 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "sui-indexer-alt-e2e-tests"
version = "0.1.0"
authors = ["Mysten Labs <[email protected]>"]
license = "Apache-2.0"
publish = false
edition = "2021"

[lints]
workspace = true

[[test]]
name = "tests"
harness = false

[dependencies]

[dev-dependencies]
anyhow.workspace = true
async-trait.workspace = true
datatest-stable.workspace = true
diesel = { workspace = true, features = ["chrono"] }
diesel-async = { workspace = true, features = ["bb8", "postgres", "async-connection-wrapper"] }
prometheus.workspace = true
reqwest.workspace = true
serde_json.workspace = true
telemetry-subscribers.workspace = true
tokio.workspace = true
tokio-util.workspace = true
url.workspace = true

sui-indexer-alt.workspace = true
sui-indexer-alt-framework.workspace = true
sui-indexer-alt-jsonrpc.workspace = true
sui-pg-db.workspace = true
sui-transactional-test-runner.workspace = true
6 changes: 6 additions & 0 deletions crates/sui-indexer-alt-e2e-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]

// Empty src/lib.rs to get rusty-tags working.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
processed 2 tasks

task 1, lines 6-10:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 0,
"result": "1337"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 70 --simulator --objects-snapshot-min-checkpoint-lag 2 --reference-gas-price 1337

//# run-jsonrpc
{
"method": "suix_getReferenceGasPrice",
"params": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
processed 2 tasks

task 1, lines 6-10:
//# run-jsonrpc
Response: {
"jsonrpc": "2.0",
"id": 0,
"result": "1000"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 70 --simulator --objects-snapshot-min-checkpoint-lag 2

//# run-jsonrpc
{
"method": "suix_getReferenceGasPrice",
"params": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
processed 6 tasks

task 1, lines 19-22:
//# run-graphql
Error: GraphQL queries are not supported in these tests

task 2, line 24:
//# run-jsonrpc
Error: Missing JSON-RPC query

task 3, lines 26-29:
//# run-jsonrpc
Error: Failed to parse JSON-RPC query

task 4, lines 31-35:
//# run-jsonrpc
Error: Failed to parse JSON-RPC query

task 5, lines 37-41:
//# run-jsonrpc --show-headers
Headers: {
"content-type": "application/json; charset=utf-8",
"content-length": "40",
}

Response: {
"jsonrpc": "2.0",
"id": 0,
"result": "1000"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 70 --simulator --objects-snapshot-min-checkpoint-lag 2

// This test is checking details about the test runner:
//
// (1) It does not support GraphQL queries.
// (2) Tests will fail if the JSON-RPC query does not contian methods or
// params.
// - No JSON object.
// - Missing params.
// - Extra trailing comma (tricky!)
// (3) Displaying response headers is supported.
//
// The test description is at the top because the JSON does not have explicit
// syntax for comments.

//# run-graphql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be run-jsonrpc?
Also curious why it was possible to mix up? Should we error if it happens?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is as intended. We do error if you try to run the wrong kind of query, and in fact this is the test for that (see the comments above this line).

{
chainIdentifier
}

//# run-jsonrpc

//# run-jsonrpc
{
"method": "suix_getReferenceGasPrice"
}

//# run-jsonrpc
{
"method": "suix_getReferenceGasPrice",
"params": [],
}

//# run-jsonrpc --show-headers
{
"method": "suix_getReferenceGasPrice",
"params": []
}
Loading
Loading