add proxy test framework

This commit is contained in:
owen05
2020-11-24 16:12:38 +08:00
parent 71e1d8717c
commit 5e6db3e4b6
7 changed files with 334 additions and 29 deletions

View File

@@ -35,6 +35,12 @@ export const DVM_PROXY_NAME = "DVMProxy"
export const CONST_FEE_RATE_MODEL_NAME = "ConstFeeRateModel"
export const PERMISSION_MANAGER_NAME = "PermissionManager"
export const EXTERNAL_VALUE_NAME = "ExternalValue"
export const DODO_PROXY_NAME = "DODOV2Proxy01"
export const FEE_RATE_MODEL_NAME = "FeeRateModel"
export const DPP_NAME = "DPP"
export const DPP_FACTORY_NAME = "DPPFactory"
export const SMART_APPROVE = "SmartApprove"
export const DODO_SELL_HELPER = "DODOSellHelper"
interface ContractJson {
abi: any;

View File

@@ -8,4 +8,8 @@ export function decimalStr(value: string): string {
export function gweiStr(gwei: string): string {
return new BigNumber(gwei).multipliedBy(10 ** 9).toFixed(0, BigNumber.ROUND_DOWN)
}
}
export function mweiStr(gwei: string): string {
return new BigNumber(gwei).multipliedBy(10 ** 6).toFixed(0, BigNumber.ROUND_DOWN)
}s

147
test/utils/ProxyContext.ts Normal file
View File

@@ -0,0 +1,147 @@
/*
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, MAX_UINT256 } from './Converter';
import { EVM, getDefaultWeb3 } from './EVM';
import * as log from './Log';
BigNumber.config({
EXPONENTIAL_AT: 1000,
DECIMAL_PLACES: 80,
});
export class ProxyContext {
EVM: EVM;
Web3: Web3;
DODOProxy: Contract;
DVMFactory: Contract;
DPPFactory: Contract;
SmartApprove: Contract;
//token
DODO: Contract;
USDT: Contract;
WETH: Contract;
Deployer: string;
Maintainer: string;
SpareAccounts: string[];
constructor() { }
async init() {
this.EVM = new EVM();
this.Web3 = getDefaultWeb3();
var WETH = await contracts.newContract(
contracts.WETH_CONTRACT_NAME
);
var cloneFactory = await contracts.newContract(
contracts.CLONE_FACTORY_CONTRACT_NAME
);
var dvmTemplate = await contracts.newContract(contracts.DVM_NAME)
var dppTemplate = await contracts.newContract(contracts.DPP_NAME)
var feeRateModelTemplate = await contracts.newContract(contracts.FEE_RATE_MODEL_NAME)
var permissionManagerTemplate = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
var vauleSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME)
this.DVMFactory = await contracts.newContract(contracts.DVM_FACTORY_NAME,
[
cloneFactory.options.address,
dvmTemplate.options.address,
feeRateModelTemplate.options.address,
permissionManagerTemplate.options.address,
vauleSource.options.address
]
)
this.DPPFactory = await contracts.newContract(contracts.DPP_FACTORY_NAME,
[
cloneFactory.options.address,
dppTemplate.options.address,
feeRateModelTemplate.options.address,
permissionManagerTemplate.options.address,
vauleSource.options.address
]
)
this.SmartApprove = await contracts.newContract(
contracts.SMART_APPROVE
);
var dodoSellHelper = await contracts.newContract(
contracts.DODO_SELL_HELPER
);
this.DODOProxy = await contracts.newContract(contracts.DODO_PROXY_NAME,
[
dvmFactory.options.address,
dppFactory.options.address,
WETH.options.address,
smartApprove.options.address,
dodoSellHelper.options.address
]
);
this.DODO = await contracts.newContract(
contracts.MINTABLE_ERC20_CONTRACT_NAME,
["DODO Token", "DODO", 18]
);
this.USDT = await contracts.newContract(
contracts.MINTABLE_ERC20_CONTRACT_NAME,
["USDT Token", "USDT", 6]
);
this.WETH = await contracts.newContract(
contracts.WETH_CONTRACT_NAME
);
const allAccounts = await this.Web3.eth.getAccounts();
this.Deployer = allAccounts[0];
this.Maintainer = allAccounts[1];
this.SpareAccounts = allAccounts.slice(2, 10);
console.log(log.blueText("[Init DVM 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, token: Contract, amount: string) {
await token.methods.mint(to, amount).send(this.sendParam(this.Deployer));
}
async approveProxy(account: string) {
await this.DODO.methods
.approve(this.SmartApprove.options.address, MAX_UINT256)
.send(this.sendParam(account));
await this.USDT.methods
.approve(this.SmartApprove.options.address, MAX_UINT256)
.send(this.sendParam(account));
await this.WETH.methods
.approve(this.SmartApprove.options.address, MAX_UINT256)
.send(this.sendParam(account));
}
}
export async function getProxyContext(): Promise<ProxyContext> {
var context = new ProxyContext();
await context.init();
return context;
}