cairo: bug: non-deterministically encountering Error: Failed setting up runner. when running cairo-test
Bug Report
Cairo version: 8a160d3d7c00f7abada689cb3fbc1bb6daba072b
Current behavior:
When running cairo-test --starknet ., the test runner fails with error
Error: Failed setting up runner.
Caused by:
Failed calculating gas usage, it is likely a call for `gas::withdraw_gas` is missing.
It’s very weird, because it doesn’t happen everytime. I’m writing tests against deployed contracts, using the following code:
use starknet::syscalls::deploy_syscall;
use starknet::class_hash::Felt252TryIntoClassHash;
use starknet::contract_address::contract_address_const;
use starknet::ContractAddress;
use starknet::testing;
use starknet::get_contract_address;
use traits::Into;
use traits::TryInto;
use option::OptionTrait;
use result::ResultTrait;
use array::ArrayTrait;
use debug::PrintTrait;
use simple_vault::vault::Vault;
use simple_vault::vault::IVaultDispatcher;
use simple_vault::vault::IVaultDispatcherTrait;
use tests::mocks::mock_erc20::MockERC20;
use tests::mocks::mock_erc20::IMockERC20Dispatcher;
use tests::mocks::mock_erc20::IMockERC20DispatcherTrait;
use openzeppelin::token::erc20::IERC20Dispatcher;
use openzeppelin::token::erc20::IERC20DispatcherTrait;
fn setup() -> (IMockERC20Dispatcher, IVaultDispatcher) {
// Set up.
// Deploy mock token.
let user1 = contract_address_const::<0x123456789>();
let mut calldata = ArrayTrait::new();
let name = 'Mock Token';
let symbol = 'TKN';
calldata.append(name);
calldata.append(symbol);
let (token_address, _) = deploy_syscall(
MockERC20::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
).unwrap();
let mut calldata = ArrayTrait::<felt252>::new();
calldata.append('Mock Token Vault');
calldata.append('vwTKN');
calldata.append(token_address.into());
let (vault_address, _) = deploy_syscall(
Vault::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
).unwrap();
let token = IMockERC20Dispatcher { contract_address: token_address };
let vault = IVaultDispatcher { contract_address: vault_address };
(token, vault)
}
#[test]
#[available_gas(2000000000000)]
fn test_atomic_deposit_withdratest_atomic_deposit_withdraww() {
let (underlying, vault) = setup();
let alice = contract_address_const::<0x123456789>();
testing::set_contract_address(alice);
underlying.mint(alice, 100.into());
// //TODO fix: calling underlying.approve() here causes a failed calculating gas usage here
underlying.approve(vault.contract_address, 100.into());
// snip
}
I haven’t been able to isolate the problem, as it worked fine when I used tried to setup a smaller repo with just ERC20 + testing mocks for mint/approval. I can provide more context with the full repository if required, but it’s changing constantly and subject to a lot of changes. Expected behavior: The test runs fine
Steps to reproduce:
Other information:
Halfway through redacting this, I actually re-tested to see what happened when I uncommented the underlying.approve(vault.contract_address, 100.into());, and it ran; but after removing the TODO comment above, it stopped running. This non-determinism is quite odd 🤔 . I can’t figure out how to reproduce it reliably. The code and its dependencies don’t rely on any recursive function or loop.
The non-determinism is the most surprising part, as randomly commenting - uncommenting lines seems to fix it for a while, before modifying the file again and breaking it.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
having a less naive algorithm for adding constraints seemed to have sufficed for now. attached a pr.
please feel free to test other large projects on it and tell me what you see. I apologise for the long wait.
All tests running and passing on cubit, amazing!
I have the exact same issue with cubit. Easily reproducible by just trying to run
make testwith https://github.com/influenceth/cubitTo see the non-determinism, try commenting out various test suites, some combos will run, some won’t with seemingly no pattern.