I want to take the counter smart contract in the quick start guide here https://docs.fuel.network/guides/quickstart/building-a-smart-contract/ and turn it into a contract where assets can be transferred.
The modified contract now looks like this
contract;
use std::{
address::Address,
call_frames::contract_id,
constants::BASE_ASSET_ID,
identity::Identity,
token::*,
};
storage {
counter: u64 = 0,
}
abi Counter {
#[storage(read, write)]
fn increment();
#[storage(read)]
fn count() -> u64;
#[payable]
fn trigger_transferout();
#[payable]
fn trigger_transfer();
}
impl Counter for Contract {
#[storage(read)]
fn count() -> u64 {
storage.counter.read()
}
#[storage(read, write)]
fn increment() {
let incremented = storage.counter.read() + 1;
storage.counter.write(incremented);
}
#[payable]
fn trigger_transfer() {
// Transfer the asset back to the originating contract
transfer(Identity::ContractId(contract_id()), BASE_ASSET_ID, 1);
}
#[payable]
fn trigger_transferout() {
const RECEIVER = Address::from(0x532ee5fb2cabec472409eb5f9b42b59644edb7bf9943eda9c2e3947305ed5e96);
transfer(Identity::Address(RECEIVER), BASE_ASSET_ID, 1);
}
}
and I modified the test to be like this
#[tokio::test]
async fn test_increment() {
let (instance, _id) = get_contract_instance().await;
instance.methods().trigger_transfer().call().await.unwrap();
}
But when I run the test it fails with
thread 'test_increment' panicked at tests/harness.rs:49:56:
called `Result::unwrap()` on an `Err` value: RevertTransactionError { reason: "NotEnoughBalance", revert_id: 0, receipts: [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: a47c6c1a05138237a6b205304ce57c9d41885200e52ad4a13e2885aff5b5a888, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 9999835, param1: 1187837885, param2: 1, pc: 11632, is: 11632 }, Panic { id: a47c6c1a05138237a6b205304ce57c9d41885200e52ad4a13e2885aff5b5a888, reason: PanicInstruction { reason: NotEnoughBalance, instruction: 1011418176 }, pc: 12568, is: 11632, contract_id: None }, ScriptResult { result: Panic, gas_used: 314 }] }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test test_increment ... FAILED
Based on the error I suspect the issue is in the setup. Basically here
// 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;
let wallet = wallets.pop().unwrap();
I think this needs to be updated such that the wallet has got some amount of base asset.
Question is how do I do this? I have scoured the docs but could not seem to find how…
fuelup show
Default host: aarch64-apple-darwin
fuelup home: /Users/me/.fuelup
installed toolchains
--------------------
beta-3-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
beta-4-aarch64-apple-darwin
active toolchain
-----------------
latest-aarch64-apple-darwin (default)
forc : 0.44.1
- forc-client
- forc-deploy : 0.44.1
- forc-run : 0.44.1
- forc-doc : 0.44.1
- forc-explore : 0.28.1
- forc-fmt : 0.44.1
- forc-index : 0.20.7
- forc-lsp : 0.44.1
- forc-tx : 0.44.1
- forc-wallet : 0.3.0
fuel-core : 0.20.4
fuel-core-keygen : Error getting version string
fuel-indexer : 0.20.7
fuels versions
---------------
forc : 0.45
forc-wallet : 0.45