Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overriding named fork config info in docs #2500

Merged
merged 3 commits into from
Sep 26, 2024
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
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod name;
pub mod explicit;
pub mod overridden_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use fork_testing::{IPokemonGalleryDispatcher, IPokemonGalleryDispatcherTrait};

const CONTRACT_ADDRESS: felt252 =
0x0522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716;

#[test]
#[fork("SEPOLIA_LATEST", block_number: 200000)]
fn test_using_forked_state() {
let dispatcher = IPokemonGalleryDispatcher {
contract_address: CONTRACT_ADDRESS.try_into().unwrap()
};

dispatcher.like("Charizard");
let pokemon = dispatcher.pokemon("Charizard");

assert!(pokemon.is_some());
assert_eq!(pokemon.unwrap().likes, 1);
}
7 changes: 7 additions & 0 deletions docs/src/snforge-advanced-features/fork-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ From this moment forks can be set using their name in the `fork` attribute.
{{#include ../../listings/snforge_advanced_features/crates/fork_testing/tests/name.cairo}}
```

In some cases you may want to override `block_id` defined in the `Scarb.toml` file.
You can do it by passing `block_number`, `block_hash`, `block_tag` arguments to the `fork` attribute.

```rust
{{#include ../../listings/snforge_advanced_features/crates/fork_testing/tests/overridden_name.cairo}}
```

## Testing Forked Contracts

Once the fork is configured, the test will run on top of the forked state, meaning that it will have access to every contract deployed on the real network.
Expand Down
Loading