【问题标题】:Updating the block_timestamp after each function call每次函数调用后更新 block_timestamp
【发布时间】:2020-12-05 06:19:06
【问题描述】:

我想在每次函数调用后更新 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

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您跟进此问题 - 相同的问题和相同的解决方案。这应该是公认的答案。
    【解决方案2】:

    不确定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 无关,因为它抱怨状态不一致,这可能意味着持久性集合出现问题。

    【讨论】:

    • 不,它仍然给出错误。请查看附件代码。
    猜你喜欢
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    相关资源
    最近更新 更多