Skip to content

Commit

Permalink
fix: 2024_07 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Sep 27, 2024
1 parent 263f933 commit dfcf526
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
5 changes: 4 additions & 1 deletion listings/applications/merkle_tree/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[package]
name = "merkle_tree"
version.workspace = true
edition = '2023_11'
edition = "2024_07"

[dependencies]
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true

[scripts]
test.workspace = true

Expand Down
21 changes: 7 additions & 14 deletions listings/applications/merkle_tree/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use merkle_tree::contract::MerkleTree::__member_module_hashes::InternalContractMemberStateTrait as HashesInt;
use merkle_tree::contract::MerkleTree::__member_module_hashes_length::InternalContractMemberStateTrait as HashesLenInt;
use merkle_tree::contract::IMerkleTreeDispatcherTrait;
use merkle_tree::contract::{IMerkleTreeDispatcher, MerkleTree, ByteArrayHashTrait};
use starknet::syscalls::deploy_syscall;
use starknet::{ContractAddress, SyscallResultTrait};
use starknet::testing::set_contract_address;
use core::poseidon::PoseidonTrait;
use core::hash::{HashStateTrait, HashStateExTrait};
use starknet::storage::{StorageMapReadAccess, StoragePointerReadAccess};

fn deploy_util(class_hash: felt252, calldata: Array<felt252>) -> ContractAddress {
let (address, _) = deploy_syscall(class_hash.try_into().unwrap(), 0, calldata.span(), false)
.unwrap_syscall();

address
}

Expand All @@ -22,11 +20,10 @@ fn setup() -> IMerkleTreeDispatcher {
}

#[test]
#[available_gas(20000000)]
fn should_deploy() {
let deploy = setup();

let state = MerkleTree::contract_state_for_testing();
let state = @MerkleTree::contract_state_for_testing();
// "link" a new MerkleTree struct to the deployed MerkleTree contract
// in order to access its internal state fields for assertions
set_contract_address(deploy.contract_address);
Expand All @@ -35,7 +32,6 @@ fn should_deploy() {
}

#[test]
#[available_gas(20000000)]
fn build_tree_succeeds() {
/// Set up
let deploy = setup();
Expand Down Expand Up @@ -80,23 +76,21 @@ fn build_tree_succeeds() {

// verify contract storage state

let state = MerkleTree::contract_state_for_testing();
let state = @MerkleTree::contract_state_for_testing();
// "link" a new MerkleTree struct to the deployed MerkleTree contract
// in order to access its internal state fields for assertions
set_contract_address(deploy.contract_address);

assert_eq!(state.hashes_length.read(), expected_hashes.len());

let mut i = 0;
while i < expected_hashes
.len() {
assert_eq!(state.hashes.read(i), *expected_hashes.at(i));
i += 1;
};
while i < expected_hashes.len() {
assert_eq!(state.hashes.read(i), *expected_hashes.at(i));
i += 1;
};
}

#[test]
#[available_gas(20000000)]
#[should_panic(expected: ('Data length is not a power of 2', 'ENTRYPOINT_FAILED'))]
fn build_tree_fails() {
/// Set up
Expand All @@ -113,7 +107,6 @@ fn build_tree_fails() {
}

#[test]
#[available_gas(20000000)]
fn verify_leaf_succeeds() {
/// Set up
let deploy = setup();
Expand Down

0 comments on commit dfcf526

Please sign in to comment.