私はTruffleのテストサービス(モカとチャイを使用していると信じています)を使ってクラウデールの機能をテストする自動テストを書いています。私はテストが非決定論的に失敗する理由を理解することができません(つまり、ランダムな例外を除いてランダムな点で失敗するように見えます)。トリュフルテストを実行するときの非決定的な例外
例:/ 私は私のテストを実行し、時には彼らのすべてが、私は私のテストを実行して、時々、このエラーメッセージが表示されます
を渡す:
✓ deadline is set when beneficiary clicks start
✓ should return a State of 'Funding' after start is clicked (101ms)
✓ should allow someone to invest and record balance
✓ should send 1 ERC20 token to participant (184ms)
✓ softcap should not return reached when amountRaised is smaller
✓ softcap should return reached when amountRaised is bigger
✓ hardcap should not return reached when amountRaised is smaller
✓ hardcap should return reached when amountRaised is bigger
1) should give 1 ETH in change as hard cap was exceeded
> No events were emitted
✓ should return a State of 'Successful' when hardcap reached
✓ beneficiary should be able to withdraw funds
✓ should return a State of 'Finished' when beneficiary has funds
22 passing (2s)
1 failing
1) Contract: Sale should give 1 ETH in change as hard cap was exceeded:
Uncaught AssertionError: deadline was not set after start pressed by beneficiary: expected '0' to not equal 0
at test/2Crowdsale_Test.js:119:14
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
1
truffle(develop)>
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:320098
throw reason;
^
TypeError: Cannot read property 'currentRetry' of undefined
at
/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/runner.js:
552:28
at done
(/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/runnable.js
:295:5)
at
/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/runnable.js:
359:11
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
アサーションは、エラーメッセージが一致していないとしてこれが混乱しています - 変更アサーションは失敗しますが、返されるメッセージは合格した以前のテストの一部です(受取人がクリックを開始すると期限が設定されます)。もう一度テストを実行
私が得た:
✓ approves contract by beneficiary
✓ should return a State of 'Not Started' before start is clicked (134ms)
✓ deadline is set when beneficiary clicks start
✓ should return a State of 'Funding' after start is clicked (98ms)
✓ should allow someone to invest and record balance
✓ should send 1 ERC20 token to participant (143ms)
✓ softcap should not return reached when amountRaised is smaller
✓ softcap should return reached when amountRaised is bigger
✓ hardcap should not return reached when amountRaised is smaller
✓ hardcap should return reached when amountRaised is bigger
1) should give 1 ETH in change as hard cap was exceeded
> No events were emitted
2) should return a State of 'Successful' when hardcap reached
Events emitted during test:
---------------------------
Transfer(_from: <indexed>, _to: <indexed>, _value: 5)
FundTransfer(backer: 0xf17f52151ebef6c7334fad080c5704d77216b732, amount: 5000000000000000000, isContribution: true)
reachedSoftCap(recipient: 0x627306090abab3a6e1400e9345bc60c78a8bef57, totalAmountRaised: 6000000000000000000)
---------------------------
✓ beneficiary should be able to withdraw funds
✓ should return a State of 'Finished' when beneficiary has funds
21 passing (2s)
2 failing
1) Contract: Sale should give 1 ETH in change as hard cap was exceeded:
Uncaught AssertionError: deadline was not set after start pressed by beneficiary: expected '0' to not equal 0
at test/2Crowdsale_Test.js:119:14
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
2) Contract: Sale should return a State of 'Successful' when hardcap reached:
Uncaught AssertionError: hardcap was not met when amountRaised was bigger: expected false to equal true
at test/2Crowdsale_Test.js:195:14
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
2
truffle(develop)>
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:320098
throw reason;
^
TypeError: Cannot set property 'state' of undefined
at
/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/runner.js:
576:20
at done
(/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/runnable.js
:295:5)
at /usr/local/lib/node_modules/truffle/node_modules/mocha/lib/runnable.js:353:11
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
私は今、前のエラーメッセージを持って、今もう一つは、再び、エラーメッセージがアサーションエラーと一致しない場合にスローされます。私が得た4度目のテストを実行する
:前の2に完全に異なる誤りである
✓ should allow someone to invest and record balance
✓ should send 1 ERC20 token to participant (120ms)
✓ softcap should not return reached when amountRaised is smaller
✓ softcap should return reached when amountRaised is bigger
✓ hardcap should not return reached when amountRaised is smaller
✓ hardcap should return reached when amountRaised is bigger
✓ should give 1 ETH in change as hard cap was exceeded (275ms)
✓ should return a State of 'Successful' when hardcap reached (61ms)
✓ beneficiary should be able to withdraw funds
1) should return a State of 'Finished' when beneficiary has funds
> No events were emitted
22 passing (2s)
1 failing
1) Contract: Sale should return a State of 'Finished' when beneficiary has funds:
AssertionError: State of contract was not 'Finished': expected '4' to equal 6
at test/2Crowdsale_Test.js:243:14
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
。これは、以前のテスト(受益者が資金を引き出せるようにすべきである)と同じくらい混乱しています。また、州のテストが6に等しく、このテストに合格します。
テストのたびに、私はトリュフコンソールを終了し、プロジェクトから自分のビルドフォルダを削除し、トリュフコンソールとテストを再入力します(チェーンがリセットされたと仮定できるように)。まず、Dappを通して自分自身でテストするときにこれらの結果を得られないので、意味がありません。また、毎回表示しないでください。ランダムなエラーでランダムな時間がかかるようです。
誰にもこれに問題がありますか?
私は、テストではコールバックまたは約束を使用する必要がありますが、ここではmochaのドキュメントhttps://mochajs.org/#hooksで引用されているように、どちらも使用しないでください。したがって、私の.then()関数は約束が返されるまで待たなければならないのでどこでもdone()を実装していません。 しかし、なぜアサーションエラーが過去のテストのエラーをもたらすのかを完全に理解していますが、毎回同じエラーを返さないのでしょうか? –
はい、ここで述べたように、testrpcはtruffle開発コンソールに自動的に統合されています:https://github.com/trufflesuite/ganache-cli –
私はdone()を使うことについて話していました。あなたの選択でした。約束を返すだけで完璧です。 – Sergeon