gpt4 book ai didi

rust - 如何捕获NEAR samart契约(Contract)日志(env::log)?

转载 作者:行者123 更新时间:2023-12-03 11:35:14 24 4
gpt4 key购买 nike

我想在NEAR Rust智能合约测试运行时(不是终端)中捕获日志(env::log)并检查输出(在测试功能中)。我该怎么做?

最佳答案

尚未提供此功能。这是PR,它将把它介绍给near_sdk https://github.com/near/near-sdk-rs/pull/229。假设您提供了足够的可见性,也许您可​​以仅抓取执行该操作的代码。

/// Returns a copy of logs from VMLogic. Only available in unit tests.
pub fn get_logs() -> Vec<String> {
let blockchain_interface =
env::take_blockchain_interface().expect("Blockchain interface is not set");
let logs = blockchain_interface
.as_mocked_blockchain()
.expect("MockedBlockchain interface expected")
.logs();
env::set_blockchain_interface(blockchain_interface);
logs
}

关于rust - 如何捕获NEAR samart契约(Contract)日志(env::log)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64076936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com