在 Rust 测试中,如何检查帐户的状态(帐户余额)?
例如。我有这个辅助函数:
fn set_context(account_index: usize, is_view: bool, deposit: Amount) {
let context = VMContextBuilder::new()
.signer_account_id(accounts(account_index))
.is_view(is_view)
.attached_deposit(deposit)
.build();
testing_env!(context);
}
然后我的测试包含:
...
let mut contract = Contract::new();
set_context(1, false, near_string_to_yocto("0.3".to_string()));
let recipient = accounts(0);
let _matcher1_offer_result = contract.offer_matching_funds(&recipient);
set_context(2, false, near_string_to_yocto("0.1".to_string()));
let _matcher2_offer_result = contract.offer_matching_funds(&recipient);
// TODO: Assert that this (escrow) contract now contains the correct amount of funds. Assert that the matchers' account balances have decreased appropriately.
我无法在任何文档或存储库中找到示例。
E.g. https://docs.rs/near-sdk/latest/src/near_sdk/test_utils/context.rs.html#10-14 https://docs.rs/near-sdk/latest/src/near_sdk/test_utils/context.rs.html#10-14
由于声誉较低,无法直接评论 Vlad 的帖子,但您需要获取帐户详细信息(例如帐户余额)的方法是account.view_account()
方法。您也可以在这里找到所有相关的帐户方法:https://docs.rs/workspaces/0.4.0/workspaces/struct.Account.html https://docs.rs/workspaces/0.4.0/workspaces/struct.Account.html
Workspaces 文档还不够完善
关于我们如何改进文档有任何反馈吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)