const MasterChef = artifacts.require('MasterChef'); const StakingRewards = artifacts.require('StakingRewards'); const TokenMock = artifacts.require('TokenMock'); const {time, BN, ether} = require('@openzeppelin/test-helpers'); const {use, expect} = require('chai'); function bn(params) { return new BN(params.toString()); } use(require('chai-bn')(BN)); const PID = 0; const ALLOCATE_POINT_SUSHI = ether('1000'); const ALLOCATE_POINT_XFT = ether('1000'); contract('DeltaHubStaking', ([owner, dev, wallet1, wallet2, wallet3, wallet4, wallet5]) => { let slp; let sushi; let xft; let onsen; let staking; beforeEach(async () => { slp = await TokenMock.new('SLP', 'SLP', ether('10000000'), {from: owner}); sushi = await TokenMock.new('SUSHI', 'SUSHI', ether('10000000'), {from: owner}); xft = await TokenMock.new('XFT', 'XFT', ether('10000000'), {from: owner}); onsen = await MasterChef.new( sushi.address, dev, ether('0.01'), await time.latestBlock(), await time.latestBlock() + 2592000, // apx. 12 month {from: owner}, ); staking = await StakingRewards.new( xft.address, sushi.address, slp.address, onsen.address, {from: owner}, ); await onsen.add(ALLOCATE_POINT_SUSHI, slp.address, false, {from: owner}); await sushi.mint(onsen.address, ALLOCATE_POINT_SUSHI); await xft.transfer(staking.address, ALLOCATE_POINT_XFT, {from: owner}); await staking.notifyRewardAmount(ALLOCATE_POINT_XFT, {from: owner}); await slp.transfer(wallet1, ether('100000'), {from: owner}); await slp.transfer(wallet2, ether('100000'), {from: owner}); await slp.transfer(wallet3, ether('100000'), {from: owner}); await slp.transfer(wallet4, ether('100000'), {from: owner}); await slp.transfer(wallet5, ether('100000'), {from: owner}); await slp.approve(staking.address, new BN(2).pow(new BN(255)), {from: wallet1}); await slp.approve(staking.address, new BN(2).pow(new BN(255)), {from: wallet2}); await slp.approve(staking.address, new BN(2).pow(new BN(255)), {from: wallet3}); await slp.approve(staking.address, new BN(2).pow(new BN(255)), {from: wallet4}); await slp.approve(staking.address, new BN(2).pow(new BN(255)), {from: wallet5}); }); describe('test gas usage', () => { beforeEach( async () => { await slp.approve(onsen.address, new BN(2).pow(new BN(255)), {from: wallet1}); await slp.approve(onsen.address, new BN(2).pow(new BN(255)), {from: wallet2}); await slp.approve(onsen.address, new BN(2).pow(new BN(255)), {from: wallet3}); }); it('should stake to onsen contract', async () => { const amount = ether('2'); let totalStaked = await bn(0); for (let i = 1; i < 50; i++) { const stakeAmount = await bn(amount).mul(bn(i)); await onsen.deposit(PID, stakeAmount, {from: wallet1}); await onsen.deposit(PID, stakeAmount, {from: wallet2}); await onsen.deposit(PID, stakeAmount, {from: wallet3}); await staking.stake(stakeAmount, {from: wallet1}); await staking.stake(stakeAmount, {from: wallet2}); await staking.stake(stakeAmount, {from: wallet3}); totalStaked = await totalStaked.add(stakeAmount); } for (let i = 1; i < 50; i++) { const stakeAmount = await bn(amount).mul(bn(i)); await staking.withdraw(stakeAmount, {from: wallet1}); await staking.withdraw(stakeAmount, {from: wallet2}); await staking.withdraw(stakeAmount, {from: wallet3}); await onsen.withdraw(PID, stakeAmount, {from: wallet1}); await onsen.withdraw(PID, stakeAmount, {from: wallet2}); await onsen.withdraw(PID, stakeAmount, {from: wallet3}); } }); it('should withdraw from onsen contract', async () => { await staking.stake(ether('100'), {from: wallet1}); expect((await staking.userInfo(wallet1)).amount).to.be.a.bignumber.equal(ether('100')); expect((await onsen.userInfo(PID, staking.address)).amount).to.be.a.bignumber.equal(ether('100')); await staking.withdraw(ether('100'), {from: wallet1}); expect((await staking.userInfo(wallet1)).amount).to.be.a.bignumber.equal('0'); expect((await onsen.userInfo(PID, staking.address)).amount).to.be.a.bignumber.equal('0'); }); }); });