Skip to content

Commit

Permalink
Ignore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkawula committed Dec 13, 2024
1 parent 3ab3144 commit 49f8a90
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
155 changes: 155 additions & 0 deletions crates/forge/tests/integration/cheat_execution_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,161 @@ fn start_and_stop_cheat_transaction_hash_single_attribute() {
assert_passed(&result);
}

#[test]
#[ignore] // TODO(#2765)
#[allow(clippy::too_many_lines)]
fn start_cheat_execution_info_all_attributes_mocked() {
let test = test_case!(
indoc!(
r#"
use result::ResultTrait;
use option::OptionTrait;
use starknet::info::TxInfo;
use serde::Serde;
use traits::Into;
use starknet::ContractAddress;
use starknet::ContractAddressIntoFelt252;
use starknet::Felt252TryIntoContractAddress;
use array::SpanTrait;
use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, cheat_execution_info, ExecutionInfoMock, Operation, CheatArguments, CheatSpan};
use starknet::info::v2::ResourceBounds;
#[starknet::interface]
trait ICheatTxInfoChecker<TContractState> {
fn get_tx_hash(ref self: TContractState) -> felt252;
fn get_nonce(ref self: TContractState) -> felt252;
fn get_account_contract_address(ref self: TContractState) -> ContractAddress;
fn get_signature(ref self: TContractState) -> Span<felt252>;
fn get_version(ref self: TContractState) -> felt252;
fn get_max_fee(ref self: TContractState) -> u128;
fn get_chain_id(ref self: TContractState) -> felt252;
fn get_resource_bounds(ref self: TContractState) -> Span<ResourceBounds>;
fn get_tip(ref self: TContractState) -> u128;
fn get_paymaster_data(ref self: TContractState) -> Span<felt252>;
fn get_nonce_data_availability_mode(ref self: TContractState) -> u32;
fn get_fee_data_availability_mode(ref self: TContractState) -> u32;
fn get_account_deployment_data(ref self: TContractState) -> Span<felt252>;
}
#[test]
fn start_cheat_execution_info_all_attributes_mocked() {
let contract = declare("CheatTxInfoChecker").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap();
let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address };
let mut execution_info_mock: ExecutionInfoMock = Default::default();
execution_info_mock.tx_info.nonce = Operation::Start(CheatArguments {
value: 411,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.account_contract_address = Operation::Start(CheatArguments {
value: 422.try_into().unwrap(),
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.version = Operation::Start(CheatArguments {
value: 433,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.transaction_hash = Operation::Start(CheatArguments {
value: 444,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.chain_id = Operation::Start(CheatArguments {
value: 455,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.max_fee = Operation::Start(CheatArguments {
value: 466,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.signature = Operation::Start(CheatArguments {
value: array![477, 478].span(),
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.resource_bounds = Operation::Start(CheatArguments {
value: array![ResourceBounds { resource: 55, max_amount: 66, max_price_per_unit: 77 }, ResourceBounds { resource: 111, max_amount: 222, max_price_per_unit: 333 }].span(),
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.tip = Operation::Start(CheatArguments {
value: 123,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.paymaster_data = Operation::Start(CheatArguments {
value: array![22, 33, 44].span(),
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.nonce_data_availability_mode = Operation::Start(CheatArguments {
value: 99,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.fee_data_availability_mode = Operation::Start(CheatArguments {
value: 88,
target: contract_address,
span: CheatSpan::Indefinite
});
execution_info_mock.tx_info.account_deployment_data = Operation::Start(CheatArguments {
value: array![111, 222].span(),
target: contract_address,
span: CheatSpan::Indefinite
});
cheat_execution_info(execution_info_mock);
let nonce = dispatcher.get_nonce();
assert(nonce == 411, 'Invalid nonce');
let account_contract_address: felt252 = dispatcher.get_account_contract_address().into();
assert(account_contract_address == 422, 'Invalid account address');
let version = dispatcher.get_version();
assert(version == 433, 'Invalid version');
let transaction_hash = dispatcher.get_tx_hash();
assert(transaction_hash == 444, 'Invalid tx hash');
let chain_id = dispatcher.get_chain_id();
assert(chain_id == 455, 'Invalid chain_id');
let max_fee = dispatcher.get_max_fee();
assert(max_fee == 466_u128, 'Invalid max_fee');
let signature = dispatcher.get_signature();
assert(signature.len() == 2, 'Invalid signature len');
assert(*signature.at(0) == 477, 'Invalid signature el[0]');
assert(*signature.at(1) == 478, 'Invalid signature el[1]');
let resource_bounds = dispatcher.get_resource_bounds();
assert(resource_bounds.len() == 2, 'Invalid resource_bounds len');
assert(*resource_bounds.at(0).resource == 55, 'Invalid resource_bounds[0][0]');
assert(*resource_bounds.at(0).max_amount == 66, 'Invalid resource_bounds[0][1]');
assert(*resource_bounds.at(0).max_price_per_unit == 77, 'Invalid resource_bounds[0][2]');
assert(*resource_bounds.at(1).resource == 111, 'Invalid resource_bounds[1][0]');
assert(*resource_bounds.at(1).max_amount == 222, 'Invalid resource_bounds[1][1]');
assert(*resource_bounds.at(1).max_price_per_unit == 333, 'Invalid resource_bounds[1][2]');
let tip = dispatcher.get_tip();
assert(tip == 123, 'Invalid tip');
let paymaster_data = dispatcher.get_paymaster_data();
assert(paymaster_data == array![22, 33, 44].span(), 'Invalid paymaster_data');
let nonce_data_availability_mode = dispatcher.get_nonce_data_availability_mode();
assert(nonce_data_availability_mode == 99, 'Invalid nonce data');
let fee_data_availability_mode = dispatcher.get_fee_data_availability_mode();
assert(fee_data_availability_mode == 88, 'Invalid fee data');
let account_deployment_data = dispatcher.get_account_deployment_data();
assert(account_deployment_data == array![111, 222].span(), 'Invalid account deployment');
}
"#
),
Contract::from_code_path(
"CheatTxInfoChecker".to_string(),
Path::new("tests/data/contracts/cheat_tx_info_checker.cairo"),
)
.unwrap()
);

let result = run_test_case(&test);

assert_passed(&result);
}

#[test]
fn start_cheat_transaction_hash_cancel_mock_by_setting_attribute_to_none() {
let test = test_case!(
Expand Down
32 changes: 32 additions & 0 deletions crates/forge/tests/integration/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,35 @@ fn cairo_test_cheatcode_error() {
),
);
}


#[test]
#[ignore] // TODO(#2765)
fn cheatcode_invalid_args() {
let test = test_utils::test_case!(indoc!(
r"
use starknet::testing::cheatcode;
use snforge_std::_cheatcode::handle_cheatcode;
#[test]
fn cheatcode_invalid_args() {
handle_cheatcode(cheatcode::<'replace_bytecode'>(array![].span()));
assert(true,'');
}
"
));

let result = run_test_case(&test);

assert_case_output_contains(
&result,
"cheatcode_invalid_args",
indoc!(
r#"
"Reading from buffer failed, this can be caused by calling starknet::testing::cheatcode with invalid arguments.
Probably `snforge_std`/`sncast_std` version is incompatible, check above for incompatibility warning.
"
"#
),
);
assert_failed(&result);
}

0 comments on commit 49f8a90

Please sign in to comment.