This commit is contained in:
owen05
2022-02-15 09:31:46 +08:00
parent 7ac5b8a403
commit 6b6ace5155
10 changed files with 391 additions and 17 deletions

View File

@@ -0,0 +1,90 @@
/*
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 { DODOStarterContext,getDODOStarterContext } from '../utils/DODOStarterContext';
import { assert } from 'chai';
import * as contracts from '../utils/Contracts';
import BigNumber from 'bignumber.js';
import { StringLiteralLike } from 'typescript';
const truffleAssert = require('truffle-assertions');
let maker: string;
let user: string;
async function init(ctx: NFTPoolContext): Promise<void> {
maker = ctx.SpareAccounts[0];
user = ctx.SpareAccounts[1];
}
async function createFairFunding(ctx: DODOStarterContext) {
// var tx = await logGas(ctx.DODONFTPoolProxy.methods.createNewNFTPoolV1(
// maker,
// ctx.DodoNft.options.address,
// 1,
// ['Filter01', 'FRAG', 'FRAG'],
// [decimalStr("10000000"), decimalStr("0.005")],
// [true, true, true],
// [0, 4, 5, 1],
// [decimalStr("1"), decimalStr("0.9"), decimalStr("1"), decimalStr("0.9"), decimalStr("2"), decimalStr("0.9")],
// [7]
// ), ctx.sendParam(maker), "createNewNFTPoolV1");
// var newFilterAdmin = tx.events['CreateNFTPool'].returnValues['newFilterAdmin']
// var filter = tx.events['CreateNFTPool'].returnValues['filter']
// return [newFilterAdmin, filter];
}
describe("FairFunding", () => {
let snapshotId: string;
let ctx: DODOStarterContext;
before(async () => {
ctx = await getDODOStarterContext();
await init(ctx);
});
beforeEach(async () => {
snapshotId = await ctx.EVM.snapshot();
});
afterEach(async () => {
await ctx.EVM.reset(snapshotId);
});
describe("FairFunding", () => {
it("Create_FairFunding", async () => {
// var tx = await logGas(ctx.DODONFTPoolProxy.methods.createNewNFTPoolV1(
// maker,
// ctx.DodoNft.options.address,
// 1,
// ['Filter01', 'FRAG', 'FRAG'],
// [decimalStr("10000000"), decimalStr("0.005")],
// [true, true, true],
// [0, 3, 2, 1],
// [decimalStr("1"), decimalStr("1.1"), decimalStr("1"), decimalStr("1.1"), decimalStr("2"), decimalStr("1.1")],
// [5]
// ), ctx.sendParam(maker), "createNewNFTPoolV1");
// var newFilterAdmin = tx.events['CreateNFTPool'].returnValues['newFilterAdmin']
// var filter = tx.events['CreateNFTPool'].returnValues['filter']
// console.log("newFilterAdmin:", newFilterAdmin)
// console.log("filterV1:", filter)
// assert.equal(
// tx.events['CreateNFTPool'].returnValues['filterAdminOwner'],
// maker
// )
});
});
});

View File

View File

@@ -85,6 +85,12 @@ export const DODO_NFT_APPROVE = "DODONFTApprove"
export const DODO_NFT_POOL_PROXY = "DODONFTPoolProxy"
export const DODO_STARTER_PROXY = "DODOStarterProxy"
export const DODO_STARTER_FACTORY = "DODOStarterFactory"
export const FAIR_FUNDING = "FairFunding"
export const INSTANT_FUNDING = "InstantFunding"
interface ContractJson {
abi: any;
networks: { [network: number]: any };

View File

@@ -0,0 +1,108 @@
/*
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 DODOStarterContext {
EVM: EVM;
Web3: Web3;
//contract
DODOStarterFactory: Contract;
//account
Deployer: string;
Maintainer: string;
SpareAccounts: string[];
//token
SellToken: Contract;
FundToken: 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.SellToken = await contracts.newContract(
contracts.MINTABLE_ERC20_CONTRACT_NAME,
["SellToken", "DODO", 18]
);
this.FundToken = await contracts.newContract(
contracts.MINTABLE_ERC20_CONTRACT_NAME,
["FundToken", "USDT", 18]
);
let cloneFactory = await contracts.newContract(
contracts.CLONE_FACTORY_CONTRACT_NAME
);
let fairFundingTemplate = await contracts.newContract(
contracts.FAIR_FUNDING
)
let instantFundingTemplate = await contracts.newContract(
contracts.INSTANT_FUNDING
)
this.DODOStarterFactory = await contracts.newContract(contracts.DODO_STARTER_FACTORY,
[
cloneFactory.options.address,
fairFundingTemplate.options.address,
instantFundingTemplate.options.address
]
)
await this.DODOStarterFactory.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer));
console.log(log.blueText("[Init DODOStarter 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 getDODOStarterContext(): Promise<DODOStarterContext> {
var context = new DODOStarterContext();
await context.init();
return context;
}