Println! macro doesn't work printing values

I am facing this error, where unwrapping a call cannot returns this error. I just want to print the returned value…

`FuelCallResponse<fuels::types::Address>` cannot be formatted with the default formatted

My ./test/harness.rs

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

abigen!(Contract(name="MyContract", abi="out/debug/test_asset-abi.json"));


#[tokio::test]
async fn test_harness() {
    // Test code here
    let (instance, _id) = get_contract_instance().await;

    let result = instance.methods().deposit().call().await.unwrap();
    let result2 = instance.methods().test_deposit_asset_id_same_generated().call().await.unwrap();
    let _str_from_address: &str = result.to_string().as_str();
    let r2_str_from_address: &str = result2.to_string().as_str();
    println!("{:?}",_str_from_address);
    println!("{:?}",r2_str_from_address);



}


async fn get_contract_instance() -> (MyContract<WalletUnlocked>, ContractId) {
    // Launch a local network and deploy the contract
    let wallets = launch_custom_provider_and_get_wallets(
        WalletsConfig::new(
            Some(3),             /* Three wallets */
            Some(1),             /* Single coin (UTXO) */
            Some(1_000_000_000), /* Amount per coin */
        ),
        None,
        None,
    )
    .await
    .unwrap();
 
    let wallet = wallets.get(0).unwrap().clone();
    
    let id = Contract::load_from(
        "./out/debug/test_asset.bin",
        LoadConfiguration::default(),
    )
    .unwrap()
    .deploy(&wallet, TxPolicies::default())
    .await
    .unwrap();
 
    let instance = MyContract::new(id.clone(), wallet);
 
    (instance, id.into())
}

My sway contract:

// Constant Product AMM - Uniswap V2.
contract;

use std::{
    constants::ZERO_B256,
    hash::sha256,
    asset::transfer,
    hash::Hash,
    asset_id::AssetId,
    asset::{
        burn,
        mint_to,
    },
    contract_id::ContractId,
    call_frames::{
        msg_asset_id,
    },
    context::msg_amount,
    string::String,
};
 

abi MyContract {
    #[storage(read, write)]
    fn deposit()-> Address;
    
    #[storage(read)]
    fn test_deposit_asset_id_same_generated() -> Address;
}


impl MyContract for Contract {
    #[storage(read, write)]
    fn deposit() -> Address {

        let owner = msg_sender().unwrap();
        let asset_id = msg_asset_id().bits();
        let address_from_b256: Address = Address::from(asset_id);
        address_from_b256
    }


    #[storage(read)]
    fn test_deposit_asset_id_same_generated() -> Address  {
        let token_id = b256::zero();
        let token_address = ZERO_B256;
        let sub_id = sha256((token_address, token_id));

        
        let asset_id: b256 = AssetId::new(ContractId::this(), sub_id).bits();
        let address_from_b256: Address = Address::from(asset_id);
    
        address_from_b256
        
    }

}

println! macro doesn’t work at all, why it doesn’t work?

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

abigen!(Contract(name="MyContract", abi="out/debug/test_asset-abi.json"));


#[tokio::test]
async fn test_harness() {
    // Test code here
    let (instance, _id) = get_contract_instance().await;

    let result = instance. Methods().deposit().call().await. Unwrap().value;
    let result2 = instance. Methods().test_deposit_asset_id_same_generated().call().await. Unwrap().value;
    println!("{:?}",result );
    println!("{:?}",result2 );



}

it seems like a rust error to me. could you share your rust version? and also the output for the fuelup show from your terminal

This is my terminal running cargo test

   Compiling test_asset v0.1.0 (/home/lokicheck/Desktop/test_asset)
warning: unused variable: `result2`
  --> tests/harness.rs:12:9
   |
12 |     let result2 = instance.methods().test_deposit_asset_id_same_generated().call().await.unwrap().value;
   |         ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_result2`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `test_asset` (test "integration_tests") generated 1 warning
    Finished `test` profile [unoptimized + debuginfo] target(s) in 1m 04s
     Running tests/harness.rs (target/debug/deps/integration_tests-c9599d2b0d721b79)

running 1 test
test test_harness ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.53s

This is my terminal running fuelup show

Default host: x86_64-unknown-linux-gnu
fuelup home: /home/lokicheck/.fuelup

installed toolchains
--------------------
latest-x86_64-unknown-linux-gnu (default)
nightly-2024-05-28-x86_64-unknown-linux-gnu
testnet-x86_64-unknown-linux-gnu

active toolchain
----------------
latest-x86_64-unknown-linux-gnu (default)
  forc : 0.60.0
    - forc-client
      - forc-deploy : 0.60.0
      - forc-run : 0.60.0
    - forc-crypto : 0.60.0
    - forc-debug : 0.60.0
    - forc-doc : 0.60.0
    - forc-explore : 0.28.1
    - forc-fmt : 0.60.0
    - forc-lsp : 0.60.0
    - forc-tx : 0.60.0
    - forc-wallet : 0.7.1
  fuel-core : 0.26.0
  fuel-core-keygen : 0.26.0

fuels versions
--------------
forc : 0.62.0
forc-wallet : 0.62.0

Looking at the output for the cargo test it seems that the test is passing and it is just giving the warning.

And for the Println, †he error you are encountering, can you try updating your result and result2 to this

let result = instance.methods().deposit().call().await.unwrap().value;
let result2 = instance.methods().test_deposit_asset_id_same_generated().call().await.unwrap().value;
1 Like

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