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

Truffle における JS での テスト について

Truffle における JS での テスト について

2018/03/22(木) 第2回ブロックチェーン勉強会@東京でLTした資料です。TruffleにおけるJSでのテストについて簡単にまとめています。

8bb7c9b7323d84b9858e67ae9fc854be?s=128

Katsunori Tanaka

March 23, 2018
Tweet

Transcript

  1. %..DPN-BCPాதࠀయ ୈճϒϩοΫνΣʔϯษڧձ!౦ژ 5SV⒐Fʹ͓͚Δ +4Ͱͷςετʹ͍ͭͯ

  2. X © DMM.com Group ాதࠀయ ࣗݾ঺հ  ࣮࣭ ʹ+0*/ͨͯ͠ લॴଐɿϑϩϯτΤϯυ։ൃ෦

    ໨Լษڧத %..DPN-BCP εϚʔτίϯτϥΫτ։ൃ෦
  3. X © DMM.com Group 5SV⒐FೖΕͯΈ·͢ IUUQUSV⒐FGSBNFXPSLDPN

  4. X © DMM.com Group $ npm install -g truffle

  5. X © DMM.com Group αϯϓϧͱͯ͠ 0⒏DJBM#PYFTͷ NFUBDPJOΛೖΕͯΈ·͢

  6. X © DMM.com Group $ truffle unbox metacoin

  7. X © DMM.com Group KTͷςετίʔυ UFTUNFUBDPJOKT ΛோΊͯΈ·͢

  8. X © DMM.com Group it("should put 10000 MetaCoin in the

    first account", function() { return MetaCoin.deployed().then(function(instance) { return instance.getBalance.call(accounts[0]); }).then(function(balance) { assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); }); }); UFTUNFUBDPJOKT
  9. X © DMM.com Group function getBalance(address addr) public view returns(uint)

    { return balances[addr]; } .FUB$PJOTPM
  10. X © DMM.com Group HFU#BMBODFϝιουͷ ໭Γ஋ͷܕVJOU ͬͯ΋ͪΖΜ+4ʹ͸ແ͍ʜ

  11. X © DMM.com Group KTςετίʔυ಺Ͱ DPOTPMFMPHଧͬͯ ࣮ࡍʹ֬ೝͯ͠Έ·͢

  12. X © DMM.com Group function (balance) { console.log('-----------------------------------'); console.log('▼ getBalanceϝιουͷ໭Γ஋ɿunitܕ

    ▼'); console.log(balance); console.log('-----------------------------------'); console.log('▼ JSͰͷܕ ▼'); console.log(typeof balance); console.log('-----------------------------------'); console.log('▼ valueOf() ͰJSϓϦϛςΟϒܕΛ֬ೝ ▼'); console.log(typeof balance.valueOf()); assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account”); }); UFTUNFUBDPJOKT
  13. X © DMM.com Group ΋΍΋΍ϙΠϯτ

  14. X © DMM.com Group VJOUܕ͕KTςετίʔυͰ͸ɺ#JH/VNCFS0CKFDU #JH/VNCFSͷϓϦϛςΟϒܕ͕TUSJOH ͦ΋ͦ΋ςετίʔυͰɺܕνΣοΫΛ͍ͯ͠ͳ͍ ɹʢBTTFSUTUSJDU&RVBMͷํ͕ྑ͍ؾ͕͢Δʣ TPMJEJUZͰςετίʔυॻ͍ͨํ͕ྑ͍ͷ͔ͳʜʁ ɹʢ·ͩษڧෆ଍ɺ'&ΤϯδχΞʹ͸ͱ͖ͬͭ΍͍͢ʣ

  15. X © DMM.com Group ࠷ޙʹ

  16. X © DMM.com Group ·ͩ·ͩ ΋΍΋΍தʂ ΋ͬͱษڧ͠·͢ʂ

  17. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ 5IBOLZPVGPSZPVSLJOEBUUFOUJPO