1

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

Michael
  • 41,989
  • 11
  • 82
  • 128
shamb0
  • 21
  • 3
  • 1
    Maybe you need to add `-- --nocapture` to your test command. See: https://stackoverflow.com/questions/25106554/why-doesnt-println-work-in-rust-unit-tests – Shawn Tabrizi Oct 15 '20 at 08:48
  • Thanks @ShawnTabrizi suggested command **"cargo +nightly test -- --nocapture"** is working fine ... – shamb0 Oct 15 '20 at 09:18

1 Answers1

2

By default, Rust hides the stdout of successful tests.

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

cargo +nightly test -- --nocapture
Shawn Tabrizi
  • 12,206
  • 1
  • 38
  • 69