热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

NEAR开发者认证NCDDay3

文章目录Day3课程测试web3资源AssemblyScriptRustDay3课程https:learnnear.clublessonsday-3-testing-web3-n

文章目录

  • Day3课程
    • 测试 web3
    • 资源
      • AssemblyScript
      • Rust


Day3课程

https://learnnear.club/lessons/day-3-testing-web3-ncdl1c4/
https://hackmd.io/@nearly-learning

测试 web3

学习编写智能合约的单元测试和模拟测试。

今天的目标是编写可以合约的单元测试和模拟测试。

核心活动

  • 在下面的资源章节中,选择AssemblyScript或Rust
    • 为列为核心活动的每个合约编写3-5个单元测试

奖励活动
如果您有时间四处逛逛,这里还有更多适合您的东西。

如果您需要更多有关此挑战的想法,请考虑以下事项:

  1. 查找没有单元测试的合约(有很多)并编写它们
  2. 从合约中删除一些(或全部)现有的单元测试并重写它们。
  3. 看看这个小难题,对您来说可能很有趣
    • [Scavenger Hunt Challenge #4] (https://hackmd.io/@nearly-learning/hunt-04)
  4. 从空白文档(或只是样板)开始,然后尝试测试驱动(TDD)合约。

更加深入的探索
如果您感到无所畏惧,那么大约一天之内就可以走上这条路

While simulation tests are an evolving work in progress, we do have a few examples which can help you. The key to understanding simulation tests on NEAR is that you’re testing the Wasm binary. This means the same simulation test configuration will work for Rust and AssemblyScript.

虽然模拟测试是一项不断发展的工作,但我们确实有一些示例可以为您提供帮助。 了解NEAR上的模拟测试的关键在于您正在测试Wasm二进制文件。 这意味着相同的模拟测试配置将适用于Rust和AssemblyScript。

In fact, the exact same simulation tests can be used against a compiled Rust or compiled AssemblyScript contract. Maybe this is obvious once you consider that simulation tests are using the same on-chain virtual machine so everything you do in a simulation test should be 1:1 repeatable on-chain.

实际上,可以对已编译的Rust或已编译的AssemblyScript合约使用完全相同的模拟测试。 一旦您考虑到模拟测试使用的是相同的链上虚拟机,就恨容易理解。因此您在模拟测试中所做的一切都应该在1:1链上虚拟机可重复的。

Heads up, simulation tests must be written in Rust. The examples below will make that clear.

  • NEARly Neighbors has simulation tests
  • Workshop on Cross-contract Calls has simulation tests

资源

记住:今天的活动

  • 您确实需要为每个合约构建(并运行测试,如果可用的话)
  • 你应该试着理解合约中的每一行代码

AssemblyScript

如果你想专注于AssemblyScript, OPEN the list of AssemblyScript contracts

至少3份被标记为核心活动的合同

a)为每个合约编写3-5个新的单元测试,不管它是否已经有单元测试

b)验证测试如预期通过(测试可以通过命令行运行)

单元测试是由as- aspect提供的,语法类似于RSpec。这个库有很好的文档记录,但有时tests for the testing library可能是帮助您快速学习的示例的最佳来源。

near.dev 上几乎所有可用的示例都包括单元测试。
在这里插入图片描述

Rust

请参考原文


推荐阅读
author-avatar
canku
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有