- test/ERC20Farmable.js
- test/behaviors/ERC20Farmable.behavior.js
- should behave like farmable
- farm
- userFarms
- exit
- deposit
- Staker w/o tokens joins on 1st week and adds token on 2nd
- Two stakers with the same stakes wait 1 w
- Two stakers with the different (1:3) stakes wait 1 w
- Two stakers with the different (1:3) stakes wait 2 weeks
- One staker on 1st and 3rd weeks farming with gap
- One staker on 1st and 3rd weeks farming with gap + claim in the middle
- One staker on 1st and 3rd weeks farming with gap + exit/farm in the middle
- One staker on 1st and 3rd weeks farming with gap + exit/claim in the middle
- Three stakers with the different (1:3:5) stakes wait 3 weeks
- Three stakers with the different (1:3:5) stakes wait 3 weeks for 1 farming event
- Notify Reward Amount before prev farming finished
- transfers
- should behave like farmable
- test/FarmingPool.js
- startFarming
- name
- symbol
- decimals
- mint
- burn
- deposit
- Two stakers with the same stakes wait 1 w
- Two stakers with the different (1:3) stakes wait 1 w
- Two stakers with the different (1:3) stakes wait 2 weeks
- One staker on 1st and 3rd weeks farming with gap
- One staker on 1st and 3rd weeks farming with gap + claim in the middle
- Three stakers with the different (1:3:5) stakes wait 3 weeks + 1 second
- Three stakers with the different (1:3:5) stakes wait 3 weeks
- One staker on 2 durations with gap
- Notify Reward Amount from mocked distribution to 10,000
- Thrown with Period too large
- Thrown with Amount too large
- Notify Reward Amount before prev farming finished
- transfer
Generic farming scenarios
Farm initialization scenarios
Test Scenario Checks that only distributor may launch farming. "Distributor" is the only account that offers farming reward. Initial setup
wallet1
- distributor accountwallet2
- non-distributor account
Test Steps
Start farming using wallet2
Expected results
Revert with error 'F: access denied'
.
Test Scenario
Check that farming period is of uint40
size.
Test Steps Start farming using 2^40^ as farming period.
Expected results
Revert with error 'FA: period too large'
.
Test Scenario
Check that farming amount is under uint192
Test Steps Start farming using 2^192^ as farming reward.
Expected results
Revert with error 'FA: amount too large'
.
Token's claim scenarios
Test Scenario Checks that farming reward can be claimed with the regular scenario 'join - farm - claim'. Initial setup
farm
started farming for 1 day with 1000 units rewardwallet1
has 1000 unit of farmable token and joined the farm
Test Steps
- Fast-forward time to 1 day and 1 hour
- Claim reward for
wallet1
Expected results
wallet1
reward token balance equals 1000
Test Scenario Checks that non-farming wallet doesn't get a reward Initial setup
farm
started farming for 1 day with 1000 units rewardwallet1
has 1000 unit of farmable token and joined the farmwallet2
hasn't joined the farm
Test Steps
- Fast-forward time to 1 day and 1 hour
- Claim reward for
wallet2
Expected results
wallet2
gift token balance doesn't change after claim
Farm's claim scenarios
Test Scenario
Ensure that claimFor
can be called only by farmable token contract
Initial setup
wallet1
has 1000 unit of farmable token and joined the farmwallet2
has 1000 unit of farmable token and joined the farm
Test Steps
Call farm's claimFor
for wallet1
Expected results
Revert with error 'ERC20: access denied'
Behavior test scenarios
Wallet joining scenarios
Test Scenario Checks if farm's total supply is updated after a wallet joins
Initial setup
wallet1
has 1000 unit of farmable token but has not joined the farm
Test Steps
wallet1
joins the farm
Expected results Farm's total supply equals 1000
Test Scenario Checks if farm's total supply is decreased after a wallet balance decreased Initial setup
wallet1
has 1000 unit of farmable token and joined the farmwallet2
has no farmable token and hasn't joined the farm
Test Steps
Transfer 600 units from wallet1
to wallet2
Expected results
Farm's total supply decreased and equals to 400
Test Scenario Checks if farm's total supply is increased after a wallet balance increased Initial setup
wallet1
has 1000 unit of farmable token and joined the farmwallet2
has 1000 unit of farmable token and hasn't joined the farm
Test Steps
Transfer 500 units from wallet2
to wallet1
Expected results
Farm's total supply increased and equals to 1500
Test Scenario Checks if farm's total supply is unchaged after a transfer between farming wallets Initial setup
wallet1
has 1000 unit of farmable token and joined the farmwallet2
has 1000 unit of farmable token and joined the farm
Test Steps
Transfer 500 units from wallet1
to wallet2
Expected results
Farm's total supply remains unchanged and equals to 400
Test Scenario Ensure that wallet can't join the same farm twice Initial setup
wallet1
has 1000 unit of farmable token and has joined the farm
Test Steps
Join wallet1
to the farm
Expected results
Reverts with error 'ERC20Farmable: already farming'
Check all farms a user is farming scenarios
Test Scenario Check farms list a user farming is returned correctly for the wallet
Initial setup
wallet1
has 1000 unit of farmable token and joined the only farm
Test Steps
Get all farms for wallet1
Expected results
- Number of farms returned is 1
- Address of the farm is the farm's address
wallet1
joined during setup
Tokens farming exit scenarios
Test Scenario Checks that farm's total supply decreases after a user quits farming
Initial setup
farm
has not started farmingwallet1
has 1000 unit of farmable token and joined thefarm
Test Steps
wallet1
quits the farm
Expected results Farm's total supply equals 0
Test Scenario Check that wallet can't quit a farm that it doesn't participate
Initial setup
wallet1
has not joined any farm
Test Steps
Quit wallet1
from the farm
Expected results
Reverts with error 'ERC20Farmable: already exited'
Test Scenario Check that wallet can't quit a farm twice in a row
Initial setup
wallet1
has joined the farm
Test Steps
- Quit
wallet1
from thefarm
- Quit
wallet1
from thefarm
Expected results
Reverts with error 'ERC20Farmable: already exited'
Farming reward calculations scenarios
Test Scenario Staker without farming tokens joins on 1st week and adds them on 2nd
72k => 1x: + +-------+ => 36k
Initial setup
farm
has started farming 72k for 2 weekswallet1
has no farmable token and joined thefarm
Test Steps
- Fast-forward to 1 week end
wallet1
gets farming tokens- Fast-forward to 2 week
Expected results After step 1 - farmed reward = 0 After step 3 - farmed reward = 36k
Test Scenario Two stakers with the same stakes wait 1w
72k => 1x: +-------+ => 36k
# 1x: +-------+ => 36k
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
wallet2
has 1 farmable token and joined thefarm
Test Steps Fast-forward to week 1 end
Expected results
wallet1
farmed reward is 36k
wallet2
farmed reward is 36k
Test Scenario Two stakers with the same stakes wait 1w
72k => 1x: +-------+ => 18k
# 3x: +-------+ => 54k
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
wallet2
has 3 farmable token and joined thefarm
Test Steps Fast-forward to week 1 end
Expected results
wallet1
farmed reward is 18k
wallet2
farmed reward is 54k
Test Scenario Two stakers with the different (1:3) stakes wait 2 weeks
72k => 1x: +--------+ 72k => 1x: +--------+ => 72k for 1w + 18k for 2w
# 0x: 3x: +--------+ => 0k for 1w + 54k for 2w
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
wallet2
has 3 farmable token and has not joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
---|---|---|---|
1. | Fast-forward => week 1 | 72k | 0 |
2. | wallet2 joins the farm |
72k | 0 |
3. | farm starts new farming 72k for 1 week |
72k | 0 |
4. | Fast-forward => week 2 | 90k | 54k |
Test Scenario One staker on 1st and 3rd weeks farming with gap
72k => 1x: +--------+ 72k => 1x: +--------+ = 72k for 1w + 0k for 2w + 72k for 3w
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
---|---|---|
1. | Fast-forward => week 1 | 72k |
2. | Fast-forward => week 2 | 72k |
3. | farm starts new farming 72k for 1 week |
72k |
4. | Fast-forward => week 3 | 144k |
Test Scenario One staker on 1st and 3rd weeks farming with gap and claims in the middle
72k => 1x: +--------+ 72k => 1x: +--------+ = 72k for 1w + 0k for 2w + 72k for 3w
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
---|---|---|
1. | Fast-forward => week 1 | 72k |
2. | Claim reward for wallet1 |
0 |
2. | Fast-forward => week 2 | 0 |
3. | farm starts new farming 72k for 1 week |
0 |
4. | Fast-forward => week 3 | 72k |
Test Scenario One staker on 1st and 3rd weeks farming with gap and exits and rejoins in the middle
72k => 1x: +--------+ 72k => 1x: +--------+ = 72k for 1w + 0k for 2w + 72k for 3w
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
---|---|---|
1. | Fast-forward => week 1 | 72k |
2. | wallet1 quits farm |
72k |
3. | wallet1 joins farm |
72k |
4. | Fast-forward => week 2 | 72k |
5. | farm starts new farming 72k for 1 week |
72k |
6. | Fast-forward => week 3 | 144k |
Test Scenario One staker on 1st and 3rd weeks farming with gap and exits, claims and rejoins in the middle
72k => 1x: +--------+ 72k => 1x: +--------+ = 72k for 1w + 0k for 2w + 72k for 3w
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
---|---|---|
1. | Fast-forward => week 1 | 72k |
2. | wallet1 quits farm |
72k |
3. | wallet1 claims farming reward |
0k |
4. | wallet1 joins farm |
0k |
5. | Fast-forward => week 2 | 0k |
6. | farm starts new farming 72k for 1 week |
72k |
7. | Fast-forward => week 3 | 72k |
Test Scenario Three stakers with the different (1:3:5) stakes wait 3 weeks
1x: 72k => +-------+ 72k => +-------+ 72k => +-------+ = 18k for 1w + 8k for 2w + 12k for 3w
3x: +-------+ +-------+ = 54k for 1w + 24k for 2w + 0k for 3w
5x: +-------+ +-------+ = 0k for 1w + 40k for 2w + 60k for 3w
Initial setup
farm
has started farming 72k for 1 weekwallet1
has 1 farmable token and joined thefarm
wallet2
has 3 farmable token and joined thefarm
wallet3
has 5 farmable token and hasn't joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
wallet3 |
---|---|---|---|---|
1. | Fast-forward => week 1 | 18k | 54k | 0 |
2. | wallet3 joins farm |
18k | 54k | 0 |
3. | farm starts new farming 72k for 1 week |
18k | 54k | 0 |
4. | Fast-forward => week 2 | 26k | 78k | 40k |
5. | wallet2 quits farm |
26k | 78k | 40k |
6. | farm starts new farming 72k for 1 week |
26k | 78k | 40k |
7. | Fast-forward => week 3 | 38k | 78k | 100k |
Test Scenario Three stakers with the different (1:3:5) stakes wait 3 weeks for 1 farming event
1x: 216k => +---------------------+ = 18k for 1w + 8k for 2w + 12k for 3w
3x: +--------------+ = 54k for 1w + 24k for 2w + 0k for 3w
5x: +--------------+ = 0k for 1w + 40k for 2w + 60k for 3w
Initial setup
farm
has started farming 216k for 3 weekswallet1
has 1 farmable token and joined thefarm
wallet2
has 3 farmable token and joined thefarm
wallet3
has 5 farmable token and hasn't joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
wallet3 |
---|---|---|---|---|
1. | Fast-forward => week 1 | 18k | 54k | 0 |
2. | wallet3 joins farm |
18k | 54k | 0 |
3. | Fast-forward => week 2 | 26k | 78k | 40k |
4. | wallet2 quits farm |
26k | 78k | 40k |
5. | Fast-forward => week 3 | 38k | 78k | 100k |
Test Scenario Add more farming reward before previous farming finished
1x: 10k => +-------+ = 2750 for 1w
3x: 1k => +-------+ = 8250 for 1w
Initial setup
farm
has started farming 10k for 1 weekswallet1
has 1 farmable token and joined thefarm
wallet2
has 3 farmable token and joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
---|---|---|---|
1. | farm starts new farming 1k for 1 week |
0 | 0 |
2. | Fast-forward => week 1 | 2720 | 8250 |
Token transfer scenarios
Test Scenario Transfer from one wallet to another, both are farming
72k => 2x: +-------+ 1х: +--------+ = 9k for 1w + 27k for 2w = 36
# 1x: +-------+ 2x: +--------+ = 27k for 1w + 9k for 2w = 36
Initial setup
farm
has started farming 72k for 2 weekswallet1
has 1 farmable token and joined thefarm
wallet2
has 3 farmable token and joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
---|---|---|---|
1. | Fast-forward => week 1 | 9k | 27k |
2. | Transfer 2 farmable tokens from wallet2 to wallet1 |
9k | 27k |
3. | Fast-forward => week 2 | 36k | 36k |
1x: +-------+--------+ = 18k for 1w + 36k for 2w
1x: +-------+ = 18k for 1w + 0k for 2w
Test Scenario Transfer from one wallet to another, sender is farming, reciever is not farming
72k => 1x: +-------+ 1х: +--------+ = 9k for 1w + 27k for 2w = 36
# 1x: +-------+ 0x: + + = 27k for 1w + 9k for 2w = 36
Initial setup
farm
has started farming 72k for 2 weekswallet1
has 1 farmable token and joined thefarm
wallet2
has 1 farmable token and joined thefarm
wallet3
has no farmable token and hasn't joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
---|---|---|---|
1. | Fast-forward => week 1 | 18k | 18k |
2. | Transfer 2 farmable tokens from wallet2 to wallet3 |
18k | 18k |
3. | Fast-forward => week 2 | 54k | 18k |
Test Scenario Transfer farming token to farming wallet in the middle of farming
72k => 1x: +-------+ 3х: +--------+ = 18k for 1w + 27k for 2w = 36
# 1x: +-------+ 1x: +--------+ = 18k for 1w + 9k for 2w = 36
Initial setup
farm
has started farming 72k for 2 weekswallet1
has 1 farmable token and joined thefarm
wallet2
has 1 farmable token and joined thefarm
wallet3
has 2 farmable token and hasn't joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
---|---|---|---|
1. | Fast-forward => week 1 | 18k | 18k |
2. | Transfer 2 farmable tokens from wallet3 to wallet1 |
18k | 18k |
3. | Fast-forward => week 2 | 45k | 27k |
Test Scenario Transfer from one wallet to another, both are not farming
72k => 0x: + + 1х: +--------+ = 0k for 1w + 9k for 2w
# 0x: + + 3x: +--------+ = 0k for 1w + 27k for 2w
Initial setup
farm
has started farming 72k for 2 weekswallet1
has 1 farmable token and has not joined thefarm
wallet2
has 1 farmable token and has not joined thefarm
Test steps and expected rewards
# | Test Steps | wallet1 |
wallet2 |
---|---|---|---|
1. | Fast-forward => week 1 | 0 | 0 |
3. | Transfer 3 from wallet1 to wallet2 |
0 | 0 |
2. | wallet1 and wallet2 join the farm |
0 | 0 |
4. | Fast-forward => week 2 | 27k | 9k |