Skip to content

Commit

Permalink
Merge pull request #25 from rayeaster/fix-quantstamp-fixes
Browse files Browse the repository at this point in the history
add more test coverage
  • Loading branch information
GalloDaSballo authored Jul 21, 2022
2 parents d014328 + 270a32c commit 52069cf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
50 changes: 49 additions & 1 deletion tests/lens/test_lens_is_equivalent.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,52 @@ def test_claimBulkTokensOverMultipleEpochsOptimized_basic(initialized_contract,
## Verify you got the entire reward amount
assert token.balanceOf(user) == initial_reward_balance + REWARD_AMOUNT

assert calculated_amount == REWARD_AMOUNT
assert calculated_amount == REWARD_AMOUNT

def test_getClaimableBulkRewards_coverage(initialized_contract, user, fake_vault, token, second_user):
INITIAL_DEPOSIT = 1e18
REWARD_AMOUNT = 1e20
EPOCH = initialized_contract.currentEpoch()

## Add rewards here
token.approve(initialized_contract, MaxUint256, {"from": user})
initialized_contract.addReward(EPOCH, fake_vault, token, REWARD_AMOUNT, {"from": user})

## User didn't deposited, they have 0 points
assert initialized_contract.points(EPOCH, fake_vault, user) == 0

## Because user has the tokens too, we check the balance here
initial_reward_balance = token.balanceOf(user)

## Test revert cases: require(params.epochStart <= params.epochEnd);
claimParams = [EPOCH + 1, EPOCH, fake_vault.address, [token.address]]
with brownie.reverts():
quote = initialized_contract.getClaimableBulkRewards(claimParams, user)

## Test revert cases: require(params.epochEnd < currentEpoch());
claimParams = [EPOCH, EPOCH + 1000, fake_vault.address, [token.address]]
with brownie.reverts():
quote = initialized_contract.getClaimableBulkRewards(claimParams, user)

## Wait the epoch to end
chain.sleep(initialized_contract.SECONDS_PER_EPOCH() + 1)
chain.mine()
claimParams = [EPOCH, EPOCH, fake_vault.address, [token.address]]
quote = initialized_contract.getClaimableBulkRewards(claimParams, user)
after_reward_balance = token.balanceOf(user)
assert after_reward_balance == initial_reward_balance ## no reward here since no deposit

## Only deposit so we get 100% of rewards and claim midway
initialized_contract.notifyTransfer(AddressZero, user, INITIAL_DEPOSIT, {"from": fake_vault})
nxtEPOCH = initialized_contract.currentEpoch()
initialized_contract.addReward(nxtEPOCH, fake_vault, token, REWARD_AMOUNT, {"from": user})
chain.sleep(initialized_contract.SECONDS_PER_EPOCH() + 1)
chain.mine()
initialized_contract.claimReward(nxtEPOCH, fake_vault, token, user, {"from": user})

## Test revert cases: require(pointsWithdrawn[epochId][params.vault][user][token] == 0);
claimParams = [nxtEPOCH, nxtEPOCH, fake_vault.address, [token.address]]
with brownie.reverts():
quote = initialized_contract.getClaimableBulkRewards(claimParams, user)


5 changes: 4 additions & 1 deletion tests/unit/test_accrue_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ def test_revert_if_accrue_future(initialized_contract, user, fake_vault):
initialized_contract.accrueUser(epoch + 1, fake_vault, user)

with brownie.reverts():
initialized_contract.accrueVault(epoch + 1, fake_vault)
initialized_contract.accrueVault(epoch + 1, fake_vault)

with brownie.reverts():
initialized_contract.getVaultTimeLeftToAccrue(epoch + 1000, fake_vault)
11 changes: 11 additions & 0 deletions tests/unit/test_time_to_accrue_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,15 @@ def test_if_wait_one_more_epoch(initialized_contract, user, fake_vault):
epoch_two_end = epoch_two[1]
assert initialized_contract.getUserTimeLeftToAccrue(2, fake_vault, user) == epoch_two_end - epoch_two_start ## Accrue happens at deposit

def test_getUserTimeLeftToAccure_revert(initialized_contract, user, fake_vault):
INITIAL_DEPOSIT = 1e18

EPOCH = 1

deposit_tx = initialized_contract.notifyTransfer(AddressZero, user, INITIAL_DEPOSIT, {"from": fake_vault})
time_of_deposit = deposit_tx.timestamp
## Test revert case: require(epochId <= currentEpoch());
with brownie.reverts():
initialized_contract.getUserTimeLeftToAccrue(EPOCH + 1000, fake_vault, user)


4 changes: 4 additions & 0 deletions tests/unit/test_weird.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def test_zero_balance_epoch_two(initialized_contract, user, fake_vault, token):
## Check that we have non-zero balance and totalSupply for current
assert initialized_contract.getBalanceAtEpoch(initialized_contract.currentEpoch(), fake_vault, user)[0] == INITIAL_DEPOSIT
assert initialized_contract.getTotalSupplyAtEpoch(initialized_contract.currentEpoch(), fake_vault)[0] == INITIAL_DEPOSIT

## Test revert case: require(epochId <= currentEpoch());
with brownie.reverts():
initialized_contract.getTotalSupplyAtEpoch(2000, fake_vault)


def test_add_reward_zero_add(initialized_contract, user, fake_vault, token):
Expand Down

0 comments on commit 52069cf

Please sign in to comment.