upload test case
This commit is contained in:
@@ -13,9 +13,11 @@ contract Governance is InitializableOwnable {
|
|||||||
|
|
||||||
// ============ Storage ============
|
// ============ Storage ============
|
||||||
|
|
||||||
address immutable _DODO_TOKEN_;
|
address _DODO_TOKEN_;
|
||||||
|
|
||||||
constructor(address dodoToken) public {
|
constructor() public {
|
||||||
|
}
|
||||||
|
function setVDODOAddress(address dodoToken) public onlyOwner{
|
||||||
_DODO_TOKEN_ = dodoToken;
|
_DODO_TOKEN_ = dodoToken;
|
||||||
}
|
}
|
||||||
function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) {
|
function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) {
|
||||||
|
|||||||
@@ -159,7 +159,9 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard {
|
|||||||
superiorVDODO = DecimalMath.mulFloor(newVdodoAmount, _SUPERIOR_RATIO_);
|
superiorVDODO = DecimalMath.mulFloor(newVdodoAmount, _SUPERIOR_RATIO_);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mintToSuperior(user, superiorVDODO);
|
if (user.superior != address(0)) {
|
||||||
|
_mintToSuperior(user, superiorVDODO);
|
||||||
|
}
|
||||||
|
|
||||||
_updateAlpha(newAlpha);
|
_updateAlpha(newAlpha);
|
||||||
|
|
||||||
@@ -209,7 +211,7 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard {
|
|||||||
balance = user.VDODOAmount.sub(DecimalMath.divFloor(user.credit, getLatestAlpha()));
|
balance = user.VDODOAmount.sub(DecimalMath.divFloor(user.credit, getLatestAlpha()));
|
||||||
}
|
}
|
||||||
|
|
||||||
function availableBalanceOf(address account) public returns (uint256 balance) {
|
function availableBalanceOf(address account) public view returns (uint256 balance) {
|
||||||
uint256 lockedBalance = IGovernance(_DOOD_GOV_).getLockedvDODO(account);
|
uint256 lockedBalance = IGovernance(_DOOD_GOV_).getLockedvDODO(account);
|
||||||
balance = balanceOf(account).sub(lockedBalance);
|
balance = balanceOf(account).sub(lockedBalance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ async function init(ctx: VDODOContext): Promise<void> {
|
|||||||
await ctx.mintTestToken(account0, decimalStr("1000"));
|
await ctx.mintTestToken(account0, decimalStr("1000"));
|
||||||
await ctx.mintTestToken(account1, decimalStr("1000"));
|
await ctx.mintTestToken(account1, decimalStr("1000"));
|
||||||
|
|
||||||
|
await ctx.approveProxy(account0);
|
||||||
|
await ctx.approveProxy(account1);
|
||||||
|
await ctx.approveProxy(account2);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("VDODO", () => {
|
describe("VDODO", () => {
|
||||||
@@ -48,7 +51,6 @@ describe("VDODO", () => {
|
|||||||
describe("vdodo", () => {
|
describe("vdodo", () => {
|
||||||
|
|
||||||
it("vdodo init", async () => {
|
it("vdodo init", async () => {
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await ctx.DODO.methods.balanceOf(account0).call(),
|
await ctx.DODO.methods.balanceOf(account0).call(),
|
||||||
decimalStr("1000")
|
decimalStr("1000")
|
||||||
@@ -69,7 +71,35 @@ describe("VDODO", () => {
|
|||||||
await ctx.VDODO.methods.totalSupply().call(),
|
await ctx.VDODO.methods.totalSupply().call(),
|
||||||
decimalStr("0")
|
decimalStr("0")
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
it("vdodo first mint with no superior", async () => {
|
||||||
|
|
||||||
|
await ctx.VDODO.methods.mint(decimalStr("10"),"0x0000000000000000000000000000000000000000").send(ctx.sendParam(account0))
|
||||||
|
assert.equal(
|
||||||
|
await ctx.DODO.methods.balanceOf(account0).call(),
|
||||||
|
decimalStr("990")
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await await ctx.VDODO.methods.alpha().call(),
|
||||||
|
await ctx.alpha
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await ctx.DODO.methods.balanceOf(ctx.VDODO.options.address).call(),
|
||||||
|
decimalStr("10")
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
await ctx.VDODO.methods.balanceOf(account0).call(),
|
||||||
|
decimalStr("0.1")
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await ctx.VDODO.methods.totalSupply().call(),
|
||||||
|
decimalStr("0.1")
|
||||||
|
);
|
||||||
|
assert.notEqual(
|
||||||
|
await ctx.VDODO.methods.lastRewardBlock().call(),
|
||||||
|
ctx.lastRewardBlock
|
||||||
|
);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ export class VDODOContext {
|
|||||||
this.EVM = new EVM();
|
this.EVM = new EVM();
|
||||||
this.Web3 = getDefaultWeb3();
|
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.DODO = await contracts.newContract(
|
this.DODO = await contracts.newContract(
|
||||||
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
contracts.MINTABLE_ERC20_CONTRACT_NAME,
|
||||||
["DODO Token", "DODO", 18]
|
["DODO Token", "DODO", 18]
|
||||||
@@ -67,9 +72,14 @@ export class VDODOContext {
|
|||||||
[this.DODOApprove.options.address]
|
[this.DODOApprove.options.address]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
this.Governance = await contracts.newContract(
|
||||||
|
contracts.DODO_GOVERNANCE
|
||||||
|
)
|
||||||
this.VDODO = await contracts.newContract(
|
this.VDODO = await contracts.newContract(
|
||||||
contracts.VDODO_NAME,
|
contracts.VDODO_NAME,
|
||||||
[
|
[
|
||||||
|
this.Governance.options.address,
|
||||||
this.DODO.options.address,
|
this.DODO.options.address,
|
||||||
this.DODOCirculationHelper.options.address,
|
this.DODOCirculationHelper.options.address,
|
||||||
this.DODOApproveProxy.options.address,
|
this.DODOApproveProxy.options.address,
|
||||||
@@ -77,26 +87,31 @@ export class VDODOContext {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
this.Governance = await contracts.newContract(
|
await this.Governance.methods.initOwner(
|
||||||
contracts.DODO_GOVERNANCE,
|
this.Deployer
|
||||||
[this.VDODO.options.address]
|
).send(this.sendParam(this.Deployer))
|
||||||
)
|
|
||||||
|
|
||||||
const allAccounts = await this.Web3.eth.getAccounts();
|
await this.Governance.methods.setVDODOAddress(
|
||||||
this.Deployer = allAccounts[0];
|
this.VDODO.options.address
|
||||||
this.Maintainer = allAccounts[1];
|
).send(this.sendParam(this.Deployer))
|
||||||
this.SpareAccounts = allAccounts.slice(2, 10);
|
|
||||||
|
|
||||||
await this.VDODO.methods.updateGovernance(
|
await this.DODOApprove.methods.init(this.Deployer,this.DODOApproveProxy.options.address).send(this.sendParam(this.Deployer));
|
||||||
this.Governance.options.address
|
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))
|
).send(this.sendParam(this.Deployer))
|
||||||
|
|
||||||
this.alpha = await this.VDODO.methods.alpha().call();
|
this.alpha = await this.VDODO.methods.alpha().call();
|
||||||
this.lastRewardBlock = await this.VDODO.methods.lastRewardBlock().call();
|
this.lastRewardBlock = await this.VDODO.methods.lastRewardBlock().call();
|
||||||
|
|
||||||
|
console.log(log.blueText("[Init VDODO context]"));
|
||||||
|
|
||||||
console.log("alpha = "+ this.alpha);
|
console.log("alpha = "+ this.alpha);
|
||||||
console.log("lastRewardBlock = " + this.lastRewardBlock);
|
console.log("lastRewardBlock = " + this.lastRewardBlock);
|
||||||
console.log(log.blueText("[Init VDODO context]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendParam(sender, value = "0") {
|
sendParam(sender, value = "0") {
|
||||||
@@ -111,6 +126,14 @@ export class VDODOContext {
|
|||||||
async mintTestToken(to: string, amount: string) {
|
async mintTestToken(to: string, amount: string) {
|
||||||
await this.DODO.methods.mint(to, amount).send(this.sendParam(this.Deployer));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getVDODOContext(): Promise<VDODOContext> {
|
export async function getVDODOContext(): Promise<VDODOContext> {
|
||||||
|
|||||||
Reference in New Issue
Block a user