Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Truffle Test Tips and other

Avatar for nakajo2011 nakajo2011
November 10, 2018

Truffle Test Tips and other

Avatar for nakajo2011

nakajo2011

November 10, 2018
Tweet

More Decks by nakajo2011

Other Decks in Programming

Transcript

  1. Copyright ©2018 chaintope, Inc. all rights reserved. Truffle Test Tips

    1. 答え合わせ 2. Truffle Testの起動シーケンス 3. new()とdeployed() 4. HowTo Event Test 5. Dapp Projects test statistic 今日話すこと
  2. Copyright ©2018 chaintope, Inc. all rights reserved. Truffle Test Tips

    1. 答え合わせ 2. Truffle Testの起動シーケンス 3. new()とdeployed() 4. HowTo Event Test 5. Dapp Projects test statistic 今日話すこと
  3. Copyright ©2018 chaintope, Inc. all rights reserved. # Analysis result

    for BatchOverFlowToken: ~~ snip ~~ ==== Integer Overflow ==== SWC ID: 101 Type: Warning Contract: BatchOverFlowToken Function name: batchTransfer(address[],uint256) PC address: 2599 -------------------- In file: BatchOverFlowToken.sol:20 uint256(cnt) * _value -------------------- 1. 答え合わせ
  4. Copyright ©2018 chaintope, Inc. all rights reserved. Truffle Test Tips

    1. 答え合わせ 2. Truffle Testの起動シーケンス 3. new()とdeployed() 4. HowTo Event Test 5. Dapp Projects test statistic 今日話すこと
  5. Copyright ©2018 chaintope, Inc. all rights reserved. ・truffle embeded node

    or ganache-cliの場合 2. Truffle Testの起動シーケンス
  6. Copyright ©2018 chaintope, Inc. all rights reserved. Truffleではクリーンな環境を作成する https://truffleframework.com/docs/truffle/testing/testing-your-contracts#clean-room-environment 1.

    ganache-cli使う時と、go-ethereumなどを使う時で動作 が異なるので注意 2. コンパイルが通らないとNG a. solidity編集中にちょっとテストを。。ができない 3. Migrationが通らないとNG a. migration fileを作っている場合は特に注意 2. Truffle Testの起動シーケンス
  7. Copyright ©2018 chaintope, Inc. all rights reserved. Truffle Test Tips

    1. 答え合わせ 2. Truffle Testの起動シーケンス 3. new()とdeployed() 4. HowTo Event Test 5. Dapp Projects test statistic 今日話すこと
  8. Copyright ©2018 chaintope, Inc. all rights reserved.  Contract.new() • 新しくsmart

    contractのインスタンスを生成する • つまりnetworkにdeployされる • 基本的にはこれを使って書く • new()するたびにcontract addressは変わるので注意 • deployに膨大なgasを使うContractの場合、gasが不足 するかもしれないので注意 • その場合はgasPrice=1とかにしちゃえばいい 3. new()とdeployed()
  9. Copyright ©2018 chaintope, Inc. all rights reserved.  Contract.deployed() • 事前にmigrationでdeployされたSmart

    Contractのイン スタンスが帰ってくる • truffle devの時は基本的に使えない • ganache-cliの時は自分でmigrationを事前にする必 要がある 3. new()とdeployed()
  10. Copyright ©2018 chaintope, Inc. all rights reserved.  Contract.deployed() • あまり使ったことはない

    • インスタンス取得にdeployする必要がないので高速 • でも前の状態を保持しているので注意が必要 3. new()とdeployed()
  11. Copyright ©2018 chaintope, Inc. all rights reserved. Truffle Test Tips

    1. 答え合わせ 2. Truffle Testの起動シーケンス 3. new()とdeployed() 4. HowTo Event Test 5. Dapp Projects test statistic 今日話すこと
  12. Copyright ©2018 chaintope, Inc. all rights reserved. • Contract.EventName()なメソッドでEventは定義されて いる

    • 引数は順番に次の3つ • topics : indexedをつけたparameterを絞り込む • term: Eventをキャッチするblock範囲 • callback: Filterに関係するeventが発生した時に呼ば れる 4. HowTo Event Test
  13. Copyright ©2018 chaintope, Inc. all rights reserved. • Eventが発生したかどうかは結構重要 •

    Eventが余分に発生していないこともチェックする必要が あある 4. HowTo Event Test
  14. Copyright ©2018 chaintope, Inc. all rights reserved. Truffle Test Tips

    1. 答え合わせ 2. Truffle Testの起動シーケンス 3. new()とdeployed() 4. HowTo Event Test 5. Dapp Projects test statistic 今日話すこと
  15. Copyright ©2018 chaintope, Inc. all rights reserved. • Research 20

    Dapps • Make test projects: 4 • Not have test projects: 9 • Not found repository: 7  Has Test Project is 30 % 5. Dapp Projects test statistic
  16. Copyright ©2018 chaintope, Inc. all rights reserved. ちなみに・・・・ TheDAO has

    test …... https://github.com/slockit/DAO/tree/develop/tests 5. Dapp Projects test statistic