From 126acd6bdf97619951412163ccc621204cebe0b7 Mon Sep 17 00:00:00 2001 From: owen05 Date: Tue, 2 Feb 2021 16:16:21 +0800 Subject: [PATCH] vDODO test frameWork update --- contracts/DODOToken/Governance.sol | 9 +-- test/utils/VDODOContext.ts | 22 +++--- test/vDODO/erc20.test.ts | 68 +++++++++++++++++++ test/vDODO/global.test.ts | 64 +++++++++++++++++ .../mintRedeem.test.ts} | 52 ++++++++++++-- 5 files changed, 193 insertions(+), 22 deletions(-) create mode 100644 test/vDODO/erc20.test.ts create mode 100644 test/vDODO/global.test.ts rename test/{Token/vdodo.test.ts => vDODO/mintRedeem.test.ts} (76%) diff --git a/contracts/DODOToken/Governance.sol b/contracts/DODOToken/Governance.sol index 8cca54d..9c950d2 100644 --- a/contracts/DODOToken/Governance.sol +++ b/contracts/DODOToken/Governance.sol @@ -13,15 +13,12 @@ contract Governance is InitializableOwnable { // ============ Storage ============ - address _DODO_TOKEN_; + address immutable _DODO_TOKEN_; - constructor() public { + constructor(dodoToken) public { + _DODO_TOKEN_ = dodoToken } - function setVDODOAddress(address dodoToken) public onlyOwner{ - _DODO_TOKEN_ = dodoToken; - } - function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) { lockedvDODO = 0;//DOTO,0 for test } diff --git a/test/utils/VDODOContext.ts b/test/utils/VDODOContext.ts index 8c447ac..e7ea044 100644 --- a/test/utils/VDODOContext.ts +++ b/test/utils/VDODOContext.ts @@ -72,10 +72,13 @@ export class VDODOContext { [this.DODOApprove.options.address] ) - this.Governance = await contracts.newContract( - contracts.DODO_GOVERNANCE + contracts.DODO_GOVERNANCE, + [ + this.DODO.options.address + ] ) + this.VDODO = await contracts.newContract( contracts.VDODO_NAME, [ @@ -91,23 +94,20 @@ export class VDODOContext { this.Deployer ).send(this.sendParam(this.Deployer)) - await this.Governance.methods.setVDODOAddress( - this.VDODO.options.address - ).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.VDODO.options.address]).send(this.sendParam(this.Deployer)); - - await this.VDODO.methods.initOwner( this.Deployer ).send(this.sendParam(this.Deployer)) + await this.VDODO.methods.changePerReward(decimalStr("1")).send(this.sendParam(this.Deployer)); + await this.mintTestToken(this.VDODO.options.address, decimalStr("100000")); + this.alpha = await this.VDODO.methods.alpha().call(); this.lastRewardBlock = await this.VDODO.methods.lastRewardBlock().call(); - + console.log(log.blueText("[Init VDODO context]")); console.log("init alpha = " + this.alpha); @@ -126,13 +126,11 @@ export class VDODOContext { async mintTestToken(to: string, amount: string) { await this.DODO.methods.mint(to, amount).send(this.sendParam(this.Deployer)); } + async approveProxy(account: string) { await this.DODO.methods .approve(this.DODOApprove.options.address, MAX_UINT256) .send(this.sendParam(account)); - await this.VDODO.methods - .approve(this.DODOApprove.options.address, MAX_UINT256) - .send(this.sendParam(account)); } } diff --git a/test/vDODO/erc20.test.ts b/test/vDODO/erc20.test.ts new file mode 100644 index 0000000..ff0d4a5 --- /dev/null +++ b/test/vDODO/erc20.test.ts @@ -0,0 +1,68 @@ +/* + + Copyright 2021 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +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'; + +let account0: string; +let account1: string; + +async function init(ctx: VDODOContext): Promise { + account0 = ctx.SpareAccounts[0]; + account1 = ctx.SpareAccounts[1]; + + await ctx.mintTestToken(account0, decimalStr("1000")); + await ctx.mintTestToken(account1, decimalStr("1000")); + + await ctx.approveProxy(account0); + await ctx.approveProxy(account1); +} + +describe("vDODO-erc20", () => { + let snapshotId: string; + let ctx: VDODOContext; + + before(async () => { + ctx = await getVDODOContext(); + //打开transfer开关 + await init(ctx); + }); + + beforeEach(async () => { + snapshotId = await ctx.EVM.snapshot(); + }); + + afterEach(async () => { + await ctx.EVM.reset(snapshotId); + }); + + describe("vdodo-erc20", () => { + + it("transfer-vdodo", async () => { + //检查四个人 【包括from, to 以及各自的上级】,info变化 + //alpha lastRewardBlock + //各自dodo余额变化 + }); + + it("transferFrom-vdodo", async () => { + //检查四个人 【包括from, to 以及各自的上级】,info变化 + //alpha lastRewardBlock + //各自dodo余额变化 + //approve 状态变化 + + + //再次transferFrom 预期revert + }); + + it("transfer - close", async () => { + //预期revert + }); + }) +}); diff --git a/test/vDODO/global.test.ts b/test/vDODO/global.test.ts new file mode 100644 index 0000000..41d5afa --- /dev/null +++ b/test/vDODO/global.test.ts @@ -0,0 +1,64 @@ +/* + + Copyright 2021 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +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'; + +let account0: string; +let account1: string; + +async function init(ctx: VDODOContext): Promise { + account0 = ctx.SpareAccounts[0]; + account1 = ctx.SpareAccounts[1]; + + await ctx.mintTestToken(account0, decimalStr("1000")); + await ctx.mintTestToken(account1, decimalStr("1000")); + + await ctx.approveProxy(account0); + await ctx.approveProxy(account1); +} + +describe("vDODO-owner", () => { + 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-erc20", () => { + + it("change-reward", async () => { + //改变前alpha lastRewardBlock 状态 + + //change-reward + + //改变后状态 + }); + + + it("donate", async () => { + //改变前alpha lastRewardBlock 状态 + + //change-reward + + //改变后状态 + }); + }) +}); diff --git a/test/Token/vdodo.test.ts b/test/vDODO/mintRedeem.test.ts similarity index 76% rename from test/Token/vdodo.test.ts rename to test/vDODO/mintRedeem.test.ts index 1f210a7..2474472 100644 --- a/test/Token/vdodo.test.ts +++ b/test/vDODO/mintRedeem.test.ts @@ -12,25 +12,23 @@ 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 { account0 = ctx.SpareAccounts[0]; account1 = ctx.SpareAccounts[1]; - account2 = ctx.SpareAccounts[2]; await ctx.mintTestToken(account0, decimalStr("1000")); await ctx.mintTestToken(account1, decimalStr("1000")); await ctx.approveProxy(account0); await ctx.approveProxy(account1); - await ctx.approveProxy(account2); } +//TODO: 抽象出来mint func + describe("VDODO", () => { let snapshotId: string; let ctx: VDODOContext; @@ -72,6 +70,52 @@ describe("VDODO", () => { decimalStr("0") ); }); + + + it("vdodo-mint-first", async () => { + //第一次mint 后 + //alpha lastRewardBlock 状态 + //user superior info 状态 + //vDODO 总量变化,以及vDODO合约dodo余额,user dodo余额 + + }); + + it("vdodo-mint-second", async () => { + //第二次mint 后(传入之前的superior地址) + //alpha lastRewardBlock 状态 + //user superior info 状态 + //vDODO 总量变化,以及vDODO合约dodo余额,user dodo余额 + }); + + + it("vdodo-mint-second-otherSuperior", async () => { + //第二次mint 后(传入非之前superior地址) + //alpha lastRewardBlock 状态 + //user superior info 状态 + //vDODO 总量变化,以及vDODO合约dodo余额,user dodo余额 + }); + + + it("redeem-amount-read", async () => { + //正确读取 withdrawAmount 字段 + }); + + it("redeem-partial-haveMint", async () => { + + }); + + it("redeem-partial-NotMint", async () => { + //多个下级引用 + }); + + it("redeem-all-haveMint", async () => { + + }); + + it("redeem-all-NoMint", async () => { + //多个下级引用 + }); + // it("vdodo first mint with no superior", async () => { // await ctx.VDODO.methods.mint(decimalStr("10"),"0x0000000000000000000000000000000000000000").send(ctx.sendParam(account0))