在每次函数调用后更新 block_timestamp

Updating the block_timestamp after each function call

我想在每次函数调用后更新 block_timestamp。 这就是我在测试中每次函数调用后更新上下文的方式。

#[test]
    fn set_then_get_greeting() {
        let context = get_context(vec![], false);
        testing_env!(context);
        let mut contract = Welcome::new();
        contract.set_record("7dd".to_owned());
        let context = get_context(vec![], false);
        testing_env!(context);
        contract.update_record("7dd".to_owned());
        
    }

但是在状态更新时出现以下错误:

panicked at 'called `Result::unwrap()` on an `Err` value: InconsistentStateError(IntegerOverflow)'

如何在每次函数调用时更新 block_timestamp?

代码:https://gateway.ipfs.io/ipfs/QmTNHuRryBoDmTp7wqmNsCcJW8Gu7G6dz3cE3F4pynv6V9

不确定 get_context 在做什么,但您可以在调用 testing_env! 之前修改上下文,然后传递克隆的副本。

例如:

#[test]
    fn set_then_get_greeting() {
        let mut context = get_context(vec![], false);
        testing_env!(context.clone());

        let mut contract = Welcome::new();
        contract.set_record("7dd".to_owned());

        context.block_timestamp += 1000;
        testing_env!(context.clone());

        contract.update_record("7dd".to_owned());
    }

您看到的错误可能与 context 无关,因为它抱怨状态不一致,这可能意味着持久性集合出现问题。

错误是因为 storage_usage 被设置为零。设置为大数即可解决。

https://github.com/near/near-sdk-rs/issues/216