트러 플에서 테스트 서비스 (모카와 차이를 사용한다고 생각합니다)를 사용하여 crowdsale 기능을 테스트하기 위해 자동 테스트를 작성했습니다. 테스트가 비 결정적으로 실패하는 이유를 이해하는 데 문제가 있습니다. 즉, 무작위 예외로 임의의 지점에서 오류가 발생하는 것 같습니다.트러 플 테스트를 실행할 때 비 결정적 예외가 발생했습니다
예는/ 나는 내 테스트를 실행하고 때로는 그들은 모두
내가 내 테스트를 실행하고 때로는이 오류 메시지가 얻을 통과 : 어설 션 오류 메시지가 일치하지 않는
✓ 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)
내가 지금 이전 오류 메시지가 다시 오류 메시지가 어설 션 오류가 일치하지 않을 때 지금 다른 예외 : 테스트를 다시 실행
나는 얻었다. 내가 가진 네 번째 시간 동안 테스트를 실행
: 앞의 두 완전히 다른 오류가
✓ 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를 통해 직접 테스트 할 때 이러한 결과를 얻지 못해서 의미가 없습니다. 둘째, 매번 나타나지 마십시오. 임의의 오류가있는 임의의 시간 인 것 같습니다.
다른 사람이 문제가 있습니까?
테스트에서 콜백 또는 약속 중 하나를 사용하고 모카 문서 (https://mochajs.org/#hooks)에서 인용 한 것처럼 함께 사용해서는 안된다는 인상을 받았습니다. 따라서, 내 .then() 함수는 약속이 반환 될 때까지 기다려야하므로 done()을 구현하지 않았습니다. 그러나 어설 션 오류로 인해 이전 테스트에 오류가 발생하는 이유는 무엇입니까? 그렇다고하더라도 매번 동일한 오류가 반환되지는 않습니까? –
예, testrpc는 이제 여기에 명시된 바와 같이 트 뤼프 개발 콘솔에 자동으로 통합됩니다. https://github.com/trufflesuite/ganache-cli –
done()을 사용하거나 약속을 반환하는 것에 대해 이야기했습니다. 너의 선택이었다. 오직 약속을 되 돌리는 것이 완벽합니다. – Sergeon