Crowd Pooling test

This commit is contained in:
mingda
2020-12-13 17:47:47 +08:00
parent dc12b1d42d
commit b398f5b87d
10 changed files with 411 additions and 46 deletions

View File

@@ -8,10 +8,10 @@
// import * as assert from 'assert';
import { decimalStr } from '../utils/Converter';
// import { logGas } from '../utils/Log';
import { logGas } from '../utils/Log';
import { CPContext, CPContextInitConfig } from '../utils/CrowdPoolingContext';
// import { assert } from 'chai';
import BigNumber from 'bignumber.js';
import { assert } from 'chai';
const truffleAssert = require('truffle-assertions');
let bidder1: string;
@@ -32,7 +32,6 @@ describe("Funding", () => {
before(async () => {
config = {
totalBase: decimalStr("10000"),
poolBaseReserve: decimalStr("5000"),
poolQuoteCap: decimalStr("50000"),
ownerQuoteRatio: decimalStr("0.1"),
k: decimalStr("0.5"),
@@ -59,7 +58,23 @@ describe("Funding", () => {
it("bid", async () => {
await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("100")).send(ctx.sendParam(bidder1))
await ctx.CP.methods.bid(bidder1).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"))
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"))
await ctx.EVM.increaseTime(86400)
await logGas(ctx.CP.methods.cancel(bidder1, decimalStr("20")), 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.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("920"))
})
})
})