update test

This commit is contained in:
牛涛涛
2021-01-22 12:39:26 +08:00
parent 4acb508a15
commit ccf921a7d2
6 changed files with 36 additions and 36 deletions

View File

@@ -62,20 +62,20 @@ describe("Funding", () => {
it("bid and cancel", async () => {
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("100")).send(ctx.sendParam(bidder1))
await logGas(ctx.CP.methods.bid(bidder1), ctx.sendParam(bidder1), "bid")
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("99.9"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("99.9"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0.1"))
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("100"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("100"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0"))
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("50")).send(ctx.sendParam(bidder2))
await ctx.CP.methods.bid(bidder2).send(ctx.sendParam(bidder2))
assert.equal(await ctx.CP.methods.getShares(bidder2).call(), decimalStr("49.95"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("149.85"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0.15"))
assert.equal(await ctx.CP.methods.getShares(bidder2).call(), decimalStr("50"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("150"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0"))
await ctx.EVM.increaseTime(86400)
await logGas(ctx.CP.methods.cancel(bidder1, decimalStr("20"),"0x"), ctx.sendParam(bidder1), "cancel")
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("79.9"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("129.85"))
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("80"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("130"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("920"))
})

View File

@@ -62,20 +62,20 @@ describe("Funding", () => {
it("cancel by callee contract", async () => {
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("0.1")).send(ctx.sendParam(bidder1))
await logGas(ctx.CP.methods.bid(bidder1), ctx.sendParam(bidder1), "bidder1 bid")
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.0999"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.0999"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0.0001"))
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.1"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.1"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("0"))
await logGas(ctx.CP.methods.cancel(bidder1, decimalStr("0.05"),"0x"), ctx.sendParam(bidder1), "cancel and get 0.05 weth")
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.0499"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.0499"))
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.05"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.05"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("0.05"))
let beforeEthBalance = await ctx.Web3.eth.getBalance(bidder1);
let receipt = await logGas(ctx.CP.methods.cancel(ctx.DODOCallee.options.address, decimalStr("0.02"),"0x00"), ctx.sendParam(bidder1), "cancel and get 0.02 eth")
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.0299"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.0299"))
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.03"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.03"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("0.05"))
let afterEthBalance = await ctx.Web3.eth.getBalance(bidder1);
assert.equal(Number.parseInt(receipt["events"]["1"]["raw"]["data"],16),Number(decimalStr("0.02")));
@@ -92,26 +92,26 @@ describe("Funding", () => {
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("0.5")).send(ctx.sendParam(bidder2))
await logGas(ctx.CP.methods.bid(bidder2), ctx.sendParam(bidder2), "bidder2 bid")
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.4995"))
assert.equal(await ctx.CP.methods.getShares(bidder2).call(), decimalStr("0.4995"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("0.999"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("0.999"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0.001"))
assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("0.5"))
assert.equal(await ctx.CP.methods.getShares(bidder2).call(), decimalStr("0.5"))
assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("1"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("1"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.Maintainer).call(), decimalStr("0"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("0"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), decimalStr("0.5"))
await ctx.EVM.increaseTime(86400 *2)
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("0.499"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("0.5"))
await ctx.EVM.increaseTime(86400 * 2)
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "0")
let receipt1 = await logGas(await ctx.CP.methods.bidderClaim(bidder1,"0x"),ctx.sendParam(bidder1),"claim");
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("0.2495"))
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("0.25"))
let receipt2 = await logGas(await ctx.CP.methods.bidderClaim(ctx.DODOCallee.options.address,"0x00"),ctx.sendParam(bidder2),"claim");
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), decimalStr("0.5"))
assert.equal(Number.parseInt(receipt2["events"]["3"]["raw"]["data"],16),Number(decimalStr("0.2495")));
assert.equal(Number.parseInt(receipt2["events"]["3"]["raw"]["data"],16),Number(decimalStr("0.25")));
})

View File

@@ -99,7 +99,7 @@ describe("Funding", () => {
assert.equal(await pool.methods.getMidPrice().call(), "10000000003162277660")
assert.equal(await ctx.CP.methods._AVG_SETTLED_PRICE_().call(), "10000000000000000000")
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), decimalStr("49900"))
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), decimalStr("50000"))
assert.equal(await ctx.CP.methods._UNUSED_BASE_().call(), "5000000000000000000000")
assert.equal(await ctx.BASE.methods.balanceOf(ctx.Deployer).call(), "0")
@@ -107,7 +107,7 @@ describe("Funding", () => {
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "5000000000000000000000")
assert.equal(await ctx.QUOTE.methods.balanceOf(poolAddress).call(), decimalStr("50000"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("49900"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("50000"))
})
it("bid zero", async () => {

View File

@@ -74,14 +74,14 @@ describe("Funding", () => {
assert.equal(await pool.methods.getMidPrice().call(), "10000000003162277660")
assert.equal(await ctx.CP.methods._AVG_SETTLED_PRICE_().call(), "10000000000000000000")
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), decimalStr("49900"))
assert.equal(await ctx.CP.methods._UNUSED_QUOTE_().call(), decimalStr("50000"))
assert.equal(await ctx.CP.methods._UNUSED_BASE_().call(), "5000000000000000000000")
assert.equal(await ctx.BASE.methods.balanceOf(poolAddress).call(), "5000000000000000000000")
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "5000000000000000000000")
assert.equal(await ctx.QUOTE.methods.balanceOf(poolAddress).call(), decimalStr("50000"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("49900"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("50000"))
})
})

View File

@@ -68,15 +68,15 @@ describe("Funding", () => {
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "2997000000000000000000")
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "3000000000000000000000")
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), "0")
await ctx.CP.methods.bidderClaim(bidder1, "0x").send(ctx.sendParam(bidder1))
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "999000000000000000000")
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "1000000000000000000000")
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), "0")
await ctx.CP.methods.bidderClaim(bidder2, "0x").send(ctx.sendParam(bidder2))
assert.equal(await ctx.BASE.methods.balanceOf(bidder2).call(), "1998000000000000000000")
assert.equal(await ctx.BASE.methods.balanceOf(bidder2).call(), "2000000000000000000000")
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), "0")
})
@@ -92,15 +92,15 @@ describe("Funding", () => {
await logGas(ctx.CP.methods.settle(), ctx.sendParam(ctx.Deployer), "settle")
assert.equal(await ctx.BASE.methods.balanceOf(ctx.CP.options.address).call(), "5000000000000000000000")
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("39910"))
assert.equal(await ctx.QUOTE.methods.balanceOf(ctx.CP.options.address).call(), decimalStr("40000"))
await ctx.CP.methods.bidderClaim(bidder1, "0x").send(ctx.sendParam(bidder1))
assert.equal(await ctx.BASE.methods.balanceOf(bidder1).call(), "1666666666666666666666")
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), "13303333333333333333333")
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), "13333333333333333333333")
await ctx.CP.methods.bidderClaim(bidder2, "0x").send(ctx.sendParam(bidder2))
assert.equal(await ctx.BASE.methods.balanceOf(bidder2).call(), "3333333333333333333333")
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), "26606666666666666666666")
assert.equal(await ctx.QUOTE.methods.balanceOf(bidder2).call(), "26666666666666666666666")
})
it("withdraw lp token", async () => {

View File

@@ -73,7 +73,7 @@ export class CPContext {
if(config.quoteTokenContract){
this.QUOTE = await contracts.newContract(
config.quoteTokenContract,
["TestQuote", "QUOTE", 18]
["WETH9", "WETH9", 18]
);
}else{
this.QUOTE = await contracts.newContract(