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

Truffle Test Tips and other

nakajo2011
November 10, 2018

Truffle Test Tips and other

nakajo2011

November 10, 2018
Tweet

More Decks by nakajo2011

Other Decks in Programming

Transcript

  1. Copyright ©2018 chaintope, Inc. all rights reserved.
    hicon2018
    Truffle Test Tips
    2018/11/10
    chaintope, Inc
    Yukishige Nakajo

    View Slide

  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
    今日話すこと

    View Slide

  3. 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
    今日話すこと

    View Slide

  4. Copyright ©2018 chaintope, Inc. all rights reserved.
    Step - 2
    1. 答え合わせ

    View Slide

  5. Copyright ©2018 chaintope, Inc. all rights reserved.
    Step - 3
    1. 答え合わせ

    View Slide

  6. 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. 答え合わせ

    View Slide

  7. Copyright ©2018 chaintope, Inc. all rights reserved.
    Step - 4
    1. 答え合わせ

    View Slide

  8. 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
    今日話すこと

    View Slide

  9. Copyright ©2018 chaintope, Inc. all rights reserved.
    ・truffle embeded node or ganache-cliの場合
    2. Truffle Testの起動シーケンス

    View Slide

  10. Copyright ©2018 chaintope, Inc. all rights reserved.
    ・ganache-cli以外のnode(like go-ethereum)
    2. Truffle Testの起動シーケンス

    View Slide

  11. 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の起動シーケンス

    View Slide

  12. 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
    今日話すこと

    View Slide

  13. Copyright ©2018 chaintope, Inc. all rights reserved.
     
    3. new()とdeployed()

    View Slide

  14. 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()

    View Slide

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

    View Slide

  16. Copyright ©2018 chaintope, Inc. all rights reserved.
     Contract.deployed()
    ● あまり使ったことはない
    ● インスタンス取得にdeployする必要がないので高速
    ● でも前の状態を保持しているので注意が必要
    3. new()とdeployed()

    View Slide

  17. 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
    今日話すこと

    View Slide

  18. Copyright ©2018 chaintope, Inc. all rights reserved.
     
    4. HowTo Event Test

    View Slide

  19. Copyright ©2018 chaintope, Inc. all rights reserved.
    ● Contract.EventName()なメソッドでEventは定義されて
    いる
    ● 引数は順番に次の3つ
    ● topics : indexedをつけたparameterを絞り込む
    ● term: Eventをキャッチするblock範囲
    ● callback: Filterに関係するeventが発生した時に呼ば
    れる
    4. HowTo Event Test

    View Slide

  20. Copyright ©2018 chaintope, Inc. all rights reserved.
    ● Eventが発生したかどうかは結構重要
    ● Eventが余分に発生していないこともチェックする必要が
    あある
    4. HowTo Event Test

    View Slide

  21. 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
    今日話すこと

    View Slide

  22. Copyright ©2018 chaintope, Inc. all rights reserved.
    5. Dapp Projects test statistic

    View Slide

  23. 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

    View Slide

  24. Copyright ©2018 chaintope, Inc. all rights reserved.
    ちなみに・・・・
    TheDAO has test …...
    https://github.com/slockit/DAO/tree/develop/tests
    5. Dapp Projects test statistic

    View Slide

  25. Copyright ©2018 chaintope, Inc. all rights reserved.
    長時間ありがとうございました!
    おわり

    View Slide