diff --git a/contracts/DODOToken/Governance.sol b/contracts/DODOToken/Governance.sol index 4f2371d..d06a787 100644 --- a/contracts/DODOToken/Governance.sol +++ b/contracts/DODOToken/Governance.sol @@ -13,9 +13,11 @@ contract Governance is InitializableOwnable { // ============ Storage ============ - address immutable _DODO_TOKEN_; + address _DODO_TOKEN_; - constructor(address dodoToken) public { + constructor() public { + } + function setVDODOAddress(address dodoToken) public onlyOwner{ _DODO_TOKEN_ = dodoToken; } function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) { diff --git a/contracts/DODOToken/vDODOToken.sol b/contracts/DODOToken/vDODOToken.sol index 9a29e6e..818ef3c 100644 --- a/contracts/DODOToken/vDODOToken.sol +++ b/contracts/DODOToken/vDODOToken.sol @@ -159,7 +159,9 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { superiorVDODO = DecimalMath.mulFloor(newVdodoAmount, _SUPERIOR_RATIO_); } - _mintToSuperior(user, superiorVDODO); + if (user.superior != address(0)) { + _mintToSuperior(user, superiorVDODO); + } _updateAlpha(newAlpha); @@ -209,7 +211,7 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { 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); balance = balanceOf(account).sub(lockedBalance); } diff --git a/test/Token/vdodo.test.ts b/test/Token/vdodo.test.ts index 9538008..c264f09 100644 --- a/test/Token/vdodo.test.ts +++ b/test/Token/vdodo.test.ts @@ -26,6 +26,9 @@ async function init(ctx: VDODOContext): Promise { await ctx.mintTestToken(account0, decimalStr("1000")); await ctx.mintTestToken(account1, decimalStr("1000")); + await ctx.approveProxy(account0); + await ctx.approveProxy(account1); + await ctx.approveProxy(account2); } describe("VDODO", () => { @@ -48,7 +51,6 @@ describe("VDODO", () => { describe("vdodo", () => { it("vdodo init", async () => { - assert.equal( await ctx.DODO.methods.balanceOf(account0).call(), decimalStr("1000") @@ -69,7 +71,35 @@ describe("VDODO", () => { await ctx.VDODO.methods.totalSupply().call(), 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 + ); }); }) }); diff --git a/test/utils/VDODOContext.ts b/test/utils/VDODOContext.ts index 3827889..4a44c0b 100644 --- a/test/utils/VDODOContext.ts +++ b/test/utils/VDODOContext.ts @@ -47,6 +47,11 @@ export class VDODOContext { 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.DODO = await contracts.newContract( contracts.MINTABLE_ERC20_CONTRACT_NAME, ["DODO Token", "DODO", 18] @@ -67,9 +72,14 @@ export class VDODOContext { [this.DODOApprove.options.address] ) + + this.Governance = await contracts.newContract( + contracts.DODO_GOVERNANCE + ) this.VDODO = await contracts.newContract( contracts.VDODO_NAME, [ + this.Governance.options.address, this.DODO.options.address, this.DODOCirculationHelper.options.address, this.DODOApproveProxy.options.address, @@ -77,26 +87,31 @@ export class VDODOContext { ] ) - this.Governance = await contracts.newContract( - contracts.DODO_GOVERNANCE, - [this.VDODO.options.address] - ) + await this.Governance.methods.initOwner( + this.Deployer + ).send(this.sendParam(this.Deployer)) - const allAccounts = await this.Web3.eth.getAccounts(); - this.Deployer = allAccounts[0]; - this.Maintainer = allAccounts[1]; - this.SpareAccounts = allAccounts.slice(2, 10); + await this.Governance.methods.setVDODOAddress( + this.VDODO.options.address + ).send(this.sendParam(this.Deployer)) - await this.VDODO.methods.updateGovernance( - this.Governance.options.address + 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)) 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("alpha = "+ this.alpha); console.log("lastRewardBlock = " + this.lastRewardBlock); - console.log(log.blueText("[Init VDODO context]")); } sendParam(sender, value = "0") { @@ -111,6 +126,14 @@ 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)); + } } export async function getVDODOContext(): Promise {