Add test context
This commit is contained in:
@@ -40,6 +40,7 @@ contract DODOCirculationHelper is Ownable {
|
|||||||
|
|
||||||
function getCirculation() public view returns (uint256 circulation) {
|
function getCirculation() public view returns (uint256 circulation) {
|
||||||
circulation = 10**9;
|
circulation = 10**9;
|
||||||
|
//TODO circulation 需要乘以decimals吗?
|
||||||
for (uint256 i = 0; i < _LOCKED_CONTRACT_ADDRESS_.length; i++) {
|
for (uint256 i = 0; i < _LOCKED_CONTRACT_ADDRESS_.length; i++) {
|
||||||
circulation -= IERC20(_DODO_TOKEN_).balanceOf(_LOCKED_CONTRACT_ADDRESS_[i]);
|
circulation -= IERC20(_DODO_TOKEN_).balanceOf(_LOCKED_CONTRACT_ADDRESS_[i]);
|
||||||
}
|
}
|
||||||
@@ -54,7 +55,7 @@ contract DODOCirculationHelper is Ownable {
|
|||||||
uint256 x =
|
uint256 x =
|
||||||
DecimalMath.divCeil(
|
DecimalMath.divCeil(
|
||||||
dodoCirculationAmout,
|
dodoCirculationAmout,
|
||||||
IERC20(_DODO_TOKEN_).balanceOf(address(this))
|
IERC20(_DODO_TOKEN_).balanceOf(address(this))// TODO 这里应该是vdodo的值吧?
|
||||||
);
|
);
|
||||||
|
|
||||||
if (x <= 10**18) {
|
if (x <= 10**18) {
|
||||||
|
|||||||
24
contracts/DODOToken/Governance.sol
Normal file
24
contracts/DODOToken/Governance.sol
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2020 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
pragma solidity 0.6.9;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||||
|
|
||||||
|
contract Governance is InitializableOwnable {
|
||||||
|
|
||||||
|
// ============ Storage ============
|
||||||
|
|
||||||
|
address immutable _DODO_TOKEN_;
|
||||||
|
|
||||||
|
constructor(address dodoToken) public {
|
||||||
|
_DODO_TOKEN_ = dodoToken;
|
||||||
|
}
|
||||||
|
function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) {
|
||||||
|
lockedvDODO = 0;//DOTO,0 for test
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,18 +90,19 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard {
|
|||||||
// ============ Constructor ============
|
// ============ Constructor ============
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
address _dodoGov,
|
// address _dodoGov,
|
||||||
address _dodoToken,
|
address _dodoToken,
|
||||||
address _dodoCirculationHelper,
|
address _dodoCirculationHelper,
|
||||||
address _dodoApproveProxy,
|
address _dodoApproveProxy,
|
||||||
string memory _name,
|
string memory _name,
|
||||||
string memory _symbol
|
string memory _symbol
|
||||||
) public {
|
) public {
|
||||||
|
initOwner(msg.sender);
|
||||||
name = _name;
|
name = _name;
|
||||||
symbol = _symbol;
|
symbol = _symbol;
|
||||||
decimals = 18;
|
decimals = 18;
|
||||||
_DODO_APPROVE_PROXY_ = _dodoApproveProxy;
|
_DODO_APPROVE_PROXY_ = _dodoApproveProxy;
|
||||||
_DOOD_GOV_ = _dodoGov;
|
// _DOOD_GOV_ = _dodoGov;
|
||||||
_DODO_CIRCULATION_HELPER_ = _dodoCirculationHelper;
|
_DODO_CIRCULATION_HELPER_ = _dodoCirculationHelper;
|
||||||
_DODO_TOKEN_ = _dodoToken;
|
_DODO_TOKEN_ = _dodoToken;
|
||||||
lastRewardBlock = block.number;
|
lastRewardBlock = block.number;
|
||||||
@@ -128,6 +129,9 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard {
|
|||||||
function updateDODOCirculationHelper(address _helper) public onlyOwner {
|
function updateDODOCirculationHelper(address _helper) public onlyOwner {
|
||||||
_DODO_CIRCULATION_HELPER_ = _helper;
|
_DODO_CIRCULATION_HELPER_ = _helper;
|
||||||
}
|
}
|
||||||
|
function updateGovernance(address _governance) public onlyOwner {
|
||||||
|
_DOOD_GOV_ = _governance;
|
||||||
|
}
|
||||||
|
|
||||||
// ============ Functions ============
|
// ============ Functions ============
|
||||||
|
|
||||||
|
|||||||
75
test/Token/vdodo.test.ts
Normal file
75
test/Token/vdodo.test.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2021 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// import * as assert from 'assert';
|
||||||
|
|
||||||
|
import { decimalStr, MAX_UINT256 } from '../utils/Converter';
|
||||||
|
import { logGas } from '../utils/Log';
|
||||||
|
import { VDODOContext, getVDODOContext } from '../utils/VDODOContext';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
const truffleAssert = require('truffle-assertions');
|
||||||
|
|
||||||
|
let account0: string;
|
||||||
|
let account1: string;
|
||||||
|
let account2: string;
|
||||||
|
|
||||||
|
async function init(ctx: VDODOContext): Promise<void> {
|
||||||
|
account0 = ctx.SpareAccounts[0];
|
||||||
|
account1 = ctx.SpareAccounts[1];
|
||||||
|
account2 = ctx.SpareAccounts[2];
|
||||||
|
|
||||||
|
await ctx.mintTestToken(account0, decimalStr("1000"));
|
||||||
|
await ctx.mintTestToken(account1, decimalStr("1000"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("VDODO", () => {
|
||||||
|
let snapshotId: string;
|
||||||
|
let ctx: VDODOContext;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
ctx = await getVDODOContext();
|
||||||
|
await init(ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
snapshotId = await ctx.EVM.snapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await ctx.EVM.reset(snapshotId);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("vdodo", () => {
|
||||||
|
|
||||||
|
it("vdodo init", async () => {
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await ctx.DODO.methods.balanceOf(account0).call(),
|
||||||
|
decimalStr("1000")
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await ctx.VDODO.methods.balanceOf(account0).call(),
|
||||||
|
decimalStr("0")
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await ctx.VDODO.methods.alpha().call(),
|
||||||
|
ctx.alpha
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await ctx.VDODO.methods.lastRewardBlock().call(),
|
||||||
|
ctx.lastRewardBlock
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await ctx.VDODO.methods.totalSupply().call(),
|
||||||
|
decimalStr("0")
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
@@ -47,6 +47,9 @@ export const DODO_CALLEE_HELPER_NAME = "DODOCalleeHelper"
|
|||||||
export const CROWD_POOLING_NAME = "CP"
|
export const CROWD_POOLING_NAME = "CP"
|
||||||
export const CROWD_POOLING_FACTORY = "CrowdPoolingFactory"
|
export const CROWD_POOLING_FACTORY = "CrowdPoolingFactory"
|
||||||
export const DODO_INCENTIVE = "DODOIncentive"
|
export const DODO_INCENTIVE = "DODOIncentive"
|
||||||
|
export const VDODO_NAME = "vDODOToken"
|
||||||
|
export const DODO_CULATION_HELPER = "DODOCirculationHelper"
|
||||||
|
export const DODO_GOVERNANCE = "Governance"
|
||||||
|
|
||||||
interface ContractJson {
|
interface ContractJson {
|
||||||
abi: any;
|
abi: any;
|
||||||
|
|||||||
120
test/utils/VDODOContext.ts
Normal file
120
test/utils/VDODOContext.ts
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2021 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, MAX_UINT256 } from './Converter';
|
||||||
|
import { EVM, getDefaultWeb3 } from './EVM';
|
||||||
|
import * as log from './Log';
|
||||||
|
|
||||||
|
BigNumber.config({
|
||||||
|
EXPONENTIAL_AT: 1000,
|
||||||
|
DECIMAL_PLACES: 80,
|
||||||
|
});
|
||||||
|
|
||||||
|
export class VDODOContext {
|
||||||
|
EVM: EVM;
|
||||||
|
Web3: Web3;
|
||||||
|
Deployer: string;
|
||||||
|
Maintainer: string;
|
||||||
|
SpareAccounts: string[];
|
||||||
|
|
||||||
|
//token
|
||||||
|
DODO: Contract;
|
||||||
|
VDODO: Contract;
|
||||||
|
|
||||||
|
DODOApprove: Contract;
|
||||||
|
DODOApproveProxy: Contract;
|
||||||
|
|
||||||
|
DODOCirculationHelper: Contract;
|
||||||
|
Governance: Contract;
|
||||||
|
|
||||||
|
lastRewardBlock:number;
|
||||||
|
alpha:number;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
this.EVM = new EVM();
|
||||||
|
this.Web3 = getDefaultWeb3();
|
||||||
|
|
||||||
|
this.DODO = await contracts.newContract(
|
||||||
|
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
||||||
|
["DODO Token", "DODO", 18]
|
||||||
|
);
|
||||||
|
|
||||||
|
this.DODOCirculationHelper = await contracts.newContract(
|
||||||
|
contracts.DODO_CULATION_HELPER,
|
||||||
|
[
|
||||||
|
this.DODO.options.address
|
||||||
|
]
|
||||||
|
);
|
||||||
|
this.DODOApprove = await contracts.newContract(
|
||||||
|
contracts.SMART_APPROVE
|
||||||
|
);
|
||||||
|
|
||||||
|
this.DODOApproveProxy = await contracts.newContract(
|
||||||
|
contracts.SMART_APPROVE_PROXY,
|
||||||
|
[this.DODOApprove.options.address]
|
||||||
|
)
|
||||||
|
|
||||||
|
this.VDODO = await contracts.newContract(
|
||||||
|
contracts.VDODO_NAME,
|
||||||
|
[
|
||||||
|
this.DODO.options.address,
|
||||||
|
this.DODOCirculationHelper.options.address,
|
||||||
|
this.DODOApproveProxy.options.address,
|
||||||
|
"VDODO Token", "VDODO"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
this.Governance = await contracts.newContract(
|
||||||
|
contracts.DODO_GOVERNANCE,
|
||||||
|
[this.VDODO.options.address]
|
||||||
|
)
|
||||||
|
|
||||||
|
const allAccounts = await this.Web3.eth.getAccounts();
|
||||||
|
this.Deployer = allAccounts[0];
|
||||||
|
this.Maintainer = allAccounts[1];
|
||||||
|
this.SpareAccounts = allAccounts.slice(2, 10);
|
||||||
|
|
||||||
|
await this.VDODO.methods.updateGovernance(
|
||||||
|
this.Governance.options.address
|
||||||
|
).send(this.sendParam(this.Deployer))
|
||||||
|
|
||||||
|
this.alpha = await this.VDODO.methods.alpha().call();
|
||||||
|
this.lastRewardBlock = await this.VDODO.methods.lastRewardBlock().call();
|
||||||
|
|
||||||
|
console.log("alpha = "+ this.alpha);
|
||||||
|
console.log("lastRewardBlock = " + this.lastRewardBlock);
|
||||||
|
console.log(log.blueText("[Init VDODO context]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendParam(sender, value = "0") {
|
||||||
|
return {
|
||||||
|
from: sender,
|
||||||
|
gas: process.env["COVERAGE"] ? 10000000000 : 7000000,
|
||||||
|
gasPrice: process.env.GAS_PRICE,
|
||||||
|
value: decimalStr(value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async mintTestToken(to: string, amount: string) {
|
||||||
|
await this.DODO.methods.mint(to, amount).send(this.sendParam(this.Deployer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getVDODOContext(): Promise<VDODOContext> {
|
||||||
|
var context = new VDODOContext();
|
||||||
|
await context.init();
|
||||||
|
return context;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user