Radix: How to check token balance in Rust Scrypto test?

59 Views Asked by At

I am trying to write a Scrypto test to test my Radix Scrypto smart contract.

in Scrypto 0.9.0, the "balance" method shown below has been removed from the Account Component.

    let manifest = ManifestBuilder::new()
        .call_method(compo_addr, "balance", manifest_args!(resource_addr))
        .build();

How can I check my account(compo_addr) balance of a given token address(resource_addr) ?

2

There are 2 best solutions below

1
Jishan Shaikh On

Account component has been removed in favor of TokenAccount component, use it as:

let token_account = ctx.state().get_account(resource_addr)?.get_component::<TokenAccount>()?;
let balance = token_account.get_balance(&compo_addr)?;
0
Russo On
let component_balance: Option<Decimal> = test_runner.account_balance(component_address, resource_address);