Skip to content

⚙️ Ditto: Library to test and benchmark Starknet full nodes

Notifications You must be signed in to change notification settings

KasarLabs/ditto

Repository files navigation

⚙️ Ditto: Library to test and benchmark Starknet full nodes

A simple Rust RPC test utility for the Deoxys Starknet node.

Getting started

💡 Before you get started, make sure you have access to an active Deoxys and Pathfinder node.

For tests to work, you will need to specify an pathfinder api url and deoxys api url. These must be stored in ./unit_tests/secret.json.

⚠️ Make sure to never commit or share your api keys in ./unit_tests/secret.json.

secret.json format:

{
    "pathfinder": "pathfinder-node-url",
    "deoxys": "deoxys-node-url"
}

Writing unit tests

Unit tests should be written inside of ./unit_test/tests/, but nothing stops you from creating your own module. Just make sure to import the necessary dependencies, which are:

Guidelines

💡 You can find a module for common imports in `./unit_tests/tests/common.rs

  • Failure case tests should be prefixed with fail_, success tests should be prefixed with work_.

  • Test should be well documented, following Rustdoc guidelines.

  • Any recurring initialization logic should be extracted to ./unit_tests/src/fixtures.rs. See rstest for more information on how to create fixtures.

  • Any constants should be extracted to ./unit_tests/src/constants.rs, along with proper Rustdoc documentation. If the constant contains a block hash, transaction hash, or other Starknet hashed location, please include a link to the hash's page on StarkScan.

  • Try and test as many edge cases as possible. Ths mostly includes optional parameters. You can find a list of Starknet RPC call and their arguments / return data here

Example Test

./unit_tests/tests/test_block_number.rs

mod common;
use common::*;

use std::collections::HashMap;

use starknet_providers::{jsonrpc::{HttpTransport, JsonRpcClient}, Provider};

///
/// Unit test for `starknet_getBlockNumber`
/// 
/// purpose: get block number on latest block
/// success case: retrieve correct block number
/// 
#[rstest]
#[tokio::test]
async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
    let deoxys = &clients[mainnet::network::DEOXYS];
    let pathfinder = &clients[mainnet::network::PATHFINDER];

    let response_deoxys = deoxys.block_number().await.expect("Deoxys : Error while getting the block number");
    let response_pathfinder = pathfinder.block_number().await.expect("RPC : Error while getting the block number");

    assert_eq!(response_deoxys, response_pathfinder);
}

About

⚙️ Ditto: Library to test and benchmark Starknet full nodes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •