Skip to content

Latest commit

 

History

History
69 lines (52 loc) · 1.43 KB

5.2 附录二:调试智能合约.md

File metadata and controls

69 lines (52 loc) · 1.43 KB

我们推荐使用 VS Code 开发 ASCH 智能合约,原因有三:

  1. 配合 TSLint 插件,TypeScript 开发体验极佳
  2. 众多的插件
  3. 断点调试方便

下面列举三种调试方法。

方法一

  1. 编写 test.ts,引入 mock.ts 和 SimpleContract.ts

  2. 设置 .vscode/launch.json

    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Test Contract",
          "args": [
            "-r",
            "${workspaceFolder}/node_modules/ts-node/register",
            "${workspaceFolder}/test.ts"
          ]
        }
      ]
    }
    
  3. 在 SimpleContract.ts 添加断点

  4. 启动调试

方法二

  1. 引入 ts-jest

    1. npm i ts-jest --save
  2. 配置 jest 的 transform 为 ts-jest

    1. "jest": {
        "transform": {
          "^.+\\.ts$": "ts-jest"
        },
        "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.ts$",
        "moduleFileExtensions": [
          "ts",
          "tsx",
          "js",
          "jsx",
          "json",
          "node"
        ]
      }
  3. 在 __tests__ 目录下编写 xxx.test.ts 测试文件

方法三

基于方法二。

  1. VS Code 安装 Jest Runner 插件
  2. 在 __tests__/xxx.test.ts 某个 it 测试里添加断点,右键选择「Debug Jest」调试单个 it