KasarLabs / ditto

⚙️ Ditto: Library to test and benchmark Starknet full nodes
https://kasar.io
7 stars 6 forks source link

[![Project license](https://img.shields.io/github/license/kasarLabs/ditto.svg?style=flat-square)](LICENSE) [![Pull Requests welcome](https://img.shields.io/badge/PRs-welcome-ff69b4.svg?style=flat-square)](https://github.com/kasarLabs/ditto/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)

⚙️ 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

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);
}