From 9ff0b4a533784c97d614db49458e6e0870f0e4b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eliel=20=EC=88=98=ED=95=99?=
<46634774+elielnfinic@users.noreply.github.com>
Date: Fri, 17 May 2024 15:03:30 +0200
Subject: [PATCH] test: adding pallet test for declare transaction v0 (#1605)
---
CHANGELOG.md | 1 +
README.md | 1 +
.../pallets/starknet/src/tests/declare_tx.rs | 46 +++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac75a49305..b34aa87bb1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,7 @@
- fix(docker): fix dockerfile for `madara-node`
- feat: Remove generic hasher from block hash computation
- refacto: git submodules removed
+- test: Add pallet test for transaction declare V0
## v0.7.0
diff --git a/README.md b/README.md
index d3a01a9d34..ecf1e8c690 100644
--- a/README.md
+++ b/README.md
@@ -277,6 +277,7 @@ Thanks goes to these wonderful people
Mrisho Lukamba 💻 |
Tbelleng 💻 |
Hamza Hamud 💻 |
+ Eliel Mathe 💻 |
diff --git a/crates/pallets/starknet/src/tests/declare_tx.rs b/crates/pallets/starknet/src/tests/declare_tx.rs
index 193650bb1b..1103be3a77 100644
--- a/crates/pallets/starknet/src/tests/declare_tx.rs
+++ b/crates/pallets/starknet/src/tests/declare_tx.rs
@@ -53,6 +53,36 @@ fn create_declare_erc20_v1_transaction(
BlockifierDeclareTransaction::new(tx, tx_hash, ClassInfo::new(&erc20_class, 0, 1).unwrap()).unwrap()
}
+fn create_declare_erc20_v0_transaction(
+ chain_id: Felt252Wrapper,
+ account_type: AccountType,
+ sender_address: Option,
+ signature: Option,
+) -> BlockifierDeclareTransaction {
+ let sender_address = sender_address.unwrap_or_else(|| get_account_address(None, account_type));
+
+ let erc20_class = get_contract_class("ERC20.json", 0);
+ let erc20_class_hash =
+ ClassHash(StarkFelt::try_from("0x057eca87f4b19852cfd4551cf4706ababc6251a8781733a0a11cf8e94211da95").unwrap());
+
+ let mut tx = StarknetApiDeclareTransaction::V0(DeclareTransactionV0V1 {
+ max_fee: Fee(u128::MAX),
+ signature: Default::default(),
+ nonce: Default::default(),
+ class_hash: erc20_class_hash,
+ sender_address,
+ });
+
+ let tx_hash = tx.compute_hash(chain_id, false);
+ // Force to do that because ComputeTransactionHash cannot be implemented on DeclareTransactionV0V1
+ // directly...
+ if let StarknetApiDeclareTransaction::V0(tx) = &mut tx {
+ tx.signature = signature.unwrap_or_else(|| sign_message_hash(tx_hash));
+ }
+
+ BlockifierDeclareTransaction::new(tx, tx_hash, ClassInfo::new(&erc20_class, 0, 1).unwrap()).unwrap()
+}
+
#[test]
fn given_contract_declare_tx_works_once_not_twice() {
new_test_ext::().execute_with(|| {
@@ -349,3 +379,19 @@ fn test_verify_nonce_in_unsigned_tx() {
);
});
}
+
+#[test]
+fn test_declare_using_transaction_v0() {
+ new_test_ext::().execute_with(|| {
+ basic_test_setup(2);
+
+ let transaction = create_declare_erc20_v0_transaction(
+ Starknet::chain_id(),
+ AccountType::V0(AccountTypeV0Inner::NoValidate),
+ None,
+ None,
+ );
+
+ assert!(Starknet::validate_unsigned(TransactionSource::InBlock, &crate::Call::declare { transaction }).is_ok());
+ });
+}