diff --git a/contracts/MicroLotto.sol b/contracts/MicroLotto.sol index ef94bb3..a3562ef 100644 --- a/contracts/MicroLotto.sol +++ b/contracts/MicroLotto.sol @@ -31,13 +31,14 @@ contract MicroLotto { Random _random, uint _lottoFeePercent, uint _maxNumber, - uint _lotteryDuration + uint _lotteryDuration, + uint _ticketFee ) { require(_maxNumber >= 2); owner = msg.sender; random = _random; - ticketFee = 0.1 ether; // TODO: Make it configurable during deployment + ticketFee = _ticketFee; lottoFeePercent = _lottoFeePercent; maxNumber = _maxNumber; lotteryDuration = _lotteryDuration; diff --git a/migrations/3_micro_lotto.js b/migrations/3_micro_lotto.js index bb8bf0e..1186e39 100644 --- a/migrations/3_micro_lotto.js +++ b/migrations/3_micro_lotto.js @@ -1,18 +1,19 @@ -const Random = artifacts.require("./Random.sol"); -const MicroLotto = artifacts.require("./MicroLotto.sol"); - +const Random = artifacts.require('./Random.sol'); +const MicroLotto = artifacts.require('./MicroLotto.sol'); async function deploy(deployer) { const MAX_NUMBER = 9; const LOTTO_FEE_PERCENT = web3.toWei(0.01, 'ether'); const LOTTERY_DURATION = 10; + const TICKET_FEE_WEI = web3.toWei(0.1, 'ether'); await deployer.deploy( MicroLotto, Random.address, LOTTO_FEE_PERCENT, MAX_NUMBER, - LOTTERY_DURATION + LOTTERY_DURATION, + TICKET_FEE_WEI ); } diff --git a/test/MicroLotto.js b/test/MicroLotto.js index 4cce324..bcdb51e 100644 --- a/test/MicroLotto.js +++ b/test/MicroLotto.js @@ -7,7 +7,7 @@ const { assertThrowsInvalidOpcode, assertNumberEqual, assertValueEqual, - assertValueAlmostEqual + assertValueAlmostEqual, } = require('./Helpers.js'); const MAX_NUMBER = 10; @@ -20,8 +20,9 @@ const LOTTO_FEE_PERCENT_WEI = web3.toWei(LOTTO_FEE_PERCENT, 'ether'); const EXPECTED_PRIZE = TICKET_FEE_WEI - (LOTTO_FEE_PERCENT * TICKET_FEE_WEI); - -contract(`MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FEE_PERCENT}`, accounts => { +contract( + `MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FEE_PERCENT}`, + accounts => { const OWNER = accounts[0]; const PLAYER = accounts[1]; const EXPECTED_NUMBER = 1; @@ -32,7 +33,7 @@ contract(`MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FE beforeEach(async () => { const random = await RandomMock.new(EXPECTED_NUMBER, { - from: OWNER + from: OWNER, }); lotto = await MicroLotto.new( @@ -40,10 +41,16 @@ contract(`MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FE LOTTO_FEE_PERCENT_WEI, MAX_NUMBER, LOTTERY_DURATION, + TICKET_FEE_WEI, { from: OWNER } ); }); + it('Should create lotto object with ticketFee', async () => { + const ticketFee = await lotto.ticketFee(); + assert.equal(ticketFee, TICKET_FEE_WEI); + }); + context(`Given filled ticket on expected number ${EXPECTED_NUMBER}`, () => { let fillTicketResult; let event; @@ -79,7 +86,7 @@ contract(`MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FE beforeEach(async () => { await waitUntilClosed(); drawResult = await lotto.draw({ - from: PLAYER + from: PLAYER, }); }); @@ -110,7 +117,7 @@ contract(`MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FE beforeEach(async () => { await waitUntilClosed(); drawResult = await lotto.draw({ - from: PLAYER + from: PLAYER, }); }); @@ -127,7 +134,6 @@ contract(`MicroLotto with max number of ${MAX_NUMBER} and fee percent ${LOTTO_FE }); - -async function waitUntilClosed () { +async function waitUntilClosed() { await mineBlocks(LOTTERY_DURATION + 1); }