sui_transactional_test_runner/
offchain_state.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use async_trait::async_trait;
use serde_json::Value;
use std::time::Duration;

pub struct TestResponse {
    pub response_body: String,
    pub http_headers: Option<http::HeaderMap>,
    pub service_version: Option<String>,
}

/// Trait for interacting with the offchain state of the Sui network. To reduce test flakiness,
/// these methods are used in the `RunGraphqlCommand` to stabilize the off-chain indexed state.
#[async_trait]
pub trait OffchainStateReader: Send + Sync + 'static {
    /// Polls the checkpoint table until the given checkpoint is committed.
    async fn wait_for_checkpoint_catchup(&self, checkpoint: u64, base_timeout: Duration);

    /// Polls the checkpoint table until the given checkpoint is pruned.
    async fn wait_for_pruned_checkpoint(&self, checkpoint: u64, base_timeout: Duration);

    /// Executes a GraphQL query and returns the response.
    async fn execute_graphql(
        &self,
        query: String,
        show_usage: bool,
    ) -> anyhow::Result<TestResponse>;

    /// Executes a JSON-RPC query and returns the response. The query is given as a method name,
    /// and a JSON value representing its parameters.
    async fn execute_jsonrpc(&self, method: String, params: Value) -> anyhow::Result<TestResponse>;
}