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

Commit

Permalink
deleting tests for aregnt and braavos wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerson2102 committed May 28, 2024
1 parent 91127b7 commit b4e7162
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 148 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
- feat: Remove generic hasher from block hash computation
- refacto: git submodules removed
- test: Add pallet test for transaction declare V0
- test: Adding tests for txv3
- test: Deleting tests for wallets

## v0.7.0

Expand Down
78 changes: 2 additions & 76 deletions crates/pallets/starknet/src/tests/invoke_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ use super::utils::{
use crate::tests::constants::{UDC_ADDRESS, UDC_SELECTOR};
use crate::tests::{
get_invoke_argent_dummy, get_invoke_braavos_dummy, get_invoke_dummy, get_invoke_emit_event_dummy,
get_invoke_nonce_dummy, get_invoke_openzeppelin_dummy, get_invoke_v3_argent_dummy, get_invoke_v3_braavos_dummy,
get_invoke_v3_dummy, get_invoke_v3_openzeppelin_dummy, get_storage_read_write_dummy, set_infinite_tokens,
set_nonce,
get_invoke_nonce_dummy, get_invoke_openzeppelin_dummy, get_invoke_v3_dummy, get_invoke_v3_openzeppelin_dummy,
get_storage_read_write_dummy, set_infinite_tokens, set_nonce,
};
use crate::{Call, Error, StorageView};

Expand Down Expand Up @@ -929,22 +928,6 @@ fn given_hardcoded_contract_run_invoke_tx_v3_fails_sender_not_deployed() {
})
}

#[test]
fn given_hardcoded_contract_run_invoke_tx_v3_on_argent_account_then_it_works() {
new_test_ext::<MockRuntime>().execute_with(|| {
basic_test_setup(2);
let none_origin = RuntimeOrigin::none();
// NOT WORKING
let chain_id = Starknet::chain_id();
let mut transaction = get_invoke_v3_argent_dummy(chain_id);
if let starknet_api::transaction::InvokeTransaction::V3(tx) = &mut transaction.tx {
tx.signature = sign_message_hash(transaction.tx_hash);
};

assert_ok!(Starknet::invoke(none_origin, transaction));
});
}

#[test]
fn given_hardcoded_contract_run_invoke_tx_v3_on_openzeppelin_account_then_it_works() {
new_test_ext::<MockRuntime>().execute_with(|| {
Expand All @@ -957,63 +940,6 @@ fn given_hardcoded_contract_run_invoke_tx_v3_on_openzeppelin_account_then_it_wor
});
}

#[test]
fn given_hardcoded_contract_run_invoke_tx_v3_on_argent_account_with_incorrect_signature_then_it_fails() {
new_test_ext::<MockRuntime>().execute_with(|| {
basic_test_setup(2);
let none_origin = RuntimeOrigin::none();

let mut transaction = get_invoke_v3_argent_dummy(Starknet::chain_id());
if let starknet_api::transaction::InvokeTransaction::V3(tx) = &mut transaction.tx {
tx.signature = TransactionSignature(vec![StarkFelt::ONE, StarkFelt::ONE]);
};

let validate_result = Starknet::validate_unsigned(
TransactionSource::InBlock,
&crate::Call::invoke { transaction: transaction.clone() },
);
assert!(matches!(validate_result.unwrap_err(), TransactionValidityError::Invalid(_)));

assert_err!(Starknet::invoke(none_origin, transaction), Error::<MockRuntime>::TransactionExecutionFailed);
});
}

#[test]
fn given_hardcoded_contract_run_invoke_tx_v3_on_braavos_account_then_it_works() {
new_test_ext::<MockRuntime>().execute_with(|| {
basic_test_setup(2);
let none_origin = RuntimeOrigin::none();
// NOT WORKING
let mut transaction = get_invoke_v3_braavos_dummy(Starknet::chain_id());
if let starknet_api::transaction::InvokeTransaction::V3(tx) = &mut transaction.tx {
tx.signature = sign_message_hash(transaction.tx_hash);
};

assert_ok!(Starknet::invoke(none_origin, transaction));
});
}

#[test]
fn given_hardcoded_contract_run_invoke_tx_v3_on_braavos_account_with_incorrect_signature_then_it_fails() {
new_test_ext::<MockRuntime>().execute_with(|| {
basic_test_setup(2);
let none_origin = RuntimeOrigin::none();

let mut transaction = get_invoke_v3_braavos_dummy(Starknet::chain_id());
if let starknet_api::transaction::InvokeTransaction::V3(tx) = &mut transaction.tx {
tx.signature = TransactionSignature(vec![StarkFelt::ONE, StarkFelt::ONE]);
};

let validate_result = Starknet::validate_unsigned(
TransactionSource::InBlock,
&crate::Call::invoke { transaction: transaction.clone() },
);
assert!(matches!(validate_result.unwrap_err(), TransactionValidityError::Invalid(_)));

assert_err!(Starknet::invoke(none_origin, transaction), Error::<MockRuntime>::TransactionExecutionFailed);
});
}

#[test]
fn given_hardcoded_contract_run_invoke_tx_v3_with_inner_call_in_validate_then_it_fails() {
new_test_ext::<MockRuntime>().execute_with(|| {
Expand Down
71 changes: 0 additions & 71 deletions crates/pallets/starknet/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,40 +144,6 @@ fn get_invoke_argent_dummy(chain_id: Felt252Wrapper) -> blockifier::transaction:
blockifier::transaction::transactions::InvokeTransaction { tx, tx_hash, only_query: false }
}

fn get_invoke_v3_argent_dummy(chain_id: Felt252Wrapper) -> blockifier::transaction::transactions::InvokeTransaction {
let sender_address = ContractAddress(PatriciaKey(
StarkFelt::try_from("0x02e63de215f650e9d7e2313c6e9ed26b4f920606fb08576b1663c21a7c4a28c5").unwrap(),
));
let nonce = Nonce(StarkFelt::ZERO);
let signature = TransactionSignature::default();
let calldata = Calldata(Arc::new(vec![
StarkFelt::try_from("0x1").unwrap(), // call_array_len
StarkFelt::try_from("0x024d1e355f6b9d27a5a420c8f4b50cea9154a8e34ad30fc39d7c98d3c177d0d7").unwrap(), // to
StarkFelt::try_from("0x00e7def693d16806ca2a2f398d8de5951344663ba77f340ed7a958da731872fc").unwrap(), // selector
StarkFelt::try_from("0x0").unwrap(), // data_offset
StarkFelt::try_from("0x1").unwrap(), // data_len
StarkFelt::try_from("0x1").unwrap(), // calldata_len
StarkFelt::try_from("0x19").unwrap(), // calldata[0]
]));

let tx = starknet_api::transaction::InvokeTransaction::V3(starknet_api::transaction::InvokeTransactionV3 {
resource_bounds: create_resource_bounds(),
tip: starknet_api::transaction::Tip::default(),
calldata,
sender_address,
nonce,
signature,
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
paymaster_data: starknet_api::transaction::PaymasterData(vec![]),
account_deployment_data: starknet_api::transaction::AccountDeploymentData(vec![]),
});

let tx_hash = tx.compute_hash(chain_id, false);

blockifier::transaction::transactions::InvokeTransaction { tx, tx_hash, only_query: false }
}

// ref: https://github.com/myBraavos/braavos-account-cairo/blob/develop/src/account/Account.cairo
fn get_invoke_braavos_dummy(chain_id: Felt252Wrapper) -> blockifier::transaction::transactions::InvokeTransaction {
let signature = TransactionSignature(vec![
Expand Down Expand Up @@ -211,43 +177,6 @@ fn get_invoke_braavos_dummy(chain_id: Felt252Wrapper) -> blockifier::transaction
blockifier::transaction::transactions::InvokeTransaction { tx, tx_hash, only_query: false }
}

fn get_invoke_v3_braavos_dummy(chain_id: Felt252Wrapper) -> blockifier::transaction::transactions::InvokeTransaction {
let signature = TransactionSignature(vec![
StarkFelt::try_from("0x00f513fe663ffefb9ad30058bb2d2f7477022b149a0c02fb63072468d3406168").unwrap(),
StarkFelt::try_from("0x02e29e92544d31c03e89ecb2005941c88c28b4803a3647a7834afda12c77f096").unwrap(),
]);
let sender_address = ContractAddress(PatriciaKey(
StarkFelt::try_from("0x05ef3fba22df259bf84890945352df711bcc9a4e3b6858cb93e9c90d053cf122").unwrap(),
));
let nonce = Nonce(StarkFelt::ZERO);
let calldata = Calldata(Arc::new(vec![
StarkFelt::try_from("0x1").unwrap(), // call_array_len
StarkFelt::try_from("0x024d1e355f6b9d27a5a420c8f4b50cea9154a8e34ad30fc39d7c98d3c177d0d7").unwrap(), // to
StarkFelt::try_from("0x00e7def693d16806ca2a2f398d8de5951344663ba77f340ed7a958da731872fc").unwrap(), // selector
StarkFelt::try_from("0x0").unwrap(), // data_offset
StarkFelt::try_from("0x1").unwrap(), // data_len
StarkFelt::try_from("0x1").unwrap(), // calldata_len
StarkFelt::try_from("0x19").unwrap(), // calldata[0]
]));

let tx = starknet_api::transaction::InvokeTransaction::V3(starknet_api::transaction::InvokeTransactionV3 {
resource_bounds: create_resource_bounds(),
tip: starknet_api::transaction::Tip::default(),
calldata,
sender_address,
nonce,
signature,
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
paymaster_data: starknet_api::transaction::PaymasterData(vec![]),
account_deployment_data: starknet_api::transaction::AccountDeploymentData(vec![]),
});

let tx_hash = tx.compute_hash(chain_id, false);

blockifier::transaction::transactions::InvokeTransaction { tx, tx_hash, only_query: false }
}

// ref: https://github.com/OpenZeppelin/cairo-contracts/blob/main/src/openzeppelin/token/erc20/IERC20.cairo
fn get_invoke_emit_event_dummy(chain_id: Felt252Wrapper) -> blockifier::transaction::transactions::InvokeTransaction {
let signature = TransactionSignature(vec![
Expand Down

0 comments on commit b4e7162

Please sign in to comment.