Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ticketFee to lotto constructor #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions contracts/MicroLotto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions migrations/3_micro_lotto.js
Original file line number Diff line number Diff line change
@@ -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
);
}

Expand Down
22 changes: 14 additions & 8 deletions test/MicroLotto.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
assertThrowsInvalidOpcode,
assertNumberEqual,
assertValueEqual,
assertValueAlmostEqual
assertValueAlmostEqual,
} = require('./Helpers.js');

const MAX_NUMBER = 10;
Expand All @@ -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;
Expand All @@ -32,18 +33,24 @@ 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(
random.address,
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;
Expand Down Expand Up @@ -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,
});
});

Expand Down Expand Up @@ -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,
});
});

Expand All @@ -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);
}