Skip to content

Commit

Permalink
Renamed drawPrize instances to prizeDistributor
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Oct 6, 2021
1 parent 800bf25 commit f955bbd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions contracts/interfaces/IDrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ interface IDrawCalculator {
IDrawHistory indexed drawHistory,
IPrizeDistributionHistory indexed prizeDistributionHistory);

///@notice Emitted when the drawPrize is set/updated
event PrizeDistributorSet(PrizeDistributor indexed drawPrize);
///@notice Emitted when the prizeDistributor is set/updated
event PrizeDistributorSet(PrizeDistributor indexed prizeDistributor);

/**
* @notice Calculates the prize amount for a user for Multiple Draws. Typically called by a PrizeDistributor.
Expand Down
4 changes: 2 additions & 2 deletions deploy/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ module.exports = async (hardhat) => {
displayResult('DrawCalculator', drawCalculatorResult);

cyan('\nDeploying PrizeDistributor...');
const drawPrizeResult = await deploy('PrizeDistributor', {
const prizeDistributorResult = await deploy('PrizeDistributor', {
from: deployer,
args: [deployer, ticketResult.address, drawCalculatorResult.address],
});
displayResult('PrizeDistributor', drawPrizeResult);
displayResult('PrizeDistributor', prizeDistributorResult);

cyan('\nDeploying PrizeSplitStrategy...');
const prizeSplitStrategyResult = await deploy('PrizeSplitStrategy', {
Expand Down
4 changes: 2 additions & 2 deletions test/DrawHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ describe('DrawHistory', () => {

describe('pushDraw()', () => {
it('should fail to create a new draw when called from non-draw-manager', async () => {
const drawPrizeWallet2 = drawHistory.connect(wallet2);
const prizeDistributorWallet2 = drawHistory.connect(wallet2);

await expect(drawPrizeWallet2.pushDraw(newDraw({ drawId: 1 }))).to.be.revertedWith(
await expect(prizeDistributorWallet2.pushDraw(newDraw({ drawId: 1 }))).to.be.revertedWith(
'Manageable/caller-not-manager',
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/PrizeDistributionHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ describe('PrizeDistributionHistory', () => {
});

it('should fail to create a new draw when called from non-draw-manager', async () => {
const drawPrizeWallet2 = prizeDistributionHistory.connect(wallet2);
const prizeDistributorWallet2 = prizeDistributionHistory.connect(wallet2);

await expect(
drawPrizeWallet2.pushPrizeDistribution(1, newPrizeDistribution()),
prizeDistributorWallet2.pushPrizeDistribution(1, newPrizeDistribution()),
).to.be.revertedWith('Manageable/caller-not-manager-or-owner');
});

Expand Down
60 changes: 30 additions & 30 deletions test/PrizeDistributor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('PrizeDistributor', () => {
let wallet3: any;
let dai: Contract;
let ticket: Contract;
let drawPrize: Contract;
let prizeDistributor: Contract;
let drawCalculator: MockContract;

before(async () => {
Expand All @@ -31,15 +31,15 @@ describe('PrizeDistributor', () => {
let IDrawCalculator = await artifacts.readArtifact('IDrawCalculator');
drawCalculator = await deployMockContract(wallet1, IDrawCalculator.abi);

const drawPrizeFactory: ContractFactory = await ethers.getContractFactory('PrizeDistributor');
const prizeDistributorFactory: ContractFactory = await ethers.getContractFactory('PrizeDistributor');

drawPrize = await drawPrizeFactory.deploy(
prizeDistributor = await prizeDistributorFactory.deploy(
wallet1.address,
ticket.address,
drawCalculator.address,
);

await ticket.mint(drawPrize.address, toWei('1000'));
await ticket.mint(prizeDistributor.address, toWei('1000'));
});

/* =============================== */
Expand All @@ -49,19 +49,19 @@ describe('PrizeDistributor', () => {
describe('Getter Functions', () => {
describe('getDrawCalculator()', () => {
it('should succeed to read an empty Draw ID => DrawCalculator mapping', async () => {
expect(await drawPrize.getDrawCalculator()).to.equal(drawCalculator.address);
expect(await prizeDistributor.getDrawCalculator()).to.equal(drawCalculator.address);
});
});

describe('getDrawPayoutBalanceOf()', () => {
it('should return the user payout for draw before claiming a payout', async () => {
expect(await drawPrize.getDrawPayoutBalanceOf(wallet1.address, 0)).to.equal('0');
expect(await prizeDistributor.getDrawPayoutBalanceOf(wallet1.address, 0)).to.equal('0');
});
});

describe('getToken()', () => {
it('should succesfully read global token variable', async () => {
expect(await drawPrize.getToken()).to.equal(ticket.address);
expect(await prizeDistributor.getToken()).to.equal(ticket.address);
});
});
});
Expand All @@ -72,29 +72,29 @@ describe('PrizeDistributor', () => {
describe('Setter Functions', () => {
describe('setDrawCalculator()', () => {
it('should fail to set draw calculator from unauthorized wallet', async () => {
const drawPrizeUnauthorized = drawPrize.connect(wallet2);
const prizeDistributorUnauthorized = prizeDistributor.connect(wallet2);
await expect(
drawPrizeUnauthorized.setDrawCalculator(AddressZero),
prizeDistributorUnauthorized.setDrawCalculator(AddressZero),
).to.be.revertedWith('Ownable/caller-not-owner');
});

it('should succeed to set new draw calculator for target draw id as owner', async () => {
expect(await drawPrize.setDrawCalculator(wallet2.address))
.to.emit(drawPrize, 'DrawCalculatorSet')
expect(await prizeDistributor.setDrawCalculator(wallet2.address))
.to.emit(prizeDistributor, 'DrawCalculatorSet')
.withArgs(wallet2.address);
});

it('should not allow a zero calculator', async () => {
await expect(drawPrize.setDrawCalculator(AddressZero)).to.be.revertedWith(
await expect(prizeDistributor.setDrawCalculator(AddressZero)).to.be.revertedWith(
'PrizeDistributor/calc-not-zero',
);
});

it('should succeed to update draw calculator for target draw id as owner', async () => {
await drawPrize.setDrawCalculator(wallet2.address);
await prizeDistributor.setDrawCalculator(wallet2.address);

expect(await drawPrize.setDrawCalculator(wallet3.address))
.to.emit(drawPrize, 'DrawCalculatorSet')
expect(await prizeDistributor.setDrawCalculator(wallet3.address))
.to.emit(prizeDistributor, 'DrawCalculatorSet')
.withArgs(wallet3.address);
});
});
Expand All @@ -109,8 +109,8 @@ describe('PrizeDistributor', () => {
.withArgs(wallet1.address, [1], '0x')
.returns([toWei('10')]);

await expect(drawPrize.claim(wallet1.address, [1], '0x'))
.to.emit(drawPrize, 'ClaimedDraw')
await expect(prizeDistributor.claim(wallet1.address, [1], '0x'))
.to.emit(prizeDistributor, 'ClaimedDraw')
.withArgs(wallet1.address, 1, toWei('10'));
});

Expand All @@ -120,10 +120,10 @@ describe('PrizeDistributor', () => {
.returns([toWei('10')]);

// updated
await drawPrize.claim(wallet1.address, [0], '0x');
await prizeDistributor.claim(wallet1.address, [0], '0x');

// try again: should fail!
await expect(drawPrize.claim(wallet1.address, [0], '0x')).to.be.revertedWith(
await expect(prizeDistributor.claim(wallet1.address, [0], '0x')).to.be.revertedWith(
'PrizeDistributor/zero-payout',
);
});
Expand All @@ -134,9 +134,9 @@ describe('PrizeDistributor', () => {
.withArgs(wallet1.address, [1], '0x')
.returns([toWei('10')]);

await drawPrize.claim(wallet1.address, [1], '0x');
await prizeDistributor.claim(wallet1.address, [1], '0x');

expect(await drawPrize.getDrawPayoutBalanceOf(wallet1.address, 1)).to.equal(
expect(await prizeDistributor.getDrawPayoutBalanceOf(wallet1.address, 1)).to.equal(
toWei('10'),
);

Expand All @@ -146,11 +146,11 @@ describe('PrizeDistributor', () => {
.returns([toWei('20')]);

// try again; should reward diff
await expect(drawPrize.claim(wallet1.address, [1], '0x'))
.to.emit(drawPrize, 'ClaimedDraw')
await expect(prizeDistributor.claim(wallet1.address, [1], '0x'))
.to.emit(prizeDistributor, 'ClaimedDraw')
.withArgs(wallet1.address, 1, toWei('10'));

expect(await drawPrize.getDrawPayoutBalanceOf(wallet1.address, 1)).to.equal(
expect(await prizeDistributor.getDrawPayoutBalanceOf(wallet1.address, 1)).to.equal(
toWei('20'),
);
});
Expand All @@ -160,32 +160,32 @@ describe('PrizeDistributor', () => {
let withdrawAmount: BigNumber = toWei('100');

beforeEach(async () => {
await dai.mint(drawPrize.address, toWei('1000'));
await dai.mint(prizeDistributor.address, toWei('1000'));
});

it('should fail to withdraw ERC20 tokens as unauthorized account', async () => {
expect(
drawPrize
prizeDistributor
.connect(wallet3)
.withdrawERC20(dai.address, wallet1.address, withdrawAmount),
).to.be.revertedWith('Ownable/caller-not-owner');
});

it('should fail to withdraw ERC20 tokens if recipient address is address zero', async () => {
await expect(
drawPrize.withdrawERC20(dai.address, AddressZero, withdrawAmount),
prizeDistributor.withdrawERC20(dai.address, AddressZero, withdrawAmount),
).to.be.revertedWith('PrizeDistributor/recipient-not-zero-address');
});

it('should fail to withdraw ERC20 tokens if token address is address zero', async () => {
await expect(
drawPrize.withdrawERC20(AddressZero, wallet1.address, withdrawAmount),
prizeDistributor.withdrawERC20(AddressZero, wallet1.address, withdrawAmount),
).to.be.revertedWith('PrizeDistributor/ERC20-not-zero-address');
});

it('should succeed to withdraw ERC20 tokens as owner', async () => {
await expect(drawPrize.withdrawERC20(dai.address, wallet1.address, withdrawAmount))
.to.emit(drawPrize, 'ERC20Withdrawn')
await expect(prizeDistributor.withdrawERC20(dai.address, wallet1.address, withdrawAmount))
.to.emit(prizeDistributor, 'ERC20Withdrawn')
.withArgs(dai.address, wallet1.address, withdrawAmount);
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/features/support/PoolEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function PoolEnv() {

this.drawCalculator = async () => await ethers.getContract('DrawCalculator');

this.drawPrize = async (wallet) => (await ethers.getContract('PrizeDistributor')).connect(wallet);
this.prizeDistributor = async (wallet) => (await ethers.getContract('PrizeDistributor')).connect(wallet);

this.rng = async () => await ethers.getContract('RNGServiceStub');

Expand Down Expand Up @@ -76,7 +76,7 @@ function PoolEnv() {
debug(`Bought tickets`);
};

this.buyTicketsForPrizeDistributor = async function ({ user, tickets, drawPrize }) {
this.buyTicketsForPrizeDistributor = async function ({ user, tickets, prizeDistributor }) {
debug(`Buying tickets...`);
const owner = await this.wallet(0);
let wallet = await this.wallet(user);
Expand All @@ -100,9 +100,9 @@ function PoolEnv() {
await prizePool.depositTo(wallet.address, amount, this.overrides);

debug(`Bought tickets`);
ticket.transfer(drawPrize, amount);
ticket.transfer(prizeDistributor, amount);

debug(`Transfer tickets to drawPrize`);
debug(`Transfer tickets to prizeDistributor`);
};

this.expectUserToHaveTickets = async function ({ user, tickets }) {
Expand All @@ -123,10 +123,10 @@ function PoolEnv() {

this.claim = async function ({ user, drawId, picks }) {
const wallet = await this.wallet(user);
const drawPrize = await this.drawPrize(wallet);
const prizeDistributor = await this.prizeDistributor(wallet);
const encoder = ethers.utils.defaultAbiCoder;
const pickIndices = encoder.encode(['uint256[][]'], [[picks]]);
await drawPrize.claim(wallet.address, [drawId], pickIndices);
await prizeDistributor.claim(wallet.address, [drawId], pickIndices);
};

this.withdraw = async function ({ user, tickets }) {
Expand Down
2 changes: 1 addition & 1 deletion test/features/ticket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Tickets', () => {
await env.buyTicketsForPrizeDistributor({
user: 1,
tickets: 100,
drawPrize: (await env.drawPrize()).address,
prizeDistributor: (await env.prizeDistributor()).address,
});

const wallet = await env.wallet(1);
Expand Down

0 comments on commit f955bbd

Please sign in to comment.