Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Sep 30, 2024
1 parent eb8c75f commit b4b7f26
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions crates/katana/rpc/rpc/tests/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,13 @@ async fn trace() -> Result<()> {
let recipient = felt!("0x1");
let amount = Uint256 { low: felt!("0x1"), high: Felt::ZERO };

let res = contract.transfer(&recipient, &amount).send().await?;
dojo_utils::TransactionWaiter::new(res.transaction_hash, &provider).await?;
for _ in 0..2 {
let res = contract.transfer(&recipient, &amount).send().await?;
dojo_utils::TransactionWaiter::new(res.transaction_hash, &provider).await?;

let trace = provider.trace_transaction(res.transaction_hash).await?;
assert_matches!(trace, TransactionTrace::Invoke(_));
let trace = provider.trace_transaction(res.transaction_hash).await?;
assert_matches!(trace, TransactionTrace::Invoke(_));
}

Ok(())
}
Expand All @@ -794,22 +796,24 @@ async fn block_traces() -> Result<()> {

// setup contract to interact with (can be any existing contract that can be interacted with)
let contract = Erc20Contract::new(DEFAULT_FEE_TOKEN_ADDRESS.into(), &account);
let rpc_client = HttpClientBuilder::default().build(sequencer.url())?;

// setup contract function params
let recipient = felt!("0x1");
let amount = Uint256 { low: felt!("0x1"), high: Felt::ZERO };

// -----------------------------------------------------------------------
// Block 1

let mut hashes = Vec::new();
for _ in 0..5 {
let res = contract.transfer(&recipient, &amount).send().await?;
dojo_utils::TransactionWaiter::new(res.transaction_hash, &provider).await?;
hashes.push(res.transaction_hash);
}

let client = HttpClientBuilder::default().build(sequencer.url())?;

// Generate a block to include the transactions. The generated block will have block number 1.
client.generate_block().await?;
rpc_client.generate_block().await?;

// Get the traces of the transactions in block 1.
let traces = provider.trace_block_transactions(BlockId::Number(1)).await?;
Expand All @@ -820,5 +824,27 @@ async fn block_traces() -> Result<()> {
assert_matches!(&traces[i].trace_root, TransactionTrace::Invoke(_));
}

// -----------------------------------------------------------------------
// Block 2

let mut hashes = Vec::new();
for _ in 0..2 {
let res = contract.transfer(&recipient, &amount).send().await?;
dojo_utils::TransactionWaiter::new(res.transaction_hash, &provider).await?;
hashes.push(res.transaction_hash);
}

// Generate a block to include the transactions. The generated block will have block number 2.
rpc_client.generate_block().await?;

// Get the traces of the transactions in block 2.
let traces = provider.trace_block_transactions(BlockId::Number(2)).await?;
assert_eq!(traces.len(), 2);

for i in 0..2 {
assert_eq!(traces[i].transaction_hash, hashes[i]);
assert_matches!(&traces[i].trace_root, TransactionTrace::Invoke(_));
}

Ok(())
}

0 comments on commit b4b7f26

Please sign in to comment.