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

mock call bug #645

Closed
MaksymilianDemitraszek opened this issue Sep 12, 2023 · 2 comments · Fixed by #653
Closed

mock call bug #645

MaksymilianDemitraszek opened this issue Sep 12, 2023 · 2 comments · Fixed by #653
Assignees
Labels
bug Something isn't working snforge

Comments

@MaksymilianDemitraszek
Copy link
Member

let oracle_address: ContractAddress = 0x123456.try_into().unwrap();
start_mock_call(oracle_address, 'get_price', 69);
let oracle = IOracleDispatcher { contract_address: oracle_address };
let price = oracle.get_price();

Fails

@github-actions github-actions bot added the new label Sep 12, 2023
@MaksymilianDemitraszek MaksymilianDemitraszek added bug Something isn't working asap and removed new labels Sep 12, 2023
@Arcticae Arcticae added snforge and removed asap labels Sep 12, 2023
@Arcticae Arcticae moved this from Triage to TODO in Starknet foundry Sep 12, 2023
@delaaxe
Copy link

delaaxe commented Sep 12, 2023

minimal reproduction:

use starknet::ContractAddress;
use snforge_std::{start_mock_call, stop_mock_call};

#[starknet::interface]
trait IOracle<TContractState> {
    fn get_price(self: @TContractState, token: ContractAddress) -> u128;
}

#[test]
fn test_mocking() {
    let oracle_address = 'ORACLE'.try_into().unwrap();
    start_mock_call(oracle_address, 'get_price', 69);
    let oracle = IOracleDispatcher { contract_address: oracle_address };
    // ^^ fails with: Contract not deployed at address: 0x00000000000000000000000000000000000000000000000000004f5241434c45
    let price = oracle.get_price('TOKEN'.try_into().unwrap());
    stop_mock_call(oracle_address, 'get_price');
    assert(price == 69, 'should work');
}

@Arcticae Arcticae moved this from TODO to In Progress in Starknet foundry Sep 13, 2023
@Arcticae Arcticae self-assigned this Sep 13, 2023
github-merge-queue bot pushed a commit that referenced this issue Sep 13, 2023
<!-- Reference any GitHub issues resolved by this PR -->

Closes #645


## Checklist

<!-- Make sure all of these are complete -->

- [x] Linked relevant issue
- [x] Updated relevant documentation
- [x] Added relevant tests
- [x] Performed self-review of the code
- [x] Added changes to `CHANGELOG.md`

---------

Co-authored-by: Piotr Magiera <piotrmagiera150@gmail.com>
@github-project-automation github-project-automation bot moved this from In Progress to Done in Starknet foundry Sep 13, 2023
@delaaxe
Copy link

delaaxe commented Sep 13, 2023

still fails if trying to use get_block_number and mock calls at same time:

Screenshot 2023-09-13 at 18 58 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working snforge
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants