Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
test(rpc): disable state_diff work (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro authored Feb 21, 2024
1 parent 8c498ea commit 66c1d13
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 85 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- test(rpc): disable state_diff tests
- feat(rpc): add tests for estimateMessageFee RPC call
- refacto: rename braavos call aggregator contract
- fix: updating outdated links to external resources in documentation
Expand Down
172 changes: 87 additions & 85 deletions starknet-rpc-test/get_state_update.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
extern crate starknet_rpc_test;

use anyhow::anyhow;
use assert_matches::assert_matches;
use rstest::rstest;
use starknet_core::types::{BlockId, BlockTag, DeclaredClassItem, MaybePendingStateUpdate, NonceUpdate, StarknetError};
use starknet_core::types::{BlockId, StarknetError};
use starknet_ff::FieldElement;
use starknet_providers::ProviderError::StarknetError as StarknetProviderError;
use starknet_providers::{MaybeUnknownErrorCode, Provider, StarknetErrorWithMessage};
use starknet_rpc_test::constants::{ARGENT_CONTRACT_ADDRESS, SIGNER_PRIVATE};
use starknet_rpc_test::fixtures::{madara, ThreadSafeMadaraClient};
use starknet_rpc_test::utils::{build_single_owner_account, AccountActions};
use starknet_rpc_test::Transaction;

#[rstest]
#[tokio::test]
Expand All @@ -29,83 +25,89 @@ async fn fail_non_existing_block(madara: &ThreadSafeMadaraClient) -> Result<(),
Ok(())
}

#[rstest]
#[tokio::test]
async fn returns_correct_state_diff_transfer(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

let recipient = FieldElement::from_hex_be("0x1234").unwrap();
let sender_account_address = FieldElement::from_hex_be(ARGENT_CONTRACT_ADDRESS).expect("Invalid Contract Address");

let (state_update, block_hash, new_nonce) = {
let mut madara_write_lock = madara.write().await;
let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);

madara_write_lock
.create_block_with_txs(vec![Transaction::Execution(account.transfer_tokens(
recipient,
FieldElement::ONE,
None,
))])
.await?;

let state_update = match rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() {
MaybePendingStateUpdate::Update(update) => update,
MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending update")),
};
let block_hash_and_number = rpc.block_hash_and_number().await?;
let new_nonce = rpc.get_nonce(BlockId::Tag(BlockTag::Latest), sender_account_address).await?;

(state_update, block_hash_and_number.block_hash, new_nonce)
};

assert_eq!(state_update.block_hash, block_hash);
assert_eq!(state_update.old_root, FieldElement::ZERO);
assert_eq!(state_update.new_root, FieldElement::ZERO);

assert_eq!(state_update.state_diff.nonces.len(), 1);
assert_eq!(
state_update.state_diff.nonces[0],
NonceUpdate { contract_address: sender_account_address, nonce: new_nonce }
);

Ok(())
}

#[rstest]
#[tokio::test]
async fn returns_correct_state_diff_declare(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);
let (declare_tx, expected_class_hash, expected_compiled_class_hash) = account.declare_contract(
"./contracts/counter6/counter6.contract_class.json",
"./contracts/counter6/counter6.compiled_contract_class.json",
);

let (state_update, block_hash) = {
let mut madara_write_lock = madara.write().await;

madara_write_lock.create_block_with_txs(vec![Transaction::Declaration(declare_tx)]).await?;

let state_update = match rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() {
MaybePendingStateUpdate::Update(update) => update,
MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending update")),
};
let block_hash_and_number = rpc.block_hash_and_number().await?;

(state_update, block_hash_and_number.block_hash)
};

assert_eq!(state_update.block_hash, block_hash);
assert_eq!(state_update.old_root, FieldElement::ZERO);
assert_eq!(state_update.new_root, FieldElement::ZERO);

assert_eq!(state_update.state_diff.declared_classes.len(), 1);
assert_eq!(
state_update.state_diff.declared_classes[0],
DeclaredClassItem { class_hash: expected_class_hash, compiled_class_hash: expected_compiled_class_hash }
);

Ok(())
}
// #[rstest]
// #[tokio::test]
// async fn returns_correct_state_diff_transfer(madara: &ThreadSafeMadaraClient) -> Result<(),
// anyhow::Error> { let rpc = madara.get_starknet_client().await;

// let recipient = FieldElement::from_hex_be("0x1234").unwrap();
// let sender_account_address =
// FieldElement::from_hex_be(ARGENT_CONTRACT_ADDRESS).expect("Invalid Contract Address");

// let (state_update, block_hash, new_nonce) = {
// let mut madara_write_lock = madara.write().await;
// let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS,
// true);

// madara_write_lock
// .create_block_with_txs(vec![Transaction::Execution(account.transfer_tokens(
// recipient,
// FieldElement::ONE,
// None,
// ))])
// .await?;

// let state_update = match
// rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() {
// MaybePendingStateUpdate::Update(update) => update,
// MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending
// update")), };
// let block_hash_and_number = rpc.block_hash_and_number().await?;
// let new_nonce = rpc.get_nonce(BlockId::Tag(BlockTag::Latest),
// sender_account_address).await?;

// (state_update, block_hash_and_number.block_hash, new_nonce)
// };

// assert_eq!(state_update.block_hash, block_hash);
// assert_eq!(state_update.old_root, FieldElement::ZERO);
// assert_eq!(state_update.new_root, FieldElement::ZERO);

// assert_eq!(state_update.state_diff.nonces.len(), 1);
// assert_eq!(
// state_update.state_diff.nonces[0],
// NonceUpdate { contract_address: sender_account_address, nonce: new_nonce }
// );

// Ok(())
// }

// #[rstest]
// #[tokio::test]
// async fn returns_correct_state_diff_declare(madara: &ThreadSafeMadaraClient) -> Result<(),
// anyhow::Error> { let rpc = madara.get_starknet_client().await;

// let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS,
// true); let (declare_tx, expected_class_hash, expected_compiled_class_hash) =
// account.declare_contract( "./contracts/counter6/counter6.contract_class.json",
// "./contracts/counter6/counter6.compiled_contract_class.json",
// );

// let (state_update, block_hash) = {
// let mut madara_write_lock = madara.write().await;

// madara_write_lock.create_block_with_txs(vec![Transaction::Declaration(declare_tx)]).
// await?;

// let state_update = match
// rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() {
// MaybePendingStateUpdate::Update(update) => update,
// MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending
// update")), };
// let block_hash_and_number = rpc.block_hash_and_number().await?;

// (state_update, block_hash_and_number.block_hash)
// };

// assert_eq!(state_update.block_hash, block_hash);
// assert_eq!(state_update.old_root, FieldElement::ZERO);
// assert_eq!(state_update.new_root, FieldElement::ZERO);

// assert_eq!(state_update.state_diff.declared_classes.len(), 1);
// assert_eq!(
// state_update.state_diff.declared_classes[0],
// DeclaredClassItem { class_hash: expected_class_hash, compiled_class_hash:
// expected_compiled_class_hash } );

// Ok(())
// }

0 comments on commit 66c1d13

Please sign in to comment.