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

e2e tests: RPC read test cases #236

Merged
merged 17 commits into from
Sep 9, 2024
Merged

Conversation

Mohiiit
Copy link
Contributor

@Mohiiit Mohiiit commented Aug 26, 2024

PR includes tests for the all rpc read calls, in all cases we will be syncing a few blocks from the sepolia testnet and will make read calls and verify the information present in madara is right or not and whether the rpc calls are working fine or not.

For source of truth, I am using juno's data.

Pull Request type

  • Testing

What is the current behavior?

Resolves: #

What is the new behavior?

  • tests has been added in test directory under the rpc folder, plan is to add write test cases there as well in the future

Does this introduce a breaking change?

No

Progress

  • get block hash and block number
  • call (ignored)
  • estimate fee (ignored)
  • estimate message fee (ignored)
  • get block transaction count
  • get block with receipt
  • get block with transaction hashes
  • get block with transactions
  • get class
  • get class at
  • get class hash at
  • get state update
  • get nonce
  • get events
  • get storage at
  • get transaction by block id and index
  • get transaction by hash
  • get transaction receipt
  • get transaction status

@Mohiiit Mohiiit marked this pull request as ready for review August 29, 2024 11:04

static MADARA: Lazy<OnceCell<Arc<Mutex<MadaraCmd>>>> = Lazy::new(OnceCell::new);

async fn setup_madara() -> Arc<Mutex<MadaraCmd>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be a fixture. do we need Arc or Mutex? does a #[once] fixture autmatically handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

"0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
),
l1_gas_price: ResourcePrice {
price_in_fri: Felt::from_hex_unchecked("0x0"),
Copy link
Contributor

Choose a reason for hiding this comment

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

should we make Felt::from_hex_unchecked a macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

crates/tests/src/rpc/read.rs Show resolved Hide resolved
crates/tests/src/rpc/read.rs Show resolved Hide resolved
crates/tests/src/rpc/read.rs Show resolved Hide resolved
async fn test_get_block_txn_with_tx_works() {
let madara = get_shared_state().await;
let json_client = JsonRpcClient::new(HttpTransport::new(madara.rpc_url.clone()));
let block = { json_client.get_block_with_txs(BlockId::Number(2)).await.unwrap() };
Copy link
Member

Choose a reason for hiding this comment

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

fmt here, for braces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

madara.wait_for_ready().await;
madara.wait_for_sync_to(19).await;

// The lock is released when guard goes out of scope
Copy link
Member

Choose a reason for hiding this comment

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

i dont understand this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad, removed

"id": 1
}'

Note: The test is ignored as of now because madara doesn't support historical data retrieval.
Copy link
Member

Choose a reason for hiding this comment

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

We support historical data retrieval. We dont support it trough our bonsai trie. But all RPC endpoints are supported on latest (v0.7.1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, my bad what I meant was the calls with starknet version <0.13.0, this returns an error.

if block.info.protocol_version() < &FALLBACK_TO_SEQUENCER_WHEN_VERSION_BELOW {
        return Err(StarknetRpcApiError::UnsupportedTxnVersion);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the comment

"id": 1
}'

Note: The test is ignored as of now because madara doesn't support historical data retrieval.
Copy link
Member

Choose a reason for hiding this comment

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

same here

"id": 1
}'

Note: The test is ignored as of now because madara doesn't support historical data retrieval.
Copy link
Member

Choose a reason for hiding this comment

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

same here

assert_eq!(block, expected_block);
}

/*
Copy link
Member

Choose a reason for hiding this comment

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

I would rather comment doc using /// since we are doing it this way all over the codebase:

/// Sends a request to fetch the latest block with transactions.
/// 
/// Example curl command:
/// 
/// ```bash
/// curl --location 'https://free-rpc.nethermind.io/sepolia-juno/' \
/// --header 'Content-Type: application/json' \
/// --data '{
///     "jsonrpc": "2.0",
///     "method": "starknet_getBlockWithTxs",
///     "params": {
///         "block_id": "latest"
///     },
///     "id": 1
/// }'
/// ```

Copy link
Member

Choose a reason for hiding this comment

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

Also I would avoid referencing https://free-rpc.nethermind.io/sepolia-juno/ and replace it with a madara public rpc (we have this one here https://rpc.kasar.io/deoxys)

Copy link
Member

Choose a reason for hiding this comment

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

actually it is on mainnet

Copy link
Member

Choose a reason for hiding this comment

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

so lets rely on nethermind for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

documentation updated

@antiyro antiyro merged commit d186cc7 into madara-alliance:main Sep 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants