-1

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'
4

1 に答える 1