Skip to content

Commit

Permalink
Merge pull request #64 from KasarLabs/feat/block_versions
Browse files Browse the repository at this point in the history
block versions
  • Loading branch information
antiyro committed Jun 17, 2024
2 parents 79fabe4 + 967f8e8 commit a0462ab
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 33 deletions.
28 changes: 24 additions & 4 deletions unit_tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ pub const TRANSACTION_REVERTED: &str =
pub const ACCOUNT_CONTRACT: &str = "";
pub const TEST_CONTRACT_ADDRESS: &str = "";
pub const CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH: &str = "";
pub const TEST_CONTRACT_CLASS_HASH_V0: &str = "0x036e5b6081df2174189fb83800d2a09132286dcd1004ad960a0c8d69364e6e9a";
pub const TEST_CONTRACT_CLASS_HASH_V1: &str = "0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003";
pub const TEST_CONTRACT_CLASS_HASH_V0: &str =
"0x036e5b6081df2174189fb83800d2a09132286dcd1004ad960a0c8d69364e6e9a";
pub const TEST_CONTRACT_CLASS_HASH_V1: &str =
"0x01a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003";

///
/// Value to be used as a payload for a message in the `estimate_message_fee` test.
Expand All @@ -161,7 +163,25 @@ pub const ARGENT_CONTRACT_ADDRESS: &str = "";
pub const ERR_DEOXYS: &str = "Error waiting for response from Deoxys client";
pub const ERR_PATHFINDER: &str = "Error waiting for response from Pathfinder client";

pub const SPEC_0_5_1: &str = "0.5.1";
pub const SPEC_0_6_0: &str = "0.6.0";
pub const SPEC_0_7_0: &str = "0.7.0";
pub const SPEC_0_7_1: &str = "0.7.1";

///
/// Starknet block number versions.
///
pub const BLOCK_0: u64 = 0;
pub const BLOCK_0_9_1: u64 = 3799;
pub const BLOCK_0_10_0: u64 = 4883;
pub const BLOCK_0_10_1: u64 = 6570;
pub const BLOCK_0_10_2: u64 = 12268;
pub const BLOCK_0_10_3: u64 = 16575;
pub const BLOCK_0_11_0: u64 = 28613;
pub const BLOCK_0_11_0_2: u64 = 43851;
pub const BLOCK_0_11_1: u64 = 61394;
pub const BLOCK_0_11_2: u64 = 68096;
pub const BLOCK_0_12_0: u64 = 103129;
pub const BLOCK_0_12_1: u64 = 164901;
pub const BLOCK_0_12_2: u64 = 194410;
pub const BLOCK_0_12_3: u64 = 472644;
pub const BLOCK_0_13_0: u64 = 501514;
pub const BLOCK_0_13_1: u64 = 607878;
33 changes: 21 additions & 12 deletions unit_tests/tests/test_get_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ use std::collections::HashMap;

#[rstest]
#[tokio::test]
async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTransport>>) -> Result<()> {
async fn fail_non_existing_block(
clients: HashMap<String, JsonRpcClient<HttpTransport>>,
) -> Result<()> {
let deoxys = &clients[DEOXYS];

let test_contract_class_hash =
FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0).map_err(|e| anyhow!("Invalid Contract Class Hash: {}", e))?;
let test_contract_class_hash = FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0)
.map_err(|e| anyhow!("Invalid Contract Class Hash: {}", e))?;
let block_id = BlockId::Number(800000);

match deoxys.get_class(block_id, test_contract_class_hash).await {
Expand All @@ -26,7 +28,7 @@ async fn fail_non_existing_block(clients: HashMap<String, JsonRpcClient<HttpTran
} else {
panic!("Unexpected error: {:?}", e);
}
},
}
Ok(_) => panic!("Unexpected success: Class was found when it shouldn't be."),
}
}
Expand Down Expand Up @@ -69,8 +71,8 @@ async fn work_ok_retrieving_class_for_contract_version_0(
let deoxys = &clients[DEOXYS];
let pathfinder = &clients[PATHFINDER];

let test_contract_class_hash =
FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0).expect("Invalid Contract Class Hash");
let test_contract_class_hash = FieldElement::from_hex_be(TEST_CONTRACT_CLASS_HASH_V0)
.expect("Invalid Contract Class Hash");

let deoxys_class = deoxys
.get_class(BlockId::Number(50000), test_contract_class_hash)
Expand All @@ -82,13 +84,20 @@ async fn work_ok_retrieving_class_for_contract_version_0(
.await
.unwrap();

if let (ContractClass::Legacy(deoxys_legacy), ContractClass::Legacy(pathfinder_legacy)) = (deoxys_class, pathfinder_class) {
assert_eq!(deoxys_legacy.entry_points_by_type, pathfinder_legacy.entry_points_by_type);
if let (ContractClass::Legacy(deoxys_legacy), ContractClass::Legacy(pathfinder_legacy)) =
(deoxys_class, pathfinder_class)
{
assert_eq!(
deoxys_legacy.entry_points_by_type,
pathfinder_legacy.entry_points_by_type
);
assert_eq!(deoxys_legacy.abi, pathfinder_legacy.abi);

let deoxys_program = decode(&deoxys_legacy.program).expect("Failed to decode base64 program");
let pathfinder_program = decode(&pathfinder_legacy.program).expect("Failed to decode base64 program");


let deoxys_program =
decode(&deoxys_legacy.program).expect("Failed to decode base64 program");
let pathfinder_program =
decode(&pathfinder_legacy.program).expect("Failed to decode base64 program");

assert_eq!(deoxys_program, pathfinder_program);
} else {
panic!("Contract classes are not of the Legacy variant");
Expand Down
83 changes: 66 additions & 17 deletions unit_tests/tests/test_get_state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
mod common;
use common::*;

use starknet_core::types::{BlockId, BlockTag, MaybePendingStateUpdate, StarknetError, StateUpdate};
use starknet_core::types::{
BlockId, BlockTag, MaybePendingStateUpdate, StarknetError, StateUpdate,
};
use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider};
use std::collections::HashMap;

Expand All @@ -27,7 +29,9 @@ pub fn sort_state_update(state_update: StateUpdate) -> StateUpdate {
state_diff.deprecated_declared_classes.sort();
state_diff.declared_classes.sort_by_key(|x| x.class_hash);
state_diff.deployed_contracts.sort_by_key(|x| x.address);
state_diff.replaced_classes.sort_by_key(|x| x.contract_address);
state_diff
.replaced_classes
.sort_by_key(|x| x.contract_address);
state_diff.nonces.sort_by_key(|x| x.contract_address);

sorted_state_update
Expand Down Expand Up @@ -93,9 +97,18 @@ async fn work_genesis_block(clients: HashMap<String, JsonRpcClient<HttpTransport
let sorted_pathfinder = extract_and_sort_state_update(response_pathfinder);
let sorted_juno = extract_and_sort_state_update(response_juno);

assert_eq!(sorted_deoxys, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(sorted_deoxys, sorted_juno, "The sorted responses do not match");
assert_eq!(sorted_juno, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(
sorted_deoxys, sorted_pathfinder,
"The sorted responses do not match"
);
assert_eq!(
sorted_deoxys, sorted_juno,
"The sorted responses do not match"
);
assert_eq!(
sorted_juno, sorted_pathfinder,
"The sorted responses do not match"
);
}

#[rstest]
Expand Down Expand Up @@ -125,9 +138,18 @@ async fn work_existing_block(clients: HashMap<String, JsonRpcClient<HttpTranspor
let sorted_pathfinder = extract_and_sort_state_update(response_pathfinder);
let sorted_juno = extract_and_sort_state_update(response_juno);

assert_eq!(sorted_deoxys, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(sorted_deoxys, sorted_juno, "The sorted responses do not match");
assert_eq!(sorted_juno, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(
sorted_deoxys, sorted_pathfinder,
"The sorted responses do not match"
);
assert_eq!(
sorted_deoxys, sorted_juno,
"The sorted responses do not match"
);
assert_eq!(
sorted_juno, sorted_pathfinder,
"The sorted responses do not match"
);
}

#[rstest]
Expand Down Expand Up @@ -157,9 +179,18 @@ async fn work_loop_existing_block(clients: HashMap<String, JsonRpcClient<HttpTra
let sorted_pathfinder = extract_and_sort_state_update(response_pathfinder);
let sorted_juno = extract_and_sort_state_update(response_juno);

assert_eq!(sorted_deoxys, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(sorted_deoxys, sorted_juno, "The sorted responses do not match");
assert_eq!(sorted_juno, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(
sorted_deoxys, sorted_pathfinder,
"The sorted responses do not match"
);
assert_eq!(
sorted_deoxys, sorted_juno,
"The sorted responses do not match"
);
assert_eq!(
sorted_juno, sorted_pathfinder,
"The sorted responses do not match"
);
}
}

Expand Down Expand Up @@ -190,9 +221,18 @@ async fn work_block_pending(clients: HashMap<String, JsonRpcClient<HttpTransport
let sorted_pathfinder = extract_and_sort_state_update(response_pathfinder);
let sorted_juno = extract_and_sort_state_update(response_juno);

assert_eq!(sorted_deoxys, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(sorted_deoxys, sorted_juno, "The sorted responses do not match");
assert_eq!(sorted_juno, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(
sorted_deoxys, sorted_pathfinder,
"The sorted responses do not match"
);
assert_eq!(
sorted_deoxys, sorted_juno,
"The sorted responses do not match"
);
assert_eq!(
sorted_juno, sorted_pathfinder,
"The sorted responses do not match"
);
}

#[rstest]
Expand Down Expand Up @@ -221,7 +261,16 @@ async fn work_block_latest(clients: HashMap<String, JsonRpcClient<HttpTransport>
let sorted_pathfinder = extract_and_sort_state_update(response_pathfinder);
let sorted_juno = extract_and_sort_state_update(response_juno);

assert_eq!(sorted_deoxys, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(sorted_deoxys, sorted_juno, "The sorted responses do not match");
assert_eq!(sorted_juno, sorted_pathfinder, "The sorted responses do not match");
assert_eq!(
sorted_deoxys, sorted_pathfinder,
"The sorted responses do not match"
);
assert_eq!(
sorted_deoxys, sorted_juno,
"The sorted responses do not match"
);
assert_eq!(
sorted_juno, sorted_pathfinder,
"The sorted responses do not match"
);
}

0 comments on commit a0462ab

Please sign in to comment.