-1

What is the right way to use ink3 "self.env().block_timestamp()"

Reference code snippet ( full code is @ https://gist.github.com/shamb0/a1f24cd7981e169cc5b7d1e1b3ec4dd4 )

        pub fn get_bts(&self) -> u64 {
            let bts = self.env().block_timestamp();
            bts
        }

Invoking test execution on this function ends up in the error panicked at 'uninitialized execution context: UninitializedBlocks'.

Complete Console trace

 cargo +nightly test -- --nocapture     
    Finished test [unoptimized + debuginfo] target(s) in 0.04s
     Running target/debug/deps/ink3_spad-ae1376ecf8f75a7e

running 3 tests
test ink3_spad::tests::default_works ... thread 'ok
ink3_spad::tests::bts_works' panicked at 'uninitialized execution context: UninitializedBlocks', $HOME/rusthome/.cargo/registry/src/github.com-1ecc6299db9ec823/ink_env-3.0.0-rc2/src/engine/off_chain/impls.rs:277:14test ink3_spad::tests::it_works ... 
oknote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

test ink3_spad::tests::bts_works ... FAILED

failures:

failures:
    ink3_spad::tests::bts_works

test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--lib'
Michael
  • 41,989
  • 11
  • 82
  • 128
shamb0
  • 21
  • 3

1 Answers1

0

Annotation must be "#[ink::test]" instead of #[test]

        #[ink::test]
        fn bts_works() {
            let ink3_spad = Ink3Spad::new(false);
            assert_eq!(ink3_spad.get(), false);
            let dbg_fmtstr = format!("{:?}", ink3_spad.get_bts() );
            ink_env::debug_println( &dbg_fmtstr );
        }

Thanks @LaurentTrk for pointing me to the solution ...

shamb0
  • 21
  • 3