False positive: Tokio test passes in true; Sway function interprets false

How to reproduce the anomaly:
in the root dir of the project (links below)
run forc compile then run cargo test

The lines of interest are here

^ execution enters the false branch of the if statement (as evidenced by log output 42)
even though it should be entering the true branch because that’s what the test passes in

The test in question

1 Like

Hey @johnquid, I can replicate your issue and see that both variables passed into the deposit function are returning false. Can you bump up your forc version from 0.44.1 to 0.48.1. There might be a mismatch here because you’re on the latest version of the rust sdk 0.53.0.

I tried to replicate your error at a much smaller scale and no longer had any issues.

main.sw

contract;

abi MyContract {
    fn test_function(state: bool);
}

impl MyContract for Contract {
    #[payable]
    fn test_function(state: bool) {
        if state == true {
            log(true)
        } else {
            log(false)
        }
    }
}

harness.rs

use std::time::Instant;

use fuels::{prelude::*, types::ContractId};

// Load abi from json
abigen!(Contract(
    name = "MyContract",
    abi = "out/debug/fuelet-forum-abi.json"
));

async fn get_contract_instance() -> (MyContract<WalletUnlocked>, ContractId) {
    // Launch a local network and deploy the contract
    let mut wallets = launch_custom_provider_and_get_wallets(
        WalletsConfig::new(
            Some(1),             /* Single wallet */
            Some(1),             /* Single coin (UTXO) */
            Some(1_000_000_000), /* Amount per coin */
        ),
        None,
        None,
    )
    .await
    .unwrap();
    let wallet = wallets.pop().unwrap();

    let id = Contract::load_from(
        "./out/debug/fuelet-forum.bin",
        LoadConfiguration::default(),
    )
    .unwrap()
    .deploy(&wallet, TxPolicies::default())
    .await
    .unwrap();

    let instance = MyContract::new(id.clone(), wallet);

    (instance, id.into())
}

#[tokio::test]
async fn can_get_contract_id() {
    let (instance, _id) = get_contract_instance().await;

    let params = CallParameters::new(42, BASE_ASSET_ID, 3000); // 3k is gas


    // Now you have an instance of your contract you can use to test each function
    let res = instance
        .methods()
        .test_function(true)
        .call_params(params)
        .unwrap()
        .call()
        .await
        .unwrap()
        .decode_logs_with_type::<bool>().unwrap();
    print!("{:?}", res);
}

active toolchain

calldelegation_beta_5 (default)
forc : 0.48.1
- forc-client
- forc-deploy : 0.48.1
- forc-run : 0.48.1
- forc-doc : 0.48.1
- forc-explore - not found
- forc-fmt : 0.48.1
- forc-index - not found
- forc-lsp : 0.48.1
- forc-tx : 0.48.1
- forc-wallet - not found
fuel-core - not found
fuel-core-keygen - not found
fuel-indexer - not found

fuels versions

forc : 0.53.0

1 Like

good code amzing now

Thank you for your response…@calldelegation

After bumping up forc to 0.48.1 the anomaly no longer happens, but there is a new kind of error. There’s actually an error thrown this time (progress).

The type is of the error is InvalidMetadataIdentifier…I did a search for this on the forum, Discord, and docs…but couldn’t find anything.
Have attached a screenshot


(also if you want to replicate locally here is the relevant commit).

I’ve linked to a specific commit because the most recent one in master is related to a separate issue

1 Like

Can you please open a new topic with this information?