Skip to content

Commit

Permalink
Test/529 00 starknet/mod.rs (#544)
Browse files Browse the repository at this point in the history
* starknet_get_nonce test formatted

* test: starknet_get_Nnocence
  • Loading branch information
somthn0somthn authored Sep 28, 2023
1 parent 9fbb0a8 commit ddcf8e4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
23 changes: 23 additions & 0 deletions crates/beerus-core/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ pub fn mock_get_storage_at(server: &MockServer) -> Mock {
})
}

pub fn mock_get_nonce(server: &MockServer) -> Mock {
server.mock(|when, then| {
when.method(POST).path("/").json_body(json!({
"id":1,
"jsonrpc":"2.0",
"method":"starknet_getNonce",
"params":[
{
"block_number": 1
},
"0x0"
]
}));
then.status(200)
.header("content-type", "application/json")
.json_body(json!({
"jsonrpc": "2.0",
"id": 1,
"result": "0x0000000000000000000000000000000000000000000000000000000000000001"
}));
})
}

pub fn mock_call(server: &MockServer) -> Mock {
server.mock(|when, then| {
when.method(POST).path("/").json_body(json!({
Expand Down
34 changes: 33 additions & 1 deletion crates/beerus-core/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![cfg(not(target_arch = "wasm32"))]

pub mod common;
use common::{mock_call, mock_get_contract_storage_proof, mock_get_storage_at, mock_server_config};
use common::{
mock_call, mock_get_contract_storage_proof, mock_get_nonce, mock_get_storage_at,
mock_server_config,
};

#[cfg(test)]
mod test {
Expand Down Expand Up @@ -92,6 +95,35 @@ mod test {
);
}

#[tokio::test]
async fn given_normal_conditions_when_starknet_get_nonce_should_work() {
// Start a lightweight mock server.
let server = MockServer::start();
let mock_request = mock_get_nonce(&server);
let config = mock_server_config(&server);

let starknet_lightclient = Box::new(StarkNetLightClientImpl::new(&config).unwrap());
let mut helios_lightclient = MockEthereumLightClient::new();

helios_lightclient
.expect_starknet_last_proven_block()
.return_once(move || Ok(U256::from(1)));
let beerus = BeerusLightClient::new_from_clients(
config,
Box::new(helios_lightclient),
starknet_lightclient,
);

let block_id = BlockId::Number(1);
let storage_var = beerus
.starknet_get_nonce(FieldElement::from_str("0x00").unwrap(), &block_id)
.await
.unwrap();

mock_request.assert();
assert_eq!(storage_var, FieldElement::from_str("0x01").unwrap());
}

#[tokio::test]
async fn given_normal_conditions_when_starknet_call_should_work() {
// Start a lightweight mock server.
Expand Down

0 comments on commit ddcf8e4

Please sign in to comment.