From 53e9a6292789475a824d24e5664649d5329670cb Mon Sep 17 00:00:00 2001 From: Andrew Gardhouse Date: Wed, 2 May 2018 17:05:19 -0500 Subject: [PATCH 1/2] Lottery tests that use try/catch no longer return false positives --- lottery/test/Lottery.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lottery/test/Lottery.test.js b/lottery/test/Lottery.test.js index f836088f..fe645d7c 100644 --- a/lottery/test/Lottery.test.js +++ b/lottery/test/Lottery.test.js @@ -65,10 +65,10 @@ describe('Lottery Contract', () => { from: accounts[0], value: 0 }); - assert(false); } catch (err) { - assert(err); + return assert(err); } + assert(false); }); it('only manager can call pickWinner', async () => { @@ -76,10 +76,10 @@ describe('Lottery Contract', () => { await lottery.methods.pickWinner().send({ from: accounts[1] }); - assert(false); } catch (err) { - assert(err); + return assert(err); } + assert(false); }); it('sends money to the winner and resets the players array', async () => { From 78e6ecfefaeb0a4c58e8b4b3959624b3951bbafb Mon Sep 17 00:00:00 2001 From: Andrew Gardhouse Date: Wed, 2 May 2018 17:45:41 -0500 Subject: [PATCH 2/2] Adds lottery entrant to pickWinner() test to avoid false positive --- lottery/test/Lottery.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lottery/test/Lottery.test.js b/lottery/test/Lottery.test.js index fe645d7c..b6cab3aa 100644 --- a/lottery/test/Lottery.test.js +++ b/lottery/test/Lottery.test.js @@ -72,6 +72,11 @@ describe('Lottery Contract', () => { }); it('only manager can call pickWinner', async () => { + await lottery.methods.enter().send({ + from: accounts[1], + value: web3.utils.toWei('0.02', 'ether') + }); + try { await lottery.methods.pickWinner().send({ from: accounts[1]