diff --git a/test/factory.js b/test/factory.js index e617326c..347dfa43 100644 --- a/test/factory.js +++ b/test/factory.js @@ -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 () => { @@ -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"); });