mineV2 test ing
This commit is contained in:
@@ -35,10 +35,10 @@ contract vDODOMine is BaseMine {
|
|||||||
// ============ Deposit && Withdraw && Exit ============
|
// ============ Deposit && Withdraw && Exit ============
|
||||||
|
|
||||||
function deposit(uint256 amount) public {
|
function deposit(uint256 amount) public {
|
||||||
require(amount > 0, "vDODOMineETH: CANNOT_DEPOSIT_ZERO");
|
require(amount > 0, "DODOMineV2: CANNOT_DEPOSIT_ZERO");
|
||||||
require(
|
require(
|
||||||
amount <= IVDODOToken(_vDODO_TOKEN_).availableBalanceOf(msg.sender),
|
amount <= IVDODOToken(_vDODO_TOKEN_).availableBalanceOf(msg.sender),
|
||||||
"vDODOMineETH: vDODO_NOT_ENOUGH"
|
"DODOMineV2: vDODO_NOT_ENOUGH"
|
||||||
);
|
);
|
||||||
_totalSupply = _totalSupply.add(amount);
|
_totalSupply = _totalSupply.add(amount);
|
||||||
_balances[msg.sender] = _balances[msg.sender].add(amount);
|
_balances[msg.sender] = _balances[msg.sender].add(amount);
|
||||||
|
|||||||
168
test/DODOMineV2/erc20Mine.test.ts
Normal file
168
test/DODOMineV2/erc20Mine.test.ts
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2021 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { decimalStr, fromWei } from '../utils/Converter';
|
||||||
|
import { logGas } from '../utils/Log';
|
||||||
|
import { DODOMineV2Context, getDODOMineContext } from '../utils/DODOMineV2Context';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
import { Contract } from 'web3-eth-contract';
|
||||||
|
|
||||||
|
let account0: string;
|
||||||
|
let account1: string;
|
||||||
|
let projector: string;
|
||||||
|
|
||||||
|
async function init(ctx: DODOMineV2Context): Promise<void> {
|
||||||
|
projector = ctx.Deployer;
|
||||||
|
account0 = ctx.SpareAccounts[0];
|
||||||
|
account1 = ctx.SpareAccounts[1];
|
||||||
|
|
||||||
|
//For User
|
||||||
|
await ctx.mintTestToken(account0, ctx.ERC20, decimalStr("1000"));
|
||||||
|
await ctx.mintTestToken(account1, ctx.ERC20, decimalStr("500"));
|
||||||
|
|
||||||
|
//For Project
|
||||||
|
await ctx.mintTestToken(projector, ctx.REWARD_1, decimalStr("1000000"));
|
||||||
|
await ctx.mintTestToken(projector, ctx.REWARD_2, decimalStr("1000000"));
|
||||||
|
|
||||||
|
await ctx.approveProxy(account0, ctx.ERC20Mine.options.address, ctx.ERC20);
|
||||||
|
await ctx.approveProxy(account1, ctx.ERC20Mine.options.address, ctx.ERC20);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addRewardToken(ctx: DODOMineV2Context, token: Contract, start: number, end: number) {
|
||||||
|
await ctx.ERC20Mine.methods.addRewardToken(
|
||||||
|
token.options.address,
|
||||||
|
start,
|
||||||
|
end
|
||||||
|
).send(ctx.sendParam(projector));
|
||||||
|
|
||||||
|
let idx = await ctx.ERC20Mine.methods.getIdxByRewardToken(token.options.address).call();
|
||||||
|
let rewardInfo = await ctx.ERC20Mine.methods.rewardTokenInfos(idx).call();
|
||||||
|
await token.methods.transfer(rewardInfo.vault, decimalStr("10000")).send(this.sendParam(this.Deployer));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function balanceInfo(ctx: DODOMineV2Context, idx:number,user: string,logInfo?:string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getRewardInfo(ctx: DODOMineV2Context, idx: number, user: string, logInfo?: string) {
|
||||||
|
let erc20Mine = ctx.ERC20Mine
|
||||||
|
let obj = await erc20Mine.methods.rewardTokenInfos(idx).call();
|
||||||
|
console.log(logInfo);
|
||||||
|
console.log("Static-Data: rewardToken:" + obj.rewardToken + " " + )
|
||||||
|
console.log("startBlock:", obj.startBlock)
|
||||||
|
console.log("endBlock:", obj.endBlock)
|
||||||
|
console.log("rewardVault:", obj.rewardVault)
|
||||||
|
console.log("rewardPerBlock:", obj.rewardPerBlock)
|
||||||
|
console.log("accRewardPerShare:", obj.accRewardPerShare)
|
||||||
|
console.log("lastRewardBlock:", obj.lastRewardBlock)
|
||||||
|
var pendingReward = null;
|
||||||
|
if (user != null) {
|
||||||
|
pendingReward = await erc20Mine.methods.getPendingReward(idx, user).call();
|
||||||
|
console.log("pendingReward:", pendingReward);
|
||||||
|
}
|
||||||
|
return [obj, pendingReward];
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("erc20Mine", () => {
|
||||||
|
let snapshotId: string;
|
||||||
|
let ctx: DODOMineV2Context;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
ctx = await getDODOMineContext();
|
||||||
|
await init(ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
snapshotId = await ctx.EVM.snapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await ctx.EVM.reset(snapshotId);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("baseMine", () => {
|
||||||
|
// ======= Ownable =========
|
||||||
|
it("addRewardToken", async () => {
|
||||||
|
let erc20Mine = ctx.ERC20Mine;
|
||||||
|
var curBlock = await ctx.Web3.eth.getBlockNumber();
|
||||||
|
await erc20Mine.methods.addRewardToken(
|
||||||
|
ctx.REWARD_1.options.address,
|
||||||
|
curBlock + 2,
|
||||||
|
curBlock + 1000
|
||||||
|
).send(ctx.sendParam(projector));
|
||||||
|
let [rewardTokenInfo,] = await getRewardInfo(ctx, 0, null, "");
|
||||||
|
assert(rewardTokenInfo.rewardPerBlock, decimalStr("0"))
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removeRewardToken", async () => {
|
||||||
|
let erc20Mine = ctx.ERC20Mine;
|
||||||
|
var curBlock = await ctx.Web3.eth.getBlockNumber();
|
||||||
|
await addRewardToken(ctx, ctx.REWARD_1, curBlock + 10, curBlock + 110);
|
||||||
|
await addRewardToken(ctx, ctx.REWARD_2, curBlock + 10, curBlock + 110);
|
||||||
|
let [rewardTokenInfo,] = await getRewardInfo(ctx, 0, null, "");
|
||||||
|
await erc20Mine.methods.removeRewardToken(
|
||||||
|
rewardTokenInfo.rewardToken
|
||||||
|
).send(ctx.sendParam(projector));
|
||||||
|
[rewardTokenInfo,] = await getRewardInfo(ctx, 0, null, "");
|
||||||
|
assert(rewardTokenInfo.rewardToken, ctx.REWARD_2.options.address)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("setReward", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("setEndBlock", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("erc20Mine", () => {
|
||||||
|
|
||||||
|
it("deposit", async () => {
|
||||||
|
var curBlock = await ctx.Web3.eth.getBlockNumber();
|
||||||
|
await addRewardToken(ctx, ctx.REWARD_1, curBlock + 2, curBlock + 102);
|
||||||
|
await logGas(await ctx.ERC20Mine.methods.deposit(
|
||||||
|
decimalStr("10")
|
||||||
|
), ctx.sendParam(account0), "deposit");
|
||||||
|
|
||||||
|
//增加区块
|
||||||
|
await ctx.mintTestToken(account0, ctx.ERC20, decimalStr("0"));
|
||||||
|
await ctx.mintTestToken(account0, ctx.ERC20, decimalStr("0"));
|
||||||
|
await ctx.mintTestToken(account0, ctx.ERC20, decimalStr("0"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("withdraw", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("withdrawAll", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("getReward", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getRewardAll", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exit", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
0
test/DODOMineV2/vDODOMine.test.ts
Normal file
0
test/DODOMineV2/vDODOMine.test.ts
Normal file
@@ -50,6 +50,8 @@ export const VDODO_NAME = "vDODOToken"
|
|||||||
export const DODO_CULATION_HELPER = "DODOCirculationHelper"
|
export const DODO_CULATION_HELPER = "DODOCirculationHelper"
|
||||||
export const DODO_GOVERNANCE = "Governance"
|
export const DODO_GOVERNANCE = "Governance"
|
||||||
export const DODO_PROXY_NAME = "DODOV2Proxy02"
|
export const DODO_PROXY_NAME = "DODOV2Proxy02"
|
||||||
|
export const ERC20_MINE = "ERC20Mine"
|
||||||
|
export const VDODO_MINE = "vDODOMine"
|
||||||
|
|
||||||
interface ContractJson {
|
interface ContractJson {
|
||||||
abi: any;
|
abi: any;
|
||||||
|
|||||||
99
test/utils/DODOMineV2Context.ts
Normal file
99
test/utils/DODOMineV2Context.ts
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2020 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
import Web3 from 'web3';
|
||||||
|
import { Contract } from 'web3-eth-contract';
|
||||||
|
|
||||||
|
import * as contracts from './Contracts';
|
||||||
|
import { decimalStr, mweiStr, MAX_UINT256 } from './Converter';
|
||||||
|
import { EVM, getDefaultWeb3 } from './EVM';
|
||||||
|
import * as log from './Log';
|
||||||
|
|
||||||
|
BigNumber.config({
|
||||||
|
EXPONENTIAL_AT: 1000,
|
||||||
|
DECIMAL_PLACES: 80,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export class DODOMineV2Context {
|
||||||
|
EVM: EVM;
|
||||||
|
Web3: Web3;
|
||||||
|
|
||||||
|
//contract
|
||||||
|
ERC20Mine: Contract;
|
||||||
|
|
||||||
|
//account
|
||||||
|
Deployer: string;
|
||||||
|
Maintainer: string;
|
||||||
|
SpareAccounts: string[];
|
||||||
|
|
||||||
|
//token
|
||||||
|
REWARD_1: Contract;
|
||||||
|
REWARD_2: Contract;
|
||||||
|
ERC20: Contract;
|
||||||
|
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
this.EVM = new EVM();
|
||||||
|
this.Web3 = getDefaultWeb3();
|
||||||
|
|
||||||
|
const allAccounts = await this.Web3.eth.getAccounts();
|
||||||
|
this.Deployer = allAccounts[0];
|
||||||
|
this.Maintainer = allAccounts[1];
|
||||||
|
this.SpareAccounts = allAccounts.slice(2, 10);
|
||||||
|
|
||||||
|
this.ERC20 = await contracts.newContract(
|
||||||
|
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
||||||
|
["ERC20 Token", "ERC20", 18]
|
||||||
|
);
|
||||||
|
|
||||||
|
this.REWARD_1 = await contracts.newContract(
|
||||||
|
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
||||||
|
["REWARD_1 Token", "REWARD_1", 18]
|
||||||
|
);
|
||||||
|
|
||||||
|
this.REWARD_2 = await contracts.newContract(
|
||||||
|
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
||||||
|
["REWARD_2 Token", "REWARD_2", 18]
|
||||||
|
);
|
||||||
|
|
||||||
|
this.ERC20Mine = await contracts.newContract(
|
||||||
|
contracts.ERC20_MINE,
|
||||||
|
[this.ERC20.options.address]
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.ERC20Mine.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
|
console.log(log.blueText("[Init ERC20Mine context]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendParam(sender, value = "0") {
|
||||||
|
return {
|
||||||
|
from: sender,
|
||||||
|
gas: process.env["COVERAGE"] ? 10000000000 : 7000000,
|
||||||
|
gasPrice: mweiStr("1000"),
|
||||||
|
value: decimalStr(value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async mintTestToken(to: string, token: Contract, amount: string) {
|
||||||
|
await token.methods.mint(to, amount).send(this.sendParam(this.Deployer));
|
||||||
|
}
|
||||||
|
|
||||||
|
async approveProxy(account: string, target: string, token: Contract) {
|
||||||
|
await token.methods
|
||||||
|
.approve(target, MAX_UINT256)
|
||||||
|
.send(this.sendParam(account));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getDODOMineContext(): Promise<DODOMineV2Context> {
|
||||||
|
var context = new DODOMineV2Context();
|
||||||
|
await context.init();
|
||||||
|
return context;
|
||||||
|
}
|
||||||
@@ -46,7 +46,10 @@ then
|
|||||||
truffle test ./test/vDODO/mintRedeem.test.ts
|
truffle test ./test/vDODO/mintRedeem.test.ts
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$1"x = "erc20-mine"x ]
|
||||||
|
then
|
||||||
|
truffle test ./test/DODOMineV2/erc20Mine.test.ts
|
||||||
|
fi
|
||||||
# if [ "$1"x = "route-incentive"x ]
|
# if [ "$1"x = "route-incentive"x ]
|
||||||
# then
|
# then
|
||||||
# truffle test ./test/Route/Incentive.test.ts
|
# truffle test ./test/Route/Incentive.test.ts
|
||||||
|
|||||||
Reference in New Issue
Block a user