-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move transaction creator test util to starknet api (#661)
- Loading branch information
1 parent
2395f9a
commit a4f71a0
Showing
25 changed files
with
419 additions
and
397 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
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
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
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,132 +1,12 @@ | ||
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; | ||
use starknet_api::data_availability::DataAvailabilityMode; | ||
use starknet_api::transaction::{ | ||
AccountDeploymentData, | ||
DeclareTransactionV0V1, | ||
DeclareTransactionV2, | ||
DeclareTransactionV3, | ||
Fee, | ||
PaymasterData, | ||
Tip, | ||
TransactionHash, | ||
TransactionSignature, | ||
TransactionVersion, | ||
ValidResourceBounds, | ||
}; | ||
use starknet_api::test_utils::declare::DeclareTxArgs; | ||
|
||
use crate::execution::contract_class::ClassInfo; | ||
use crate::test_utils::default_testing_resource_bounds; | ||
use crate::transaction::account_transaction::AccountTransaction; | ||
use crate::transaction::transactions::DeclareTransaction; | ||
|
||
#[derive(Clone)] | ||
pub struct DeclareTxArgs { | ||
pub max_fee: Fee, | ||
pub signature: TransactionSignature, | ||
pub sender_address: ContractAddress, | ||
pub version: TransactionVersion, | ||
pub resource_bounds: ValidResourceBounds, | ||
pub tip: Tip, | ||
pub nonce_data_availability_mode: DataAvailabilityMode, | ||
pub fee_data_availability_mode: DataAvailabilityMode, | ||
pub paymaster_data: PaymasterData, | ||
pub account_deployment_data: AccountDeploymentData, | ||
pub nonce: Nonce, | ||
pub class_hash: ClassHash, | ||
pub compiled_class_hash: CompiledClassHash, | ||
// TODO(Arni): Consider removing this field. | ||
pub tx_hash: TransactionHash, | ||
} | ||
|
||
impl Default for DeclareTxArgs { | ||
fn default() -> Self { | ||
Self { | ||
max_fee: Fee::default(), | ||
signature: TransactionSignature::default(), | ||
sender_address: ContractAddress::default(), | ||
version: TransactionVersion::THREE, | ||
resource_bounds: default_testing_resource_bounds(), | ||
tip: Tip::default(), | ||
nonce_data_availability_mode: DataAvailabilityMode::L1, | ||
fee_data_availability_mode: DataAvailabilityMode::L1, | ||
paymaster_data: PaymasterData::default(), | ||
account_deployment_data: AccountDeploymentData::default(), | ||
nonce: Nonce::default(), | ||
class_hash: ClassHash::default(), | ||
compiled_class_hash: CompiledClassHash::default(), | ||
tx_hash: TransactionHash::default(), | ||
} | ||
} | ||
} | ||
|
||
/// Utility macro for creating `DeclareTxArgs` to reduce boilerplate. | ||
#[macro_export] | ||
macro_rules! declare_tx_args { | ||
($($field:ident $(: $value:expr)?),* $(,)?) => { | ||
$crate::test_utils::declare::DeclareTxArgs { | ||
$($field $(: $value)?,)* | ||
..Default::default() | ||
} | ||
}; | ||
($($field:ident $(: $value:expr)?),* , ..$defaults:expr) => { | ||
$crate::test_utils::declare::DeclareTxArgs { | ||
$($field $(: $value)?,)* | ||
..$defaults | ||
} | ||
}; | ||
} | ||
|
||
pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction { | ||
let tx_hash = declare_tx_args.tx_hash; | ||
let declare_tx = inner_declare_tx(declare_tx_args); | ||
let declare_tx = starknet_api::test_utils::declare::declare_tx(declare_tx_args); | ||
|
||
AccountTransaction::Declare(DeclareTransaction::new(declare_tx, tx_hash, class_info).unwrap()) | ||
} | ||
|
||
fn inner_declare_tx( | ||
declare_tx_args: DeclareTxArgs, | ||
) -> starknet_api::transaction::DeclareTransaction { | ||
// TODO: Make TransactionVersion an enum and use match here. | ||
if declare_tx_args.version == TransactionVersion::ZERO { | ||
starknet_api::transaction::DeclareTransaction::V0(DeclareTransactionV0V1 { | ||
max_fee: declare_tx_args.max_fee, | ||
signature: declare_tx_args.signature, | ||
sender_address: declare_tx_args.sender_address, | ||
nonce: declare_tx_args.nonce, | ||
class_hash: declare_tx_args.class_hash, | ||
}) | ||
} else if declare_tx_args.version == TransactionVersion::ONE { | ||
starknet_api::transaction::DeclareTransaction::V1(DeclareTransactionV0V1 { | ||
max_fee: declare_tx_args.max_fee, | ||
signature: declare_tx_args.signature, | ||
sender_address: declare_tx_args.sender_address, | ||
nonce: declare_tx_args.nonce, | ||
class_hash: declare_tx_args.class_hash, | ||
}) | ||
} else if declare_tx_args.version == TransactionVersion::TWO { | ||
starknet_api::transaction::DeclareTransaction::V2(DeclareTransactionV2 { | ||
max_fee: declare_tx_args.max_fee, | ||
signature: declare_tx_args.signature, | ||
sender_address: declare_tx_args.sender_address, | ||
nonce: declare_tx_args.nonce, | ||
class_hash: declare_tx_args.class_hash, | ||
compiled_class_hash: declare_tx_args.compiled_class_hash, | ||
}) | ||
} else if declare_tx_args.version == TransactionVersion::THREE { | ||
starknet_api::transaction::DeclareTransaction::V3(DeclareTransactionV3 { | ||
signature: declare_tx_args.signature, | ||
sender_address: declare_tx_args.sender_address, | ||
resource_bounds: declare_tx_args.resource_bounds, | ||
tip: declare_tx_args.tip, | ||
nonce_data_availability_mode: declare_tx_args.nonce_data_availability_mode, | ||
fee_data_availability_mode: declare_tx_args.fee_data_availability_mode, | ||
paymaster_data: declare_tx_args.paymaster_data, | ||
account_deployment_data: declare_tx_args.account_deployment_data, | ||
nonce: declare_tx_args.nonce, | ||
class_hash: declare_tx_args.class_hash, | ||
compiled_class_hash: declare_tx_args.compiled_class_hash, | ||
}) | ||
} else { | ||
panic!("Unsupported transaction version: {:?}.", declare_tx_args.version) | ||
} | ||
} |
Oops, something went wrong.