forked from sushi-labs/sushiswap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { expectRevert, time } = require('@openzeppelin/test-helpers'); | ||
const SushiToken = artifacts.require('SushiToken'); | ||
const MasterChef = artifacts.require('MasterChef'); | ||
const MockERC20 = artifacts.require('MockERC20'); | ||
const UniswapV2Pair = artifacts.require('UniswapV2Pair'); | ||
const UniswapV2Factory = artifacts.require('UniswapV2Factory'); | ||
const Migrator = artifacts.require('Migrator'); | ||
|
||
contract('Migrator', ([alice, bob, dev, minter]) => { | ||
beforeEach(async () => { | ||
this.factory1 = await UniswapV2Factory.new(alice, { from: alice }); | ||
this.factory2 = await UniswapV2Factory.new(alice, { from: alice }); | ||
this.sushi = await SushiToken.new({ from: alice }); | ||
this.weth = await MockERC20.new('WETH', 'WETH', '100000000', { from: minter }); | ||
this.token = await MockERC20.new('TOKEN', 'TOKEN', '100000000', { from: minter }); | ||
this.lp1 = await UniswapV2Pair.at((await this.factory1.createPair(this.weth.address, this.token.address)).logs[0].args.pair); | ||
this.lp2 = await UniswapV2Pair.at((await this.factory2.createPair(this.weth.address, this.token.address)).logs[0].args.pair); | ||
this.chef = await MasterChef.new(this.sushi.address, dev, '1000', '0', '100000', { from: alice }); | ||
this.migrator = await Migrator.new(this.chef.address, this.factory2.address, '0'); | ||
await this.sushi.transferOwnership(this.chef.address, { from: alice }); | ||
await this.chef.add('100', this.lp1.address, true, { from: alice }); | ||
}); | ||
|
||
it('should do the migration successfully', async () => { | ||
await this.token.transfer(this.lp1.address, '10000000', { from: minter }); | ||
await this.weth.transfer(this.lp1.address, '500000', { from: minter }); | ||
await this.lp1.mint(minter); | ||
assert.equal((await this.lp1.balanceOf(minter)).valueOf(), '2235067'); | ||
await this.lp1.approve(this.chef.address, '100000000000', { from: minter }); | ||
await this.chef.deposit('0', '2000000', { from: minter }); | ||
assert.equal((await this.lp1.balanceOf(this.chef.address)).valueOf(), '2000000'); | ||
await expectRevert(this.chef.migrate(0), 'migrate: no migrator'); | ||
await this.chef.setMigrator(this.migrator.address, { from: alice }); | ||
await expectRevert(this.chef.migrate(0), 'migrate: bad'); | ||
await this.factory2.setMigrator(this.migrator.address, { from: alice }); | ||
await this.chef.migrate(0); | ||
assert.equal((await this.lp1.balanceOf(this.chef.address)).valueOf(), '0'); | ||
assert.equal((await this.lp2.balanceOf(this.chef.address)).valueOf(), '2000000'); | ||
await this.chef.withdraw('0', '2000000', { from: minter }); | ||
await this.lp2.transfer(this.lp2.address, '2000000', { from: minter }); | ||
await this.lp2.burn(bob); | ||
assert.equal((await this.token.balanceOf(bob)).valueOf(), '8939805'); | ||
assert.equal((await this.weth.balanceOf(bob)).valueOf(), '446989'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const { expectRevert } = require('@openzeppelin/test-helpers'); | ||
const SushiToken = artifacts.require('SushiToken'); | ||
const SushiBar = artifacts.require('SushiBar'); | ||
|
||
contract('SushiToken', ([alice, bob, carol]) => { | ||
beforeEach(async () => { | ||
this.sushi = await SushiToken.new({ from: alice }); | ||
this.bar = await SushiBar.new(this.sushi.address, { from: alice }); | ||
this.sushi.mint(alice, '100', { from: alice }); | ||
this.sushi.mint(bob, '100', { from: alice }); | ||
this.sushi.mint(carol, '100', { from: alice }); | ||
}); | ||
|
||
it('should not allow enter if not enough approve', async () => { | ||
await expectRevert( | ||
this.bar.enter('100', { from: alice }), | ||
'ERC20: transfer amount exceeds allowance', | ||
); | ||
await this.sushi.approve(this.bar.address, '50', { from: alice }); | ||
await expectRevert( | ||
this.bar.enter('100', { from: alice }), | ||
'ERC20: transfer amount exceeds allowance', | ||
); | ||
await this.sushi.approve(this.bar.address, '100', { from: alice }); | ||
await this.bar.enter('100', { from: alice }); | ||
assert.equal((await this.bar.balanceOf(alice)).valueOf(), '100'); | ||
}); | ||
|
||
it('should not allow withraw more than what you have', async () => { | ||
await this.sushi.approve(this.bar.address, '100', { from: alice }); | ||
await this.bar.enter('100', { from: alice }); | ||
await expectRevert( | ||
this.bar.leave('200', { from: alice }), | ||
'ERC20: burn amount exceeds balance', | ||
); | ||
}); | ||
|
||
it('should work with more than one participant', async () => { | ||
await this.sushi.approve(this.bar.address, '100', { from: alice }); | ||
await this.sushi.approve(this.bar.address, '100', { from: bob }); | ||
// Alice enters and gets 20 shares. Bob enters and gets 10 shares. | ||
await this.bar.enter('20', { from: alice }); | ||
await this.bar.enter('10', { from: bob }); | ||
assert.equal((await this.bar.balanceOf(alice)).valueOf(), '20'); | ||
assert.equal((await this.bar.balanceOf(bob)).valueOf(), '10'); | ||
assert.equal((await this.sushi.balanceOf(this.bar.address)).valueOf(), '30'); | ||
// SushiBar get 20 more SUSHIs from an external source. | ||
await this.sushi.transfer(this.bar.address, '20', { from: carol }); | ||
// Alice deposits 10 more SUSHIs. She should receive 10*30/50 = 6 shares. | ||
await this.bar.enter('10', { from: alice }); | ||
assert.equal((await this.bar.balanceOf(alice)).valueOf(), '26'); | ||
assert.equal((await this.bar.balanceOf(bob)).valueOf(), '10'); | ||
// Bob withdraws 5 shares. He should receive 5*60/36 = 8 shares | ||
await this.bar.leave('5', { from: bob }); | ||
assert.equal((await this.bar.balanceOf(alice)).valueOf(), '26'); | ||
assert.equal((await this.bar.balanceOf(bob)).valueOf(), '5'); | ||
assert.equal((await this.sushi.balanceOf(this.bar.address)).valueOf(), '52'); | ||
assert.equal((await this.sushi.balanceOf(alice)).valueOf(), '70'); | ||
assert.equal((await this.sushi.balanceOf(bob)).valueOf(), '98'); | ||
}); | ||
}); |