简体   繁体   English

Mod 测试在近区块链的 Rust 智能合约中不起作用

[英]Mod tests not working in Rust smart contract for near blockchain

#[cfg(test)]
mod tests {
    use super::*;
    use near_sdk::MockedBlockchain;
    use near_sdk::{testing_env, VMContext};
    fn get_context(predecessor_account_id: String, storage_usage: u64) -> VMContext {
        VMContext {
            current_account_id: "alice.testnet".to_string(),
            signer_account_id: "jane.testnet".to_string(),
            signer_account_pk: vec![0, 1, 2],
            predecessor_account_id,
            input: vec![],
            block_index: 0,
            block_timestamp: 0,
            account_balance: 0,
            account_locked_balance: 0,
            storage_usage,
            attached_deposit: 0,
            prepaid_gas: 10u64.pow(18),
            random_seed: vec![0, 1, 2],
            is_view: false,
            output_data_receivers: vec![],
            epoch_height: 19,
        }
    }
}

Error:错误: 在此处输入图像描述

CODE FROM: https://docs.near.org/docs/develop/contracts/rust/intro代码来自: https://docs.near.org/docs/develop/contracts/rust/intro

To write tests for smart contracts in rust I referred to this website article, link is pasted above.在 rust 中编写智能合约测试我参考了这篇网站文章,上面粘贴了链接。 Now I copied the boilerplate code for cargo.toml and the test config(code to that is the above - 1st from the top).现在我复制了 cargo.toml 的样板代码和测试配置(上面的代码 - 从顶部开始第一个)。 I get this error which I cannot debug, I am not sure what I am doing wrong.我收到无法调试的错误,我不确定自己做错了什么。

To clarify what others have pointed out in the comments, it looks like you have something like this:为了澄清其他人在评论中指出的内容,您似乎有这样的事情:

struct Foo {
  // whatever
}

impl Foo {
  fn some_function() {
    // whatever
  }

// this closing brace is missing
// }

#[cfg(test)]
mod tests {

}

You cannot define a module inside an impl block, so this out of order brace is causing the "module is not supported in trait s or impl s" error you see.您不能在impl块内定义模块,因此这个无序的大括号会导致您看到“模块在trait s 或impl s 中不受支持”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM