3

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());
}
foba
  • 358
  • 3
  • 10

1 Answers1

2

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

Vlad Frolov
  • 7,445
  • 5
  • 33
  • 52
  • it seems like you know the answer to https://stackoverflow.com/q/73171108/470749 I appreciate your help. https://www.near-sdk.io/testing/unit-tests doesn't say. – Ryan Jul 29 '22 at 21:37
  • 1
    @vlad can you update your link the 'the doc' as the link is now broken. – foba Jul 30 '22 at 20:54