Skip to content

Improvements#2

Open
stpoa wants to merge 8 commits intopragmaticcoders:masterfrom
stpoa:improvements
Open

Improvements#2
stpoa wants to merge 8 commits intopragmaticcoders:masterfrom
stpoa:improvements

Conversation

@stpoa
Copy link

@stpoa stpoa commented Nov 16, 2017

No description provided.

MAX_NUMBER,
LOTTERY_DURATION
LOTTERY_DURATION,
web3.toWei(0.1, 'ether')
Copy link
Contributor

@jksf jksf Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move 0.1 ether to a named constant.

const LOTTERY_DURATION = 10;

const TICKET_FEE_WEI = web3.toWei(0.1, 'ether');
const EXPECTED_TICKET_FEE_WEI = web3.toWei(0.1, 'ether');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a separate const.

it('Should create lotto object with ticketFee', async () => {
const ticketFee = await lotto.ticketFee();
assert.equal(ticketFee, EXPECTED_TICKET_FEE_WEI);
assert.equal(TICKET_FEE_WEI, EXPECTED_TICKET_FEE_WEI);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check ticketFee instead of const.


it('Should exit when ownerCollect is called by not owner user', async () => {
const action = lotto.ownerCollect.bind(lotto, { from: PLAYER });
assertThrowsInvalidOpcode(action);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert to lambda.

@@ -98,8 +98,11 @@ contract MicroLotto {
function ownerCollect() public {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accumulatedValue is resetted in draw() and blocks the funds forever. Split accumulatedValue to separate fields prize and fees.


// TODO: Do you see a problem here?
ticket.account.transfer(profit);
// ticket.account.transfer(profit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't leave commented code

address ticketAccount = ticket.account;

wonPrizes[ticketAccount] = profit;
if (wonPrizes[ticketAccount] > 0) wonPrizes[ticketAccount] += profit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An uninitialized wonPrizes value will have 0 value anyway. No need for if/else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants