Skip to content

Commit

Permalink
Raffle Timing Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptab2100 committed Jun 12, 2021
1 parent 1b8cfc4 commit 15f77fd
Show file tree
Hide file tree
Showing 9 changed files with 21,659 additions and 18,326 deletions.
5,218 changes: 2,609 additions & 2,609 deletions build/contracts/IDO.json

Large diffs are not rendered by default.

242 changes: 121 additions & 121 deletions build/contracts/IStaker.json

Large diffs are not rendered by default.

12,305 changes: 6,723 additions & 5,582 deletions build/contracts/RaffleWrap.json

Large diffs are not rendered by default.

13,269 changes: 7,205 additions & 6,064 deletions build/contracts/RaffleWrapTest.json

Large diffs are not rendered by default.

3,690 changes: 2,106 additions & 1,584 deletions build/contracts/Random.json

Large diffs are not rendered by default.

5,236 changes: 2,879 additions & 2,357 deletions build/contracts/RandomTest.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions contracts/IDOStaker/RaffleWrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ contract RaffleWrap is IDO, Random {
uint256 public ticketPrice = 3 * 10 ** 18; // Price of a ticket(no. of tokens)

modifier raffleParticipationPeriod() {
require(regStarts >= block.timestamp, "Raffle: Can't Participate Now");
require(regStarts <= block.timestamp, "Raffle: Participation Didn't Begin");
require(regStarts + regDuration >= block.timestamp, "Raffle: Participation Ended");
_;
}

modifier raffleResultPeriod() {
require(regStarts <= block.timestamp && isInitialized, "Registration Not Started Yet");
require(regStarts + regDuration >= block.timestamp, "Registration Ended");
require(regStarts + regDuration <= block.timestamp, "Raffle: Participation Didn't End");
require(saleStarts >= block.timestamp, "Raffle: Out Of Time");
_;
}

Expand All @@ -125,6 +126,7 @@ contract RaffleWrap is IDO, Random {

// Buy Tickets
function buyTickets(uint256 _noOfTickets) external raffleParticipationPeriod nonReentrant {
require(!getRegistrationStatus(msg.sender), "Already Participated In IDO");
uint256 nextTicket = ticketsSold;
nativeToken.transferFrom(msg.sender, owner(), _noOfTickets * ticketPrice);

Expand Down
8 changes: 5 additions & 3 deletions contracts/IDOStaker/RaffleWrapTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ contract RaffleWrapTest is IDO, RandomTest {
uint256 public ticketPrice = 3 * 10 ** 18; // Price of a ticket(no. of tokens)

modifier raffleParticipationPeriod() {
require(regStarts >= block.timestamp, "Raffle: Can't Participate Now");
require(regStarts <= block.timestamp, "Raffle: Participation Didn't Begin");
require(regStarts + regDuration >= block.timestamp, "Raffle: Participation Ended");
_;
}

modifier raffleResultPeriod() {
require(regStarts <= block.timestamp && isInitialized, "Registration Not Started Yet");
require(regStarts + regDuration >= block.timestamp, "Registration Ended");
require(regStarts + regDuration <= block.timestamp, "Raffle: Participation Didn't End");
require(saleStarts >= block.timestamp, "Raffle: Out Of Time");
_;
}

Expand All @@ -125,6 +126,7 @@ contract RaffleWrapTest is IDO, RandomTest {

// Buy Tickets
function buyTickets(uint256 _noOfTickets) external raffleParticipationPeriod nonReentrant {
require(!getRegistrationStatus(msg.sender), "Already Participated In IDO");
uint256 nextTicket = ticketsSold;
nativeToken.transferFrom(msg.sender, owner(), _noOfTickets * ticketPrice);

Expand Down
9 changes: 6 additions & 3 deletions test/3-raffle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ contract("RaffleWrap", accounts => {
})

it('Buy Test', async () => {
var initTime = Math.floor(Date.now() / 1000) + 10
var initTime = Math.floor(Date.now() / 1000) + 1
await raffle.initialize(initTime)

await timeout(1)

await polCoin.approve(raffle.address, '100000000000000000000', { from: accounts[0] })
await raffle.buyTickets(5, { from: accounts[0] })
var count1 = (await raffle.addressToTicketCount(accounts[0])).toNumber()
Expand All @@ -60,8 +62,9 @@ contract("RaffleWrap", accounts => {
})

it('Rand Winner Test', async () => {
var initTime = Math.floor(Date.now() / 1000) + 20
var initTime = Math.floor(Date.now() / 1000) + 1
await raffle.initialize(initTime)
await timeout(1)

await polCoin.approve(raffle.address, '100000000000000000000', { from: accounts[0] })
await polCoin.approve(raffle.address, '100000000000000000000', { from: accounts[1] })
Expand All @@ -73,7 +76,7 @@ contract("RaffleWrap", accounts => {
await raffle.buyTickets(30, { from: accounts[2] })
// await raffle.buyTickets(30, { from: accounts[3] })

await timeout(20)
await timeout(48)
await raffle.fulfillTest(
'0x11784bfa961ea00360336b7dfda4504f3e5e01a6035d89a9464ccdf8c73ac1b0',
'77626901581511883625746798795701147174388658559238937904298300184740954966236'
Expand Down

0 comments on commit 15f77fd

Please sign in to comment.