Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekdefi committed Dec 6, 2024
1 parent d34b4e1 commit 27fea51
Showing 1 changed file with 58 additions and 20 deletions.
78 changes: 58 additions & 20 deletions packages/oracle/test/unit/types/PriceResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,40 +300,52 @@ describe('PriceResponse', () => {
})

describe('#applyFeeMaximum', () => {
const maxSyncFee = parse6decimal('1')
const maxAsyncFee = parse6decimal('0.2')

it('calculates correct fee w/ non-zero sync, zero async', async () => {
await priceResponse.store({
...DEFAULT_PRICE_RESPONSE,
syncFee: parse6decimal('1'),
asyncFee: parse6decimal('0'),
syncFee: parse6decimal('2'),
asyncFee: parse6decimal('0.4'),
})

const maxSyncFee = parse6decimal('0.3')
const maxAsyncFee = parse6decimal('0.1')

await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee)
await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee, 0)

const value = await priceResponse.read()

expect(value.syncFee).to.equal(parse6decimal('0.3'))
expect(value.asyncFee).to.equal(parse6decimal('0'))
expect(value.syncFee).to.equal(maxSyncFee)
expect(value.asyncFee).to.equal(parse6decimal('0.4'))
})

it('calculates correct fee w/ non-zero sync, non-zero async', async () => {
it('calculates correct fee w/ non-zero sync, single async', async () => {
await priceResponse.store({
...DEFAULT_PRICE_RESPONSE,
syncFee: parse6decimal('1'),
asyncFee: parse6decimal('0.2'),
syncFee: parse6decimal('2'),
asyncFee: parse6decimal('0.4'),
})

const maxSyncFee = parse6decimal('0.3')
const maxAsyncFee = parse6decimal('0.1')
await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee, 1)

await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee)
const value = await priceResponse.read()

expect(value.syncFee).to.equal(maxSyncFee)
expect(value.asyncFee).to.equal(maxAsyncFee)
})

it('calculates correct fee w/ non-zero sync, multiple async', async () => {
await priceResponse.store({
...DEFAULT_PRICE_RESPONSE,
syncFee: parse6decimal('2'),
asyncFee: parse6decimal('0.4'),
})

await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee, 5)

const value = await priceResponse.read()

expect(value.syncFee).to.equal(parse6decimal('0.3'))
expect(value.asyncFee).to.equal(parse6decimal('0.1'))
expect(value.syncFee).to.equal(maxSyncFee)
expect(value.asyncFee).to.equal(parse6decimal('0.04'))
})

it('calculates correct fee w/ zero sync, zero async', async () => {
Expand All @@ -343,15 +355,41 @@ describe('PriceResponse', () => {
asyncFee: parse6decimal('0'),
})

const maxSyncFee = parse6decimal('0.3')
const maxAsyncFee = parse6decimal('0.1')

await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee)
await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee, 0)

const value = await priceResponse.read()

expect(value.syncFee).to.equal(parse6decimal('0'))
expect(value.asyncFee).to.equal(parse6decimal('0'))
})

it('calculates correct fee w/ zero sync, single async', async () => {
await priceResponse.store({
...DEFAULT_PRICE_RESPONSE,
syncFee: parse6decimal('0'),
asyncFee: parse6decimal('0.4'),
})
await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee, 1)

const value = await priceResponse.read()

expect(value.syncFee).to.equal(parse6decimal('0'))
expect(value.asyncFee).to.equal(maxAsyncFee)
})

it('calculates correct fee w/ zero sync, multiple async', async () => {
await priceResponse.store({
...DEFAULT_PRICE_RESPONSE,
syncFee: parse6decimal('0'),
asyncFee: parse6decimal('0.4'),
})

await priceResponse.applyFeeMaximum(maxSyncFee, maxAsyncFee, 5)

const value = await priceResponse.read()

expect(value.syncFee).to.equal(parse6decimal('0'))
expect(value.asyncFee).to.equal(parse6decimal('0.04'))
})
})
})

0 comments on commit 27fea51

Please sign in to comment.