I am adapting the docs in calling a payable function with base asset and using this code snippet to call payable function
// 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,wallets) = get_contract_instance().await;
let wallet_1 = wallets.get(0).unwrap();
let call_params = CallParameters::default().with_amount(1);
// help here
let result= instance.clone().with_account(wallet_1.clone()).methods().deposit().append_variable_outputs(1).call_params(call_params).unwrap().call().await.call().unwrap();
let result2 = instance.methods().test_deposit_asset_id_same_generated().call().await.unwrap().value;
assert_eq!(result, result2);
}
async fn get_contract_instance() -> (MyContract<WalletUnlocked>, ContractId,Vec<WalletUnlocked>) {
// 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(),wallets)
}
This is my main.sw
// 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()-> b256;
#[storage(read)]
fn test_deposit_asset_id_same_generated() -> b256;
}
impl MyContract for Contract {
#[storage(read, write), payable]
fn deposit() -> b256 {
let owner = msg_sender().unwrap();
let asset_id = msg_asset_id().bits();
let address_from_b256: Address = Address::from(asset_id);
asset_id
}
#[storage(read)]
fn test_deposit_asset_id_same_generated() -> b256 {
let token_id = "b256::zero()";
let token_address = AssetId::base();
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);
asset_id
}
}
This is the error:
error[E0599]: the method `methods` exists for struct `MyContract<&WalletUnlocked>`, but its trait bounds were not satisfied
--> tests/harness.rs:12:57
|
3 | abigen!(Contract(name="MyContract", abi="out/debug/test_asset-abi.json"));
| ------------------------------------------------------------------------- method `methods` not found for this struct
...
12 | let result= instance.clone().with_account(wallet_1).methods().deposit().append_variable_outputs(1).call_params(call_params).unwrap().call().await.call().unwrap();
| ^^^^^^^ method cannot be called on `MyContract<&WalletUnlocked>` due to unsatisfied trait bounds