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

Offer validity period - include upper value #697

Merged
merged 10 commits into from
Jul 7, 2023
6 changes: 3 additions & 3 deletions contracts/protocol/clients/voucher/BosonVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable

// Make sure that offer is not expired or voided
(Offer memory offer, OfferDates memory offerDates) = getBosonOffer(_offerId);
require(!offer.voided && (offerDates.validUntil > block.timestamp), OFFER_EXPIRED_OR_VOIDED);
require(!offer.voided && (block.timestamp <= offerDates.validUntil), OFFER_EXPIRED_OR_VOIDED);

// Get the first token to mint
uint256 start = range.start + range.minted;
Expand Down Expand Up @@ -276,7 +276,7 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable

// Make sure that offer is either expired or voided
(Offer memory offer, OfferDates memory offerDates) = getBosonOffer(_offerId);
require(offer.voided || (offerDates.validUntil <= block.timestamp), OFFER_STILL_VALID);
require(offer.voided || (block.timestamp > offerDates.validUntil), OFFER_STILL_VALID);

// Get the first token to burn
uint256 start = (range.lastBurnedTokenId == 0) ? range.start : (range.lastBurnedTokenId + 1);
Expand Down Expand Up @@ -314,7 +314,7 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable
function getAvailablePreMints(uint256 _offerId) external view returns (uint256 count) {
// If offer is expired or voided, return 0
(Offer memory offer, OfferDates memory offerDates) = getBosonOffer(_offerId);
if (offer.voided || (offerDates.validUntil <= block.timestamp)) {
if (offer.voided || (block.timestamp > offerDates.validUntil)) {
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/protocol/facets/ExchangeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase {
* Issues a voucher to the buyer address for non preminted offers.
*
* Reverts if:
* - Offer has been voided
* - Offer has expired
* - Offer is not yet available for commits
* - Offer's quantity available is zero [for non preminted offers]
Expand Down Expand Up @@ -266,7 +265,7 @@ contract ExchangeHandlerFacet is IBosonExchangeHandler, BuyerBase, DisputeBase {
// Make sure offer is available, and isn't void, expired, or sold out
OfferDates storage offerDates = fetchOfferDates(_offerId);
require(block.timestamp >= offerDates.validFrom, OFFER_NOT_AVAILABLE);
require(block.timestamp < offerDates.validUntil, OFFER_HAS_EXPIRED);
require(block.timestamp <= offerDates.validUntil, OFFER_HAS_EXPIRED);

if (!_isPreminted) {
// For non-preminted offers, quantityAvailable must be greater than zero, since it gets decremented
Expand Down
6 changes: 3 additions & 3 deletions test/protocol/ExchangeHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ describe("IBosonExchangeHandler", function () {

it("offer has expired", async function () {
// Go past offer expiration date
await setNextBlockTimestamp(Number(offerDates.validUntil));
await setNextBlockTimestamp(Number(offerDates.validUntil) + 1);

// Attempt to commit to the expired offer, expecting revert
await expect(
Expand Down Expand Up @@ -1355,7 +1355,7 @@ describe("IBosonExchangeHandler", function () {

it("offer has expired", async function () {
// Go past offer expiration date
await setNextBlockTimestamp(Number(offerDates.validUntil));
await setNextBlockTimestamp(Number(offerDates.validUntil) + 1);

// Attempt to commit to the expired offer, expecting revert
await expect(
Expand Down Expand Up @@ -2118,7 +2118,7 @@ describe("IBosonExchangeHandler", function () {

it("offer has expired", async function () {
// Go past offer expiration date
await setNextBlockTimestamp(Number(offerDates.validUntil));
await setNextBlockTimestamp(Number(offerDates.validUntil) + 1);

// Attempt to commit to the expired offer, expecting revert
await expect(
Expand Down
7 changes: 3 additions & 4 deletions test/protocol/clients/BosonVoucherTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ describe("IBosonVoucher", function () {

it("Should be 0 if offer is expired", async function () {
// Skip to after offer expiry
await setNextBlockTimestamp(Number(offerDates.validUntil), true);
await setNextBlockTimestamp(Number(BigInt(offerDates.validUntil) + 1n), true);

// Get available premints from contract
let availablePremints = await bosonVoucher.getAvailablePreMints(offerId);
Expand Down Expand Up @@ -1382,7 +1382,7 @@ describe("IBosonVoucher", function () {
});

context("Transfer of a preminted voucher when owner is assistant", async function () {
let voucherRedeemableFrom, voucherValid, offerValid;
let voucherRedeemableFrom, voucherValid;

beforeEach(async function () {
exchangeId = offerId = "1";
Expand All @@ -1398,7 +1398,6 @@ describe("IBosonVoucher", function () {

voucherRedeemableFrom = offerDates.voucherRedeemableFrom;
voucherValid = offerDurations.voucherValid;
offerValid = offerDates.validUntil;
});

it("Should emit a Transfer event", async function () {
Expand Down Expand Up @@ -1554,7 +1553,7 @@ describe("IBosonVoucher", function () {

it("Transfer preminted voucher, where offer has expired", async function () {
// Skip past offer expiry
await setNextBlockTimestamp(Number(offerValid));
await setNextBlockTimestamp(Number(BigInt(offerDates.validUntil) + 1n));

// Transfer should fail, since protocol reverts
await expect(
Expand Down