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
}
}