Skip to content

Commit

Permalink
Update Scarb (tests fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Oct 23, 2024
1 parent e4d1665 commit 040d6d2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb nightly-2024-04-20
starknet-foundry 0.23.0
scarb 2.8.4
starknet-foundry 0.32.0
12 changes: 10 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.32.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.32.0#3817c903b640201c72e743b9bbe70a97149828a2"

[[package]]
name = "snforge_std"
version = "0.23.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.23.0#f2bff8f796763ada77fe6033ec1b034ceee22abd"
version = "0.32.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.32.0#3817c903b640201c72e743b9bbe70a97149828a2"
dependencies = [
"snforge_scarb_plugin",
]
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ casm = true
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "2.6.3"
starknet = "2.8.4"
cairo_lib = { git = "https://github.com/HerodotusDev/cairo-lib.git", branch = "update-cairo" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.23.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.32.0" }

[tool.snforge]
exit_first = true
Expand Down
14 changes: 8 additions & 6 deletions src/core/tests/test_facts_registry.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use snforge_std::{declare, ContractClassTrait, start_prank, stop_prank, CheatTarget};

use snforge_std::{
declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait,
DeclareResultTrait
};
use herodotus_eth_starknet::core::headers_store::{
IHeadersStoreDispatcherTrait, IHeadersStoreDispatcher
};
Expand All @@ -20,14 +22,14 @@ const TEST_BLOCK: u256 = 17000000;
fn helper_create_facts_registry(
mmr_root: felt252, mmr_size: MmrSize
) -> (IEVMFactsRegistryDispatcher, ContractAddress) {
let contract = declare("HeadersStore").unwrap();
let contract = declare("HeadersStore").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![COMMITMENTS_INBOX_ADDRESS]).unwrap();
let mut headers_store = IHeadersStoreDispatcher { contract_address };
start_prank(CheatTarget::One(contract_address), COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
start_cheat_caller_address(contract_address, COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
headers_store.create_branch_from_message(mmr_root, mmr_size, 0, 1);
stop_prank(CheatTarget::One(contract_address));
stop_cheat_caller_address(contract_address);

let contract = declare("EVMFactsRegistry").unwrap();
let contract = declare("EVMFactsRegistry").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![contract_address.into()]).unwrap();
(IEVMFactsRegistryDispatcher { contract_address }, contract_address)
}
Expand Down
34 changes: 18 additions & 16 deletions src/core/tests/test_headers_store.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0

use snforge_std::{declare, ContractClassTrait, start_prank, stop_prank, CheatTarget};
use snforge_std::{
declare, ContractClassTrait, DeclareResultTrait, start_cheat_caller_address,
stop_cheat_caller_address
};
use herodotus_eth_starknet::core::headers_store::{
IHeadersStoreDispatcherTrait, IHeadersStoreDispatcher, IHeadersStoreSafeDispatcherTrait,
IHeadersStoreSafeDispatcher
Expand All @@ -18,13 +21,13 @@ const MMR_INITIAL_ROOT: MmrElement =
0x6759138078831011e3bc0b4a135af21c008dda64586363531697207fb5a2bae;

fn helper_create_headers_store() -> (IHeadersStoreDispatcher, ContractAddress) {
let contract = declare("HeadersStore").unwrap();
let contract = declare("HeadersStore").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![COMMITMENTS_INBOX_ADDRESS]).unwrap();
(IHeadersStoreDispatcher { contract_address }, contract_address)
}

fn helper_create_safe_headers_store() -> (IHeadersStoreSafeDispatcher, ContractAddress) {
let contract = declare("HeadersStore").unwrap();
let contract = declare("HeadersStore").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![COMMITMENTS_INBOX_ADDRESS]).unwrap();
(IHeadersStoreSafeDispatcher { contract_address }, contract_address)
}
Expand All @@ -35,9 +38,9 @@ fn helper_receive_hash(
dispatcher: IHeadersStoreDispatcher,
contract_address: ContractAddress
) {
start_prank(CheatTarget::One(contract_address), COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
start_cheat_caller_address(contract_address, COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
dispatcher.receive_hash(blockhash, block_number);
stop_prank(CheatTarget::One(contract_address));
stop_cheat_caller_address(contract_address);
}

#[test]
Expand Down Expand Up @@ -193,10 +196,9 @@ fn test_header_block_1() {
let mmr_id = 1;

let (dispatcher, contract_address) = helper_create_headers_store();

start_prank(CheatTarget::One(contract_address), COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
start_cheat_caller_address(contract_address, COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
dispatcher.create_branch_from_message(mmr.root, mmr.last_pos, 0, mmr_id);
stop_prank(CheatTarget::One(contract_address));
stop_cheat_caller_address(contract_address);
assert(dispatcher.get_mmr_root(mmr_id) == mmr.root, 'Root not set');

dispatcher
Expand All @@ -209,7 +211,6 @@ fn test_header_block_1() {
Option::Some(mmr_proof)
);
}

#[test]
#[feature("safe_dispatcher")]
fn test_receive_hash_wrong_address() {
Expand Down Expand Up @@ -242,7 +243,7 @@ fn test_create_branch_from_message() {
let root = 0x123123123;
let size = 10;

start_prank(CheatTarget::One(contract_address), COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
start_cheat_caller_address(contract_address, COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());

// Create MMR.
assert(dispatcher.get_mmr_size(mmr_id_1).unwrap() == 0, 'Initial mmr size should be 0');
Expand Down Expand Up @@ -272,7 +273,7 @@ fn test_create_branch_from_message() {
assert(dispatcher.get_mmr_size(mmr_id_2).unwrap() == size, 'Mmr size mismatch');
assert(dispatcher.get_mmr_root(mmr_id_2).unwrap() == root, 'Mmr root mismatch');

stop_prank(CheatTarget::One(contract_address));
stop_cheat_caller_address(contract_address);

let mmr_id_3 = 0x8124a;

Expand Down Expand Up @@ -306,9 +307,9 @@ fn test_create_branch_single_element() {
let mmr_id = 1;
let items = array![MMR_INITIAL_ELEMENT, 0x4AF3, 0xB1C2, 0x68D0, 0xE923, 0x0F4B, 0x37A8];
let mmr = helper_create_mmr_with_items(items.span());
start_prank(CheatTarget::One(contract_address), COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
start_cheat_caller_address(contract_address, COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
dispatcher.create_branch_from_message(mmr.root, mmr.last_pos, 0, mmr_id).unwrap();
stop_prank(CheatTarget::One(contract_address));
stop_cheat_caller_address(contract_address);

// Create branch with 3rd element
let new_mmr_id = 10;
Expand Down Expand Up @@ -414,9 +415,9 @@ fn test_create_branch_from() {
let mmr_id = 0x4a02;
let items = array![MMR_INITIAL_ELEMENT, 0x4AF3, 0xB1C2, 0x68D0, 0xE923, 0x0F4B, 0x37A8];
let mmr = helper_create_mmr_with_items(items.span());
start_prank(CheatTarget::One(contract_address), COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
start_cheat_caller_address(contract_address, COMMITMENTS_INBOX_ADDRESS.try_into().unwrap());
dispatcher.create_branch_from_message(mmr.root, mmr.last_pos, 0, mmr_id).unwrap();
stop_prank(CheatTarget::One(contract_address));
stop_cheat_caller_address(contract_address);

let new_mmr_id = 0x8cae;
dispatcher.create_branch_from(mmr_id, mmr.last_pos, new_mmr_id).unwrap();
Expand Down Expand Up @@ -737,7 +738,7 @@ fn helper_get_headers_rlp() -> Span<Words64> {
2995362435
]
.span(),
//array![
//array![
//18219417174019932921,
//16083864134760656902,
//10295426118574649922,
Expand Down Expand Up @@ -880,3 +881,4 @@ fn helper_get_headers_rlp() -> Span<Words64> {
]
.span()
}

15 changes: 9 additions & 6 deletions src/remappers/tests/test_timestamp_remappers.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0

use snforge_std::{declare, ContractClassTrait, start_prank, stop_prank, CheatTarget};
use snforge_std::{
declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait,
DeclareResultTrait
};
use starknet::ContractAddress;
use cairo_lib::data_structures::mmr::mmr::MMR;
use cairo_lib::data_structures::mmr::mmr::MMRTrait;
Expand All @@ -16,7 +19,7 @@ use herodotus_eth_starknet::core::headers_store::{
use herodotus_eth_starknet::core::common::MmrId;

fn deploy_headers_store() -> ContractAddress {
let contract = declare("HeadersStore").unwrap();
let contract = declare("HeadersStore").unwrap().contract_class();
let mut constructor_calldata = ArrayTrait::new();
constructor_calldata.append(0);

Expand All @@ -25,7 +28,7 @@ fn deploy_headers_store() -> ContractAddress {
}

fn deploy_timestamp_remappers(headers_store: ContractAddress) -> ContractAddress {
let contract = declare("TimestampRemappers").unwrap();
let contract = declare("TimestampRemappers").unwrap().contract_class();
let mut constructor_calldata: Array<felt252> = ArrayTrait::new();
constructor_calldata.append(headers_store.into());

Expand Down Expand Up @@ -349,7 +352,7 @@ fn inner_test_reindex_batch(
},
];
remapper_dispatcher.reindex_batch(mapper_id, ArrayTrait::new().span(), origin_elements.span());
// From this point on, mapper_peaks has root
// From this point on, mapper_peaks has root
// 0x215ea4dbc30f0b14338d306f0035277c856c486126cd34966a82ead2a0a1c01 and 4 as elements count
}

Expand All @@ -372,12 +375,12 @@ fn test_remappers() {
let headers_store_dispatcher = IHeadersStoreDispatcher { contract_address: headers_store };
let mmr_id = 0x123; // First MMR

start_prank(CheatTarget::One(headers_store), 0.try_into().unwrap());
start_cheat_caller_address(headers_store, 0.try_into().unwrap());
headers_store_dispatcher
.create_branch_from_message(
0x25aedbc0ddea804ce21d29a39f00358f68df0e462114f75b0576182d08db0, 4, 1, mmr_id
);
stop_prank(CheatTarget::One(headers_store));
stop_cheat_caller_address(headers_store);

inner_test_reindex_batch(remapper_dispatcher, mapper_id, mmr_id);

Expand Down

0 comments on commit 040d6d2

Please sign in to comment.