# How do I configure the test to use BASE\_ASSET\_ID?

**URL:** <https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095>\
**Category:** Rust SDK\
**Created:** [September 16, 2023, 6:33pm UTC](https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095 "2023-09-16T18:33:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dade](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/dade/32/1653_2.png) [@dade](https://forum.fuel.network/u/dade)\
**Post date:** [September 16, 2023, 6:33pm UTC](https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095/1 "2023-09-16T18:33:16Z")

</div>

I want to take the counter smart contract in the quick start guide here [https://docs.fuel.network/guides/quickstart/building-a-smart-contract/](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

```auto
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

```auto
#[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

```auto
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

```auto
    // 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…

```auto
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

```

---

<div class="post-metadata">

**Author:** ![calldelegation](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/calldelegation/32/1484_2.png) [@calldelegation](https://forum.fuel.network/u/calldelegation)\
**Post date:** [September 17, 2023, 12:28am UTC](https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095/2 "2023-09-17T00:28:00Z")

</div>

Hi @dade thanks for your question! The function you have written `.trigger_transfer()` is transferring assets out of the contract. However your test does only two things.

1. Deploy the contract
2. Immediately call the `.trigger_transfer()` function.

The problem is not with your wallet or your setup but the test you have written. The contract simply does not have asset’s to transfer out yet. Try funding the contract first. Hope this helps! 🙂

```auto
#[tokio::test]
async fn test_increment() {
    let (instance, _id, wallets) = get_contract_instance().await;

    let wallet_1 = wallets.get(0).unwrap();

    println!("Wallet 1 balance {}", wallet_1.get_asset_balance(&BASE_ASSET_ID).await.unwrap());

    wallet_1.force_transfer_to_contract(&_id, 1_000_000, BASE_ASSET_ID, TxParameters::default()).await;

    instance
        .with_account(wallet_1.clone())
        .unwrap()
        .methods()
        .trigger_transfer()
        .call()
        .await
        .unwrap();
}
```

---

<div class="post-metadata">

**Author:** ![dade](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/dade/32/1653_2.png) [@dade](https://forum.fuel.network/u/dade)\
**Post date:** [September 17, 2023, 5:31am UTC](https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095/3 "2023-09-17T05:31:16Z")

</div>

Thank you @calldelegation for the tip. I was able to test the first contract method `trigger_transfer`, ie the one that transfers the asset back to the contract.

But trying to test the second contract method, `trigger_transferout` the one that transfers the asset to an address does not work.

Here is the updated test

```auto
#[tokio::test]
async fn test_increment() {
    let (instance, _id, wallet_1) = get_contract_instance().await;

    println!("Wallet 1 balance {}", wallet_1.get_asset_balance(&BASE_ASSET_ID).await.unwrap());

    let _ = wallet_1.force_transfer_to_contract(&_id, 1_000_000, BASE_ASSET_ID, TxParameters::default()).await;

    instance.methods().trigger_transferout().call().await.unwrap();

}

```

But this fails with the error

```auto
running 1 test
Wallet 1 balance 1000000000
thread 'test_increment' panicked at tests/harness.rs:54:59:
called `Result::unwrap()` on an `Err` value: RevertTransactionError { reason: "failed transfer to address.", revert_id: 18446744073709486081, receipts: [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: a47c6c1a05138237a6b205304ce57c9d41885200e52ad4a13e2885aff5b5a888, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 9999835, param1: 1965078698, param2: 1, pc: 11632, is: 11632 }, Revert { id: a47c6c1a05138237a6b205304ce57c9d41885200e52ad4a13e2885aff5b5a888, ra: 18446744073709486081, pc: 13704, is: 11632 }, ScriptResult { result: Revert, gas_used: 294 }] }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test test_increment ... FAILED

```

Is transfering to Account different from transferring to Contracts?

---

<div class="post-metadata">

**Author:** ![dade](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/dade/32/1653_2.png) [@dade](https://forum.fuel.network/u/dade)\
**Post date:** [September 17, 2023, 11:27am UTC](https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095/4 "2023-09-17T11:27:57Z")

</div>

> [@dade](#):
>
> Is transfering to Account different from transferring to Contracts?

Seems so. I got it working by using [`transfer_to_address`](https://fuellabs.github.io/sway/master/std/token/fn.transfer_to_address.html) instead

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [October 8, 2023, 7:28am UTC](https://forum.fuel.network/t/how-do-i-configure-the-test-to-use-base-asset-id/3095/5 "2023-10-08T07:28:31Z")

</div>

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