Skip to content

Commit

Permalink
add collect test to factory
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemcdonald committed Nov 11, 2019
1 parent 16f15f6 commit 6b80f62
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/factory.js
Expand Up @@ -23,11 +23,35 @@ contract('BFactory', async (accounts) => {

before(async () => {
expect(admin).not.to.equal(nonAdmin);
tokens = await TTokenFactory.deployed();
factory = await BFactory.deployed();

await tokens.build(toHex("WETH"));
await tokens.build(toHex("DAI"));

WETH = await tokens.get.call(toHex("WETH"));
DAI = await tokens.get.call(toHex("DAI"));

weth = await TToken.at(WETH);
dai = await TToken.at(DAI);

// Admin balances
await weth.mint(toWei('5'));
await dai.mint(toWei('200'));

// nonAdmin balances
await weth.mint(toWei('1'), { from: nonAdmin });
await dai.mint(toWei('50'), { from: nonAdmin });

POOL = await factory.newBPool.call(); // this works fine in clean room
await factory.newBPool();
pool = await BPool.at(POOL);

await weth.approve(POOL, MAX);
await dai.approve(POOL, MAX);

await weth.approve(POOL, MAX, { from: nonAdmin });
await dai.approve(POOL, MAX, { from: nonAdmin });
});

it('BFactory is bronze release', async () => {
Expand All @@ -45,6 +69,27 @@ contract('BFactory', async (accounts) => {
assert.isTrue(isBPool)
});

it('fails nonAdmin calls collect', async () => {
await assertThrow(factory.collect(nonAdmin, { from: nonAdmin }), "ERR_NOT_BLABS");
});

it('admin collects fees', async () => {
await pool.bind(WETH, toWei('5'), toWei('5'));
await pool.bind(DAI, toWei('200'), toWei('5'));

await pool.finalize(toWei('100'));

await pool.joinPool(toWei('10'), { from: nonAdmin });
await pool.exitPool(toWei('10'), { from: nonAdmin });

await factory.collect(POOL);

let adminBalance = await pool.balanceOf(admin);

assert.equal(fromWei(adminBalance), '100.001');

});

it('nonadmin cant set blabs address', async () => {
await assertThrow(factory.setBLabs(nonAdmin, { from: nonAdmin }), "ERR_NOT_BLABS");
});
Expand Down

0 comments on commit 6b80f62

Please sign in to comment.