1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

sepparate functions

This commit is contained in:
Miquel A. Cabot 2022-04-06 18:14:18 +02:00
parent 3ddb36b468
commit a0a5230794

View File

@ -117,14 +117,17 @@ describe('Fixed Rate unit test', () => {
expect(await fixedRate.isActive(exchangeId)).to.equal(true) expect(await fixedRate.isActive(exchangeId)).to.equal(true)
expect(await fixedRate.isActive('0x00')).to.equal(false) expect(await fixedRate.isActive('0x00')).to.equal(false)
}) })
it('#getOwner - should get exchange owner given an id', async () => { it('#getOwner - should get exchange owner given an id', async () => {
expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner) expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner)
}) })
it('#getOPFCollector - should get OPF collector', async () => { it('#getOPFCollector - should get OPF collector', async () => {
expect(await fixedRate.getOPCCollector()).to.equal( expect(await fixedRate.getOPCCollector()).to.equal(
contracts.opfCommunityFeeCollectorAddress contracts.opfCommunityFeeCollectorAddress
) )
}) })
it('#getRouter - should get Router address', async () => { it('#getRouter - should get Router address', async () => {
expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress) expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress)
}) })
@ -184,10 +187,12 @@ describe('Fixed Rate unit test', () => {
// exchange owner hasn't approved any DT for sell // exchange owner hasn't approved any DT for sell
expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0') expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0')
}) })
it('#getBTSupply - should get the bt supply in the exchange', async () => { it('#getBTSupply - should get the bt supply in the exchange', async () => {
// no baseToken at the beginning // no baseToken at the beginning
expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0') expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0')
}) })
it('#calcBaseInGivenOutDT - should get bt amount in for a specific dt amount', async () => { it('#calcBaseInGivenOutDT - should get bt amount in for a specific dt amount', async () => {
// 100.2 DAI for 100 DT (0.1% market fee and 0.1% ocean fee) // 100.2 DAI for 100 DT (0.1% market fee and 0.1% ocean fee)
expect( expect(
@ -196,6 +201,7 @@ describe('Fixed Rate unit test', () => {
).baseTokenAmount ).baseTokenAmount
).to.equal('100.3') ).to.equal('100.3')
}) })
it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => { it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => {
// 99.8 DAI for 100 DT (0.1% market fee and 0.1% ocean fee) // 99.8 DAI for 100 DT (0.1% market fee and 0.1% ocean fee)
expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.7') expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.7')
@ -297,14 +303,17 @@ describe('Fixed Rate unit test', () => {
it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => { it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => {
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS) expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
}) })
it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => { it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => {
await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, user1) await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, user1)
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(user1) expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(user1)
}) })
it('#setAllowedSwapper- should disable allowed swapper(return address(0)), if exchangeOwner', async () => { it('#setAllowedSwapper- should disable allowed swapper(return address(0)), if exchangeOwner', async () => {
await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, ZERO_ADDRESS) await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, ZERO_ADDRESS)
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS) expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
}) })
it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => { it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => {
// there are no bt in the contract // there are no bt in the contract
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
@ -318,6 +327,7 @@ describe('Fixed Rate unit test', () => {
// btBalance is zero // btBalance is zero
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
}) })
it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => { it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => {
const result = await fixedRate.getExchange(exchangeId) const result = await fixedRate.getExchange(exchangeId)
// 9 dts left // 9 dts left
@ -435,14 +445,17 @@ describe('Fixed Rate unit test', () => {
expect(await fixedRate.isActive(exchangeId)).to.equal(true) expect(await fixedRate.isActive(exchangeId)).to.equal(true)
expect(await fixedRate.isActive('0x00')).to.equal(false) expect(await fixedRate.isActive('0x00')).to.equal(false)
}) })
it('#getOwner - should get exchange owner given an id', async () => { it('#getOwner - should get exchange owner given an id', async () => {
expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner) expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner)
}) })
it('#getOPFCollector - should get OPF collector', async () => { it('#getOPFCollector - should get OPF collector', async () => {
expect(await fixedRate.getOPCCollector()).to.equal( expect(await fixedRate.getOPCCollector()).to.equal(
contracts.opfCommunityFeeCollectorAddress contracts.opfCommunityFeeCollectorAddress
) )
}) })
it('#getRouter - should get Router address', async () => { it('#getRouter - should get Router address', async () => {
expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress) expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress)
}) })
@ -498,10 +511,12 @@ describe('Fixed Rate unit test', () => {
// exchange owner hasn't approved any DT for sell // exchange owner hasn't approved any DT for sell
expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0') expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0')
}) })
it('#getBTSupply - should get the bt supply in the exchange', async () => { it('#getBTSupply - should get the bt supply in the exchange', async () => {
// no baseToken at the beginning // no baseToken at the beginning
expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0') expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0')
}) })
it('#calcBaseInGivenOutDT - should get bt amount in for a specific dt amount', async () => { it('#calcBaseInGivenOutDT - should get bt amount in for a specific dt amount', async () => {
// 100.2 USDC for 100 DT (0.1% market fee and 0.1% ocean fee) // 100.2 USDC for 100 DT (0.1% market fee and 0.1% ocean fee)
expect( expect(
@ -510,6 +525,7 @@ describe('Fixed Rate unit test', () => {
).baseTokenAmount ).baseTokenAmount
).to.equal('100.3') ).to.equal('100.3')
}) })
it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => { it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => {
// 99.8 USDC for 100 DT (0.1% market fee and 0.1% ocean fee) // 99.8 USDC for 100 DT (0.1% market fee and 0.1% ocean fee)
expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.7') expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.7')
@ -609,14 +625,17 @@ describe('Fixed Rate unit test', () => {
it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => { it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => {
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS) expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
}) })
it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => { it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => {
await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, user1) await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, user1)
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(user1) expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(user1)
}) })
it('#setAllowedSwapper- should disable allowed swapper(return address(0)), if exchangeOwner', async () => { it('#setAllowedSwapper- should disable allowed swapper(return address(0)), if exchangeOwner', async () => {
await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, ZERO_ADDRESS) await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, ZERO_ADDRESS)
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS) expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
}) })
it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => { it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => {
// there are no bt in the contract // there are no bt in the contract
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
@ -630,6 +649,7 @@ describe('Fixed Rate unit test', () => {
// btBalance is zero // btBalance is zero
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
}) })
it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => { it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => {
const result = await fixedRate.getExchange(exchangeId) const result = await fixedRate.getExchange(exchangeId)
// 9 dts left // 9 dts left