This commit is contained in:
owen05
2021-04-08 16:16:11 +08:00
parent 4b54b452ee
commit 2e1b0e0e9b
10 changed files with 234 additions and 8 deletions

View File

@@ -32,7 +32,6 @@ export const DVM_VAULT_NAME = "DVMVault"
export const DVM_NAME = "DVM"
export const DVM_FACTORY_NAME = "DVMFactory"
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 FEE_RATE_MODEL_NAME = "FeeRateModel"
@@ -55,6 +54,16 @@ export const DODO_PROXY_NAME = "DODOV2Proxy02"
export const ERC20_MINE = "ERC20Mine"
export const VDODO_MINE = "vDODOMine"
export const NFT_VAULT = "NFTCollateralVault"
export const NFT_FEE = "FeeDistributor"
export const NFT_FRAG = "Fragment"
export const ERC721 = "InitializableERC721"
export const ERC1155 = "InitializableERC1155"
export const CONST_FEE_RATE_MODEL_NAME = "ConstFeeRateModel"
export const NFT_TOKEN_FACTORY = "NFTTokenFactory"
export const NFT_REGISTER = "DODONFTRegistry"
export const NFT_PROXY = "DODONFTProxy"
interface ContractJson {
abi: any;
networks: { [network: number]: any };

153
test/utils/NFTContext.ts Normal file
View File

@@ -0,0 +1,153 @@
/*
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 NFTContext {
EVM: EVM;
Web3: Web3;
NFTTokenFacotry: Contract;
NFTRegister: Contract;
CollatteralVault: Contract;
Fragment: Contract;
NFTFee: Contract;
NFTProxy: Contract;
DODOApprove: Contract;
DODOApproveProxy: Contract;
//token
USDT: Contract;
WETH: Contract;
Deployer: string;
Maintainer: string;
SpareAccounts: string[];
constructor() { }
async init(weth: string) {
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.WETH = contracts.getContractWithAddress(contracts.WETH_CONTRACT_NAME, weth);
this.USDT = await contracts.newContract(
contracts.MINTABLE_ERC20_CONTRACT_NAME,
["USDT Token", "USDT", 6]
);
var cloneFactory = await contracts.newContract(
contracts.CLONE_FACTORY_CONTRACT_NAME
);
var dvmTemplate = await contracts.newContract(contracts.DVM_NAME)
var constFeeTemplate = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME)
var ERC721Template = await contracts.newContract(contracts.ERC721)
var ERC1155Template = await contracts.newContract(contracts.ERC1155)
this.NFTTokenFacotry = await contracts.newContract(contracts.NFT_TOKEN_FACTORY,
[
cloneFactory.options.address,
ERC721Template.options.address,
ERC1155Template.options.address
]
)
this.DODOApprove = await contracts.newContract(
contracts.SMART_APPROVE
);
this.DODOApproveProxy = await contracts.newContract(
contracts.SMART_APPROVE_PROXY,
[this.DODOApprove.options.address]
)
this.NFTRegister = await contracts.newContract(contracts.NFT_REGISTER)
await this.NFTRegister.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer));
this.CollatteralVault = await contracts.newContract(
contracts.NFT_VAULT
);
this.Fragment = await contracts.newContract(contracts.NFT_FRAG)
this.NFTFee = await contracts.newContract(contracts.NFT_FEE)
this.NFTProxy = await contracts.newContract(contracts.NFT_PROXY,
[
cloneFactory.options.address,
this.WETH.options.address,
this.DODOApproveProxy.options.address,
this.Deployer,
this.CollatteralVault.options.address,
this.Fragment.options.address,
this.NFTFee.options.address,
dvmTemplate.options.address,
constFeeTemplate.options.address,
this.NFTRegister.options.address
]
)
await this.NFTProxy.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer));
await this.DODOApprove.methods.init(this.Deployer, this.DODOApproveProxy.options.address).send(this.sendParam(this.Deployer));
await this.DODOApproveProxy.methods.init(this.Deployer, [this.NFTProxy.options.address]).send(this.sendParam(this.Deployer));
console.log(log.blueText("[Init DODONFT 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) {
await this.USDT.methods
.approve(this.DODOApprove.options.address, MAX_UINT256)
.send(this.sendParam(account));
await this.WETH.methods
.approve(this.DODOApprove.options.address, MAX_UINT256)
.send(this.sendParam(account));
}
}
export async function getDODONftContext(weth: string): Promise<NFTContext> {
var context = new NFTContext();
await context.init(weth);
return context;
}

View File

@@ -162,7 +162,7 @@ export class ProxyContext {
[this.WETH.options.address]
)
console.log(log.blueText("[Init DVM context]"));
console.log(log.blueText("[Init ProxyV2 context]"));
}
sendParam(sender, value = "0") {