iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 21
0
Modern Web

DApp 開發 - 使用 web3.js系列 第 21

開發 Dapp - 在 Truffle 上除錯 (Day21)

將上一篇的 Store.sol 範例的 set() 函式改為以下內容

function set(uint x) public {
  while(true) {
    myVariable = x;
  }
}

可以模擬出現無限循環的情境

truffle develop

發佈智能合約

migrate

執行智能合約的 set 函示

SimpleStorage.deployed().then(function(instance){return instance.set(4);});

輸出結果

Error: VM Exception while processing transaction: out of gas

修復後,可以透過以下指令更新合約。

migrate --reset

可以透過 truffle develop --log 指令,再開一個主控台看 log。

truffle 內建 debug 工具,使用方式是在 truffle 的主控台輸入以下指令。

// 語法: debug tx-id
debug 0xf36163615f41ef7ed8f4a8f192149a0bf633fe1a2398ce001bf44c43dc7bdda0

會開啟 debug 模式逐行執行。

輸入 n 或按 enter 會跳到下一行,輸入 q 是退出 debug 模式。

原始碼:https://github.com/alincode/simple-storage-debugging


上一篇
開發 Dapp - 使用 Truffle 框架在測試環境發佈智能合約 (Day20)
下一篇
開發 Dapp - Truffle 樣版 (Day22)
系列文
DApp 開發 - 使用 web3.js30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言