This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(concurrency): add unitests for concurrency fee transfer
- Loading branch information
1 parent
7be4d53
commit 9ae663f
Showing
7 changed files
with
163 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod fee_utils; | ||
pub mod scheduler; | ||
#[cfg(any(feature = "testing", test))] | ||
pub mod test_utils; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use starknet_api::hash::StarkFelt; | ||
|
||
use crate::execution::call_info::CallInfo; | ||
#[cfg(test)] | ||
#[path = "fee_utils_test.rs"] | ||
mod test; | ||
|
||
// We read account balance (sender), and sequencer balance (recipient). The balance is of type | ||
// `Uint256`, consist of two felts (lsb, msb). Hence, storage read values = | ||
// [account_balance, 0, sequencer_balance, 0] | ||
const STORAGE_READ_SEQUENCER_BALANCE_INDICES: (usize, usize) = (2, 3); | ||
|
||
// Completes the fee transfer execution by fixing the call info to have the correct sequencer | ||
// balance. In concurrency mode, the fee transfer is executed with a false (constant) sequencer | ||
// balance. This affects the call info. | ||
pub fn fill_sequencer_balance_reads( | ||
fee_transfer_call_info: &mut CallInfo, | ||
sequencer_balance_low: StarkFelt, | ||
sequencer_balance_high: StarkFelt, | ||
) { | ||
let storage_read_values = &mut fee_transfer_call_info.storage_read_values; | ||
assert_eq!(storage_read_values.len(), 4, "Storage read values should have 4 elements"); | ||
|
||
let (low_index, high_index) = STORAGE_READ_SEQUENCER_BALANCE_INDICES; | ||
for index in [low_index, high_index] { | ||
assert_eq!(storage_read_values[index], StarkFelt::ZERO, "Sequencer balance should be zero"); | ||
} | ||
storage_read_values[low_index] = sequencer_balance_low; | ||
storage_read_values[high_index] = sequencer_balance_high; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use rstest::rstest; | ||
use starknet_api::hash::StarkFelt; | ||
use starknet_api::transaction::TransactionVersion; | ||
|
||
use crate::concurrency::fee_utils::fill_sequencer_balance_reads; | ||
use crate::concurrency::test_utils::create_fee_transfer_call_info; | ||
use crate::context::BlockContext; | ||
use crate::invoke_tx_args; | ||
use crate::test_utils::contracts::FeatureContract; | ||
use crate::test_utils::initial_test_state::{fund_account, test_state}; | ||
use crate::test_utils::{ | ||
create_trivial_calldata, CairoVersion, BALANCE, MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE, | ||
}; | ||
use crate::transaction::test_utils::{account_invoke_tx, block_context, l1_resource_bounds}; | ||
|
||
#[rstest] | ||
pub fn test_fill_sequencer_balance_reads(block_context: BlockContext) { | ||
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1); | ||
let account_tx = account_invoke_tx(invoke_tx_args! { | ||
sender_address: account.get_instance_address(0), | ||
calldata: create_trivial_calldata(account.get_instance_address(0)), | ||
resource_bounds: l1_resource_bounds(MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE), | ||
version: TransactionVersion::THREE | ||
}); | ||
let chain_info = &block_context.chain_info; | ||
let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]); | ||
|
||
let sequencer_balance = 100; | ||
let sequencer_address = block_context.block_info.sequencer_address; | ||
fund_account(chain_info, sequencer_address, sequencer_balance, &mut state.state); | ||
|
||
let mut concurrency_call_info = create_fee_transfer_call_info(state, &account_tx, true); | ||
let call_info = create_fee_transfer_call_info(state, &account_tx, false); | ||
|
||
assert_ne!(concurrency_call_info, call_info); | ||
|
||
fill_sequencer_balance_reads( | ||
&mut concurrency_call_info, | ||
StarkFelt::from(sequencer_balance), | ||
StarkFelt::ZERO, | ||
); | ||
|
||
assert_eq!(concurrency_call_info, call_info); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters