Files
dodo-contractV2/test/utils/VDODOContext.ts

150 lines
4.0 KiB
TypeScript
Raw Normal View History

2021-02-01 17:27:44 +08:00
/*
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;
2021-02-04 17:21:18 +08:00
// Governance: Contract;
2021-02-01 17:27:44 +08:00
2021-02-03 00:05:45 +08:00
lastRewardBlock: number;
alpha: number;
2021-02-01 17:27:44 +08:00
constructor() { }
async init() {
this.EVM = new EVM();
this.Web3 = getDefaultWeb3();
2021-02-02 01:32:53 +08:00
const allAccounts = await this.Web3.eth.getAccounts();
this.Deployer = allAccounts[0];
this.Maintainer = allAccounts[1];
this.SpareAccounts = allAccounts.slice(2, 10);
2021-02-01 17:27:44 +08:00
this.DODO = await contracts.newContract(
contracts.MINTABLE_ERC20_CONTRACT_NAME,
["DODO Token", "DODO", 18]
);
this.DODOApprove = await contracts.newContract(
contracts.SMART_APPROVE
);
this.DODOApproveProxy = await contracts.newContract(
contracts.SMART_APPROVE_PROXY,
[this.DODOApprove.options.address]
)
2021-02-04 17:21:18 +08:00
// this.Governance = await contracts.newContract(
// contracts.DODO_GOVERNANCE,
// [
// this.DODO.options.address
// ]
// )
2021-02-02 16:16:21 +08:00
2021-02-01 17:27:44 +08:00
this.VDODO = await contracts.newContract(
contracts.VDODO_NAME,
[
2021-02-03 00:05:45 +08:00
"0x0000000000000000000000000000000000000000",
2021-02-04 17:21:18 +08:00
this.DODO.options.address,
2021-02-05 11:45:36 +08:00
this.DODOApproveProxy.options.address,
this.Deployer
2021-02-01 17:27:44 +08:00
]
)
2021-02-03 00:05:45 +08:00
this.DODOCirculationHelper = await contracts.newContract(
contracts.DODO_CULATION_HELPER,
[
this.VDODO.options.address,
this.DODO.options.address
]
);
2021-02-04 17:21:18 +08:00
// await this.Governance.methods.initOwner(
// this.Deployer
// ).send(this.sendParam(this.Deployer))
2021-02-03 00:05:45 +08:00
2021-02-04 17:21:18 +08:00
// await this.Governance.methods.setVDODOAddress(
// this.VDODO.options.address
// ).send(this.sendParam(this.Deployer))
2021-02-03 00:05:45 +08:00
await this.DODOApprove.methods.init(this.Deployer, this.DODOApproveProxy.options.address).send(this.sendParam(this.Deployer));
2021-02-02 01:32:53 +08:00
await this.DODOApproveProxy.methods.init(this.Deployer, [this.VDODO.options.address]).send(this.sendParam(this.Deployer));
await this.VDODO.methods.initOwner(
this.Deployer
2021-02-01 17:27:44 +08:00
).send(this.sendParam(this.Deployer))
2021-02-09 18:56:35 +08:00
2021-02-03 00:05:45 +08:00
await this.VDODO.methods.updateDODOCirculationHelper(this.DODOCirculationHelper.options.address).send(this.sendParam(this.Deployer));
2021-02-09 18:56:35 +08:00
await this.mintTestToken(allAccounts[8], decimalStr("10000"));
await this.approveProxy(allAccounts[8]);
2021-02-02 16:16:21 +08:00
2021-02-09 18:56:35 +08:00
await this.VDODO.methods.preDepositedBlockReward(decimalStr("10000")).send(this.sendParam(allAccounts[8]));
2021-02-03 00:05:45 +08:00
2021-02-09 18:56:35 +08:00
var lastRewardBlock = await this.VDODO.methods._LAST_REWARD_BLOCK_().call();
var curBlock = await this.Web3.eth.getBlockNumber();
console.log("init-block:" + lastRewardBlock + " blockNumber:" + curBlock)
2021-02-02 14:58:38 +08:00
2021-02-09 18:56:35 +08:00
await this.VDODO.methods.changePerReward(decimalStr("1")).send(this.sendParam(this.Deployer));
console.log(log.blueText("[Init VDODO context]"));
2021-02-01 17:27:44 +08:00
}
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));
}
2021-02-02 16:16:21 +08:00
2021-02-02 01:32:53 +08:00
async approveProxy(account: string) {
await this.DODO.methods
.approve(this.DODOApprove.options.address, MAX_UINT256)
.send(this.sendParam(account));
}
2021-02-01 17:27:44 +08:00
}
export async function getVDODOContext(): Promise<VDODOContext> {
var context = new VDODOContext();
await context.init();
return context;
}