diff --git a/crates/pallets/starknet/src/tests/invoke_tx.rs b/crates/pallets/starknet/src/tests/invoke_tx.rs index b4dddc6f5a..7c09998ee4 100644 --- a/crates/pallets/starknet/src/tests/invoke_tx.rs +++ b/crates/pallets/starknet/src/tests/invoke_tx.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use blockifier::abi::abi_utils::get_storage_var_address; use blockifier::execution::contract_class::ClassInfo; -use blockifier::transaction::transactions::{DeclareTransaction, InvokeTransaction}; +use blockifier::transaction::transactions::{DeclareTransaction, DeployAccountTransaction, InvokeTransaction}; use frame_support::{assert_err, assert_ok}; use mp_felt::Felt252Wrapper; use mp_transactions::compute_hash::ComputeTransactionHash; @@ -35,8 +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_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_storage_read_write_dummy, + set_infinite_tokens, set_nonce, }; use crate::{Call, Error, StorageView}; @@ -927,18 +927,6 @@ fn given_hardcoded_contract_run_invoke_tx_v3_fails_sender_not_deployed() { }) } -#[test] -fn given_hardcoded_contract_run_invoke_tx_v3_on_openzeppelin_account_then_it_works() { - new_test_ext::().execute_with(|| { - basic_test_setup(2); - let none_origin = RuntimeOrigin::none(); - // NOT WORKING - let transaction = get_invoke_v3_openzeppelin_dummy(Starknet::chain_id()); - - assert_ok!(Starknet::invoke(none_origin, transaction)); - }); -} - #[test] fn given_hardcoded_contract_run_invoke_tx_v3_with_inner_call_in_validate_then_it_fails() { new_test_ext::().execute_with(|| { @@ -968,12 +956,13 @@ fn given_hardcoded_contract_run_invoke_tx_v3_with_inner_call_in_validate_then_it } #[test] -fn given_account_not_deployed_invoke_tx_v3_validate_works_for_nonce_one() { +fn given_account_not_deployed_invoke_tx_v3_fails_for_nonce_not_one() { new_test_ext::().execute_with(|| { basic_test_setup(2); + // Wrong address (not deployed) let contract_address = ContractAddress(PatriciaKey(StarkFelt::try_from("0x13123131").unwrap())); - // NOT WORKING + let transaction = starknet_api::transaction::InvokeTransactionV3 { resource_bounds: create_resource_bounds(), tip: starknet_api::transaction::Tip::default(), @@ -987,41 +976,95 @@ fn given_account_not_deployed_invoke_tx_v3_validate_works_for_nonce_one() { account_deployment_data: starknet_api::transaction::AccountDeploymentData(vec![StarkFelt::ZERO]), }; - set_infinite_tokens::(&contract_address); - assert_ok!(Starknet::validate_unsigned( - TransactionSource::InBlock, - &crate::Call::invoke { transaction: transaction.into() } - )); + assert_eq!( + Starknet::validate_unsigned( + TransactionSource::InBlock, + &crate::Call::invoke { transaction: transaction.into() } + ), + Err(TransactionValidityError::Invalid(InvalidTransaction::BadProof)) + ); }) } #[test] -fn given_account_not_deployed_invoke_tx_v3_fails_for_nonce_not_one() { +fn declare_transaction_v3_then_it_works() { new_test_ext::().execute_with(|| { basic_test_setup(2); - // Wrong address (not deployed) - let contract_address = ContractAddress(PatriciaKey(StarkFelt::try_from("0x13123131").unwrap())); + let chain_id = Starknet::chain_id(); + let none_origin = RuntimeOrigin::none(); + let account_addr = get_account_address(None, AccountType::V1(AccountTypeV1Inner::NoValidate)); - let transaction = starknet_api::transaction::InvokeTransactionV3 { + let contract_class = get_contract_class("TransactionRevert.casm.json", 1); + let contract_class_hash = ClassHash( + StarkFelt::try_from("0x7d2bcb1df4970245665a19b23a4d3877eb86a661e8d98b89afc4531134b99f6").unwrap(), + ); + let contract_compiled_class_hash = CompiledClassHash( + StarkFelt::try_from("0x1c02b663e928ed213d3a0fa206efb59182fa2ba41f5c204daa56c4a434b53e5").unwrap(), + ); + + let mut declare_tx = starknet_api::transaction::DeclareTransactionV3 { resource_bounds: create_resource_bounds(), tip: starknet_api::transaction::Tip::default(), - calldata: Calldata::default(), - sender_address: contract_address, - nonce: Nonce(StarkFelt::ZERO), signature: TransactionSignature::default(), + nonce: Nonce(StarkFelt::ZERO), + class_hash: contract_class_hash, + compiled_class_hash: contract_compiled_class_hash, + sender_address: account_addr, nonce_data_availability_mode: DataAvailabilityMode::L1, fee_data_availability_mode: DataAvailabilityMode::L1, paymaster_data: starknet_api::transaction::PaymasterData(vec![StarkFelt::ZERO]), account_deployment_data: starknet_api::transaction::AccountDeploymentData(vec![StarkFelt::ZERO]), }; - assert_eq!( - Starknet::validate_unsigned( - TransactionSource::InBlock, - &crate::Call::invoke { transaction: transaction.into() } - ), - Err(TransactionValidityError::Invalid(InvalidTransaction::BadProof)) + let tx_hash = declare_tx.compute_hash(chain_id, false); + declare_tx.signature = sign_message_hash(tx_hash); + + let transaction = DeclareTransaction::new( + starknet_api::transaction::DeclareTransaction::V3(declare_tx), + tx_hash, + ClassInfo::new(&contract_class, 1, 1).unwrap(), + ) + .unwrap(); + + assert_ok!(Starknet::declare(none_origin, transaction)); + }) +} + +#[test] +fn deploy_transaction_v3_then_it_works() { + new_test_ext::().execute_with(|| { + basic_test_setup(2); + + let chain_id = Starknet::chain_id(); + let none_origin = RuntimeOrigin::none(); + + let contract_class_hash = ClassHash( + StarkFelt::try_from("0x7d2bcb1df4970245665a19b23a4d3877eb86a661e8d98b89afc4531134b99f6").unwrap(), + ); + + let mut deploy_tx = starknet_api::transaction::DeployAccountTransactionV3 { + resource_bounds: create_resource_bounds(), + tip: starknet_api::transaction::Tip::default(), + signature: TransactionSignature::default(), + nonce: Nonce(StarkFelt::ZERO), + class_hash: contract_class_hash, + contract_address_salt: ContractAddressSalt::default(), + constructor_calldata: Calldata::default(), + nonce_data_availability_mode: DataAvailabilityMode::L1, + fee_data_availability_mode: DataAvailabilityMode::L1, + paymaster_data: starknet_api::transaction::PaymasterData(vec![StarkFelt::ZERO]), + }; + + let tx_hash = deploy_tx.compute_hash(chain_id, false); + deploy_tx.signature = sign_message_hash(tx_hash); + + let transaction = DeployAccountTransaction::new( + starknet_api::transaction::DeployAccountTransaction::V3(deploy_tx), + tx_hash, + ContractAddress::default(), ); + + assert_ok!(Starknet::deploy_account(none_origin, transaction)); }) } diff --git a/crates/pallets/starknet/src/tests/mod.rs b/crates/pallets/starknet/src/tests/mod.rs index 1ce806dd90..bc18e7cf0a 100644 --- a/crates/pallets/starknet/src/tests/mod.rs +++ b/crates/pallets/starknet/src/tests/mod.rs @@ -295,45 +295,6 @@ fn get_invoke_openzeppelin_dummy(chain_id: Felt252Wrapper) -> blockifier::transa blockifier::transaction::transactions::InvokeTransaction { tx, tx_hash, only_query: false } } -fn get_invoke_v3_openzeppelin_dummy( - chain_id: Felt252Wrapper, -) -> blockifier::transaction::transactions::InvokeTransaction { - let signature = TransactionSignature(vec![ - StarkFelt::try_from("0x028ef1ae6c37314bf9df65663db1cf68f95d67c4b4cf7f6590654933a84912b0").unwrap(), - StarkFelt::try_from("0x0625aae99c58b18e5161c719fef0f99579c6468ca6c1c866f9b2b968a5447e4").unwrap(), - ]); - let sender_address = ContractAddress(PatriciaKey( - StarkFelt::try_from("0x06e2616a2dceff4355997369246c25a78e95093df7a49e5ca6a06ce1544ffd50").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 length - 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 } -} - /// Returns a dummy declare transaction for the given account type. /// The declared class hash is a ERC20 contract, class hash calculated /// with starkli.