Skip to content

Commit

Permalink
update(RingBuffers): add getBufferCardinality to DrawHistory/PrizeDis…
Browse files Browse the repository at this point in the history
…tributionHistory
  • Loading branch information
kamescg committed Oct 6, 2021
1 parent 5967c1a commit 52e6c9a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions contracts/DrawHistory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ contract DrawHistory is IDrawHistory, Manageable {

/* ============ External Functions ============ */

/// @inheritdoc IDrawHistory
function getBufferCardinality() external view override returns (uint32) {
return drawRingBuffer.cardinality;
}

/// @inheritdoc IDrawHistory
function getDraw(uint32 drawId) external view override returns (IDrawBeacon.Draw memory) {
return _draws[_drawIdToDrawIndex(drawRingBuffer, drawId)];
Expand Down
5 changes: 5 additions & 0 deletions contracts/PrizeDistributionHistory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ contract PrizeDistributionHistory is IPrizeDistributionHistory, Manageable {

/* ============ External Functions ============ */

/// @inheritdoc IPrizeDistributionHistory
function getBufferCardinality() external view override returns (uint32) {
return bufferMetadata.cardinality;
}

/// @inheritdoc IPrizeDistributionHistory
function getPrizeDistribution(uint32 _drawId)
external
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/IDrawHistory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ interface IDrawHistory {
*/
event DrawSet(uint32 indexed drawId, IDrawBeacon.Draw draw);

/**
* @notice Read a ring buffer cardinality
* @return Ring buffer cardinality
*/
function getBufferCardinality() external view returns (uint32);

/**
* @notice Read a Draw from the draws ring buffer.
* @dev Read a Draw using the Draw.drawId to calculate position in the draws ring buffer.
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/IPrizeDistributionHistory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ interface IPrizeDistributionHistory {
IPrizeDistributionHistory.PrizeDistribution prizeDistribution
);

/**
* @notice Read a ring buffer cardinality
* @return Ring buffer cardinality
*/
function getBufferCardinality() external view returns (uint32);

/**
* @notice Read newest PrizeDistribution from prize distributions ring buffer.
* @dev Uses nextDrawIndex to calculate the most recently added PrizeDistribution.
Expand Down
7 changes: 7 additions & 0 deletions test/DrawHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ describe('DrawHistory', () => {
await drawHistory.setManager(wallet1.address);
});

describe.only('getBufferCardinality()', () => {
it('should read buffer cardinality set in constructor', async () => {
expect(await drawHistory.getBufferCardinality())
.to.equal(3)
});
})

describe('getNewestDraw()', () => {
it('should error when no draw history', async () => {
await expect(drawHistory.getNewestDraw()).to.be.revertedWith('DRB/future-draw');
Expand Down
9 changes: 8 additions & 1 deletion test/PrizeDistributionHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ describe('PrizeDistributionHistory', () => {
await prizeDistributionHistory.setManager(wallet1.address);
});

describe('getBufferCardinality()', () => {
it('should read buffer cardinality set in constructor', async () => {
expect(await prizeDistributionHistory.getBufferCardinality())
.to.equal(3)
});
})

describe('getNewestPrizeDistribution()', () => {
it('should error when no draw history', async () => {
await expect(prizeDistributionHistory.getNewestPrizeDistribution()).to.be.revertedWith(
Expand Down Expand Up @@ -130,7 +137,7 @@ describe('PrizeDistributionHistory', () => {

// @TODO: Create PrizeDistributionHistory harness smart contract to expose
describe('_estimateDrawId()', () => {
it('should return Draw ID 0 when no history', async () => {});
it('should return Draw ID 0 when no history', async () => { });
});
});

Expand Down

0 comments on commit 52e6c9a

Please sign in to comment.