0

Ink :: 添加调试跟踪打印的正确方法是什么?ink_env::debug_println ?

正在尝试来自https://substrate.dev/substrate-contracts-workshop/#/2/transferring-tokens的 ERC20 示例

        #[ink(message)]
        pub fn transfer(&mut self, to: AccountId, value: Balance) -> bool {
            // ACTION: Call the `transfer_from_to` with `from` as `self.env().caller()`
            let source: AccountId = self.env().caller();
            let dbg_msg = format!( "from {:#?} to {:#?}", source, to );
            ink_env::debug_println( &dbg_msg );
            self.transfer_from_to( source , to, value )
        }

使用跟踪打印,执行了测试,但看不到跟踪输出。

$ cargo +nightly test
   Compiling erc20 v0.1.0 (/tmp/tmp.MkRICOxro3/erc20)
    Finished test [unoptimized + debuginfo] target(s) in 0.85s
     Running target/debug/deps/erc20-ac25c678251cab02

running 3 tests
test erc20::tests::balance_works ... ok
test erc20::tests::new_works ... ok
test erc20::tests::transfer_works ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

注意::完整的代码片段位于路径...

https://gist.github.com/shamb0/aee23b7f4789b0cd57cbc1c8f3fa2538

4

1 回答 1

2

默认情况下,Rust 隐藏成功测试的标准输出。

要覆盖它,请--nocapture在运行测试时使用该标志:

cargo +nightly test -- --nocapture
于 2020-10-15T09:47:53.723 回答