What is the best way to test account balance changes in NEAR smart contracts?

Viewed 105

I am trying to test that an account's NEAR balance increases and decreases. env::account_balance() doesn’t seem to change even with an attached_deposit.

#[test]
fn takes_account_deposit() {
  let mut context = get_context();
  context.attached_deposit = 10000000000000000;
  testing_env!(context.clone());
  println!("Account balance before {}", env::account_balance());
  let mut contract = Contract::default();
  contract.take_deposit();
  println!("Account balance after  {}", env::account_balance());
}
1 Answers

Cross-contract calls in NEAR are asynchronous, so you need to setup a callback for the take_deposit (is my understanding correct that Contract is some other contract?). Learn more about promises and cross-contract calls in the doc

Related