Why can't we print b256 or AssetID in RustSDK test cases

How do you print b256 in test cases? Tried logging in Sway too, doesn’t show anything.

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

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

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();


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


error[E0277]: `FuelCallResponse<Bits256>` doesn't implement `std::fmt::Display`
  --> tests/harness.rs:13:15
13 |     println!("{result}",result);
   |               ^^^^^^^^ `FuelCallResponse<Bits256>` cannot be formatted with the default formatter
   = help: the trait `std::fmt::Display` is not implemented for `FuelCallResponse<Bits256>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `FuelCallResponse<Bits256>` doesn't implement `std::fmt::Display`
  --> tests/harness.rs:14:15
14 |     println!("{result2}",result);
   |               ^^^^^^^^^ `FuelCallResponse<Bits256>` cannot be formatted with the default formatted

Because of the call response, you need to add .value at the end to retrieve the value. The documentation is slightly ambiguous in returning values.

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

The above snippet will fix the problem

1 Like

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