Skip to content

Commit

Permalink
contract: Fix use of block number in subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Feb 15, 2023
1 parent 7d209d8 commit 974c487
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contract/contracts/Subscriptions.sol
Expand Up @@ -105,7 +105,7 @@ contract Subscriptions is Ownable {
uint128 rate
) public {
require(
subscriptions[user].end <= uint64(block.number) ||
subscriptions[user].end <= uint64(block.timestamp) ||
user == msg.sender,
'active subscription must have ended'
);
Expand Down
35 changes: 35 additions & 0 deletions contract/test/contract.test.ts
Expand Up @@ -425,6 +425,41 @@ describe('Subscriptions contract', () => {
initialBalance.sub(newSubValue)
);
});
it('0xMacro: should allow creating a new sub if there is an expired one', async function () {
const now = await latestBlockTimestamp();
const start = now.add(100);
const end = now.add(500);
const rate = BigNumber.from(5);
const user = subscriber2.address;
await subscribe(
stableToken,
subscriptions,
subscriber1,
start,
end,
rate,
user
);

// advance past subscription end
mineNBlocks(600);
const newNow = await latestBlockTimestamp();
expect(newNow).to.be.gte(end);

const newStart = newNow.add(100);
const newEnd = newNow.add(500);

// Should be able to create another subscription
await subscribe(
stableToken,
subscriptions,
subscriber1,
newStart,
newEnd,
rate,
user
);
});
});
describe('unsubscribe', function () {
it('should allow user to cancel an active subscription', async function () {
Expand Down

0 comments on commit 974c487

Please sign in to comment.