Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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