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

**URL:** <https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888>\
**Category:** Sway\
**Created:** [December 20, 2023, 12:46pm UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888 "2023-12-20T12:46:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnquid](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/johnquid/32/1065_2.png) [@johnquid](https://forum.fuel.network/u/johnquid)\
**Post date:** [December 20, 2023, 12:46pm UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888/1 "2023-12-20T12:46:54Z")

</div>

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

> <https://github.com/QuidMint/quid/blob/main/contracts/QD/src/main.sw#L1074>

^ 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

> <https://github.com/QuidMint/quid/blob/main/contracts/QD/tests/harness.rs#L134>

---

<div class="post-metadata">

**Author:** ![calldelegation](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/calldelegation/32/1484_2.png) [@calldelegation](https://forum.fuel.network/u/calldelegation)\
**Post date:** [December 23, 2023, 6:24pm UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888/2 "2023-12-23T18:24:09Z")

</div>

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`

```auto
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`

```auto
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

---

<div class="post-metadata">

**Author:** ![trinhthanhbinh9027](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@trinhthanhbinh9027](https://forum.fuel.network/u/trinhthanhbinh9027)\
**Post date:** [December 24, 2023, 5:45am UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888/3 "2023-12-24T05:45:16Z")

</div>

good code amzing now

---

<div class="post-metadata">

**Author:** ![johnquid](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/johnquid/32/1065_2.png) [@johnquid](https://forum.fuel.network/u/johnquid)\
**Post date:** [December 26, 2023, 6:30pm UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888/4 "2023-12-26T18:30:18Z")

</div>

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

 ![Screenshot 2023-12-26 at 18.53.49](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/e/e369ec9ae457fc2a0b9e85dd08bd1b2446df01cb.jpeg)  
(also if you want to replicate locally [here](https://github.com/QuidMint/quid/commit/e0b3a1443bfd774ffd807ea4326d05cbfe6434ef) is the relevant commit).

I’ve linked to a specific commit because the most recent one in master is related to a [separate issue](https://forum.fuel.network/t/sway-libs-floating-point-causes-compiler-to-stall-and-crash/3901)

---

<div class="post-metadata">

**Author:** ![sandusky](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sandusky/32/1313_2.png) [@sandusky](https://forum.fuel.network/u/sandusky)\
**Post date:** [January 26, 2024, 6:01am UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888/5 "2024-01-26T06:01:17Z")

</div>

> [@johnquid](#):
>
> maly 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

Can you please open a new topic with this information?

---

<div class="post-metadata">

**Author:** ![sandusky](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sandusky/32/1313_2.png) [@sandusky](https://forum.fuel.network/u/sandusky)\
**Post date:** [January 26, 2024, 6:01am UTC](https://forum.fuel.network/t/false-positive-tokio-test-passes-in-true-sway-function-interprets-false/3888/6 "2024-01-26T06:01:23Z")

</div>


