使用ink3“self.env().block_timestamp()”的正确方法是什么
参考代码片段(完整代码为@https ://gist.github.com/shamb0/a1f24cd7981e169cc5b7d1e1b3ec4dd4)
pub fn get_bts(&self) -> u64 {
let bts = self.env().block_timestamp();
bts
}
在此函数上调用测试执行最终会在 'uninitialized execution context: UninitializedBlocks' 处出现恐慌错误。
完整的控制台跟踪
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'