Contract call from another contract fails with ContractNotInInputs error

Hi all!!!

In my sway lend market dapp I have written a method that gets the price from the oracle:

get_price implementation my opinion

And my test fails

with this error

thread 'local_tests::get_oracle_price::get_oracle_price' panicked at 'called `Result::unwrap()` on an `Err` value: RevertTransactionError("", [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: 91a835cd17f2330e277a8fcec11ec80fb609e0cf0e4f051259e2aa8cd1e062af, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 1000000, param1: 3544824285, param2: 10472, pc: 11664, is: 11664 }, Panic { id: 91a835cd17f2330e277a8fcec11ec80fb609e0cf0e4f051259e2aa8cd1e062af, reason: InstructionResult { reason: ContractNotInInputs, instruction: Instruction { op: 45, ra: 16, rb: 18, rc: 19, rd: 17, imm06: 209, imm12: 1233, imm18: 74961, imm24: 4269265 } }, pc: 263912, is: 11664, contract_id: Some(d9a4d9b187e243ec48093630e2f8e4604b258199ed61365ace890810fd754fe1) }, ScriptResult { result: Panic, gas_used: 21652 }])', tests/local_tests/get_oracle_price.rs:22:35

Testnet test

I have a price oracle smart contract which already deployed and initialized here 0xde764394c83bb3c8a3aec5f75f383ff86e64728964fab4469df5910ca01b1a59 with test token BTC deployed and initialized here 0x851ec5e04fa3485ba0794b34030bbcd70e96be282cd429da03c58e8de4d46c00

I have written a sway script that gets prices from oracle in testnet.
main.sw

script;

use std::logging::log;
use oracle_abi::*;

fn get_price(asset: ContractId, price_feed: ContractId) -> u64 {
    let res = abi(Oracle, price_feed.value).get_price(asset);
    res.price
}

fn main() {
    let token = ContractId::from(0x851ec5e04fa3485ba0794b34030bbcd70e96be282cd429da03c58e8de4d46c00);
    let price_feed = ContractId::from(0xde764394c83bb3c8a3aec5f75f383ff86e64728964fab4469df5910ca01b1a59);
    let price = get_price(token, price_feed);
    assert(price == 16589783643771);
}

And here you can see the test

use dotenv::dotenv;
use fuels::prelude::*;

const RPC: &str = "node-beta-2.fuel.network";
script_abigen!(Script, "out/debug/functions_test_script-abi.json");

pub async fn setup_wallet() -> (WalletUnlocked, Provider) {
    let provider = match Provider::connect(RPC).await {
        Ok(p) => p,
        Err(error) => panic!("❌ Problem creating provider: {:#?}", error),
    };

    dotenv().ok();
    let secret = match std::env::var("SECRET") {
        Ok(s) => s,
        Err(error) => panic!("❌ Cannot find .env file: {:#?}", error),
    };

    let wallet =
        WalletUnlocked::new_from_private_key(secret.parse().unwrap(), Some(provider.clone()));

    return (wallet, provider);
}


#[tokio::test]
async fn main_test() {
    let wallet = launch_provider_and_get_wallet().await;
    let bin_path = "out/debug/functions_test_script.bin";
    let instance = Script::new(wallet.clone(), bin_path);

    let response = instance.main().call().await.unwrap();

    let logs = response.get_logs().unwrap();
    println!("{:#?}", logs);
    let log_u64 = response.get_logs_with_type::<u64>().unwrap();
    println!("{:#?}", log_u64);
}

The test fails with the same error

running 1 test
thread 'main_test' panicked at 'called `Result::unwrap()` on an `Err` value: RevertTransactionError("ContractNotInInputs", [Panic { id: 0000000000000000000000000000000000000000000000000000000000000000, reason: InstructionResult { reason: ContractNotInInputs, instruction: Instruction { op: 45, ra: 18, rb: 0, rc: 16, rd: 17, imm06: 17, imm12: 1041, imm18: 1041, imm24: 4719633 } }, pc: 10528, is: 10344, contract_id: None }, ScriptResult { result: Panic, gas_used: 5508 }])', tests/harness.rs:32:49
9 Likes

Can you try chaining simulate() with set_contracts() method?

Here is the reference to that in the Fuel Rust SDK Book. The example here uses call() instead of simulate() but the process is the same.

6 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.