Ink :: What is the right way to add the debug trace prints | ink_env::debug_println?

423 views Asked by At

Ink :: What is the right way to add the debug trace prints | ink_env::debug_println ?

Was trying ERC20 sample example from https://substrate.dev/substrate-contracts-workshop/#/2/transferring-tokens

        #[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 )
        }

With trace prints, executed the test, but can't see the trace output.

$ 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

Note:: Complete code snippet is at path ...

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

1

There are 1 answers

0
Shawn Tabrizi On

By default, Rust hides the stdout of successful tests.

To override this, use the --nocapture flag when running your test:

cargo +nightly test -- --nocapture