Updated dispenser tests. Added eventIndex for FRE.

This commit is contained in:
Maria Carmina 2023-03-17 18:25:12 +02:00
parent b780e644da
commit 3c4df83f99
4 changed files with 82 additions and 29 deletions

View File

@ -223,6 +223,7 @@ type FixedRateExchange @entity {
createdTimestamp: Int!
tx: String!
eventIndex: Int!
block: Int!
"address of the market where the datatoken was created. This address collects market fees."
@ -249,6 +250,7 @@ type FixedRateExchangeUpdate @entity {
block: Int!
createdTimestamp: Int!
tx: String!
eventIndex: Int!
}
type FixedRateExchangeSwap @entity {
@ -260,6 +262,7 @@ type FixedRateExchangeSwap @entity {
block: Int!
createdTimestamp: Int!
tx: String!
eventIndex: Int!
oceanFeeAmount: BigDecimal!
marketFeeAmount: BigDecimal!
consumeMarketFeeAmount: BigDecimal!

View File

@ -50,6 +50,7 @@ export function handleExchangeCreated(event: ExchangeCreated): void {
)
fixedRateExchange.createdTimestamp = event.block.timestamp.toI32()
fixedRateExchange.tx = event.transaction.hash.toHex()
fixedRateExchange.eventIndex = event.logIndex.toI32()
fixedRateExchange.block = event.block.number.toI32()
fixedRateExchange.save()
@ -69,6 +70,7 @@ export function handleRateChange(event: ExchangeRateChanged): void {
newExchangeUpdate.oldPrice = fixedRateExchange.price
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
newExchangeUpdate.tx = event.transaction.hash.toHex()
newExchangeUpdate.eventIndex = event.logIndex.toI32()
newExchangeUpdate.block = event.block.number.toI32()
newExchangeUpdate.exchangeId = fixedRateId
@ -89,6 +91,7 @@ export function handleMintStateChanged(event: ExchangeMintStateChanged): void {
)
const fixedRateExchange = getFixedRateExchange(fixedRateId)
fixedRateExchange.withMint = event.params.withMint
fixedRateExchange.eventIndex = event.logIndex.toI32()
fixedRateExchange.save()
}
@ -106,6 +109,7 @@ export function handleActivated(event: ExchangeActivated): void {
newExchangeUpdate.newActive = true
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
newExchangeUpdate.tx = event.transaction.hash.toHex()
newExchangeUpdate.eventIndex = event.logIndex.toI32()
newExchangeUpdate.block = event.block.number.toI32()
fixedRateExchange.active = true
@ -129,6 +133,7 @@ export function handleDeactivated(event: ExchangeDeactivated): void {
newExchangeUpdate.exchangeId = fixedRateId
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
newExchangeUpdate.tx = event.transaction.hash.toHex()
newExchangeUpdate.eventIndex = event.logIndex.toI32()
newExchangeUpdate.block = event.block.number.toI32()
fixedRateExchange.active = false
@ -149,6 +154,7 @@ export function handleAllowedSwapperChanged(
)
newExchangeUpdate.createdTimestamp = event.block.timestamp.toI32()
newExchangeUpdate.tx = event.transaction.hash.toHex()
newExchangeUpdate.eventIndex = event.logIndex.toI32()
newExchangeUpdate.block = event.block.number.toI32()
newExchangeUpdate.oldAllowedSwapper = fixedRateExchange.allowedSwapper
newExchangeUpdate.exchangeId = fixedRateId
@ -171,6 +177,7 @@ export function handleSwap(event: Swapped): void {
)
swap.createdTimestamp = event.block.timestamp.toI32()
swap.tx = event.transaction.hash.toHex()
swap.eventIndex = event.logIndex.toI32()
swap.block = event.block.number.toI32()
swap.exchangeId = fixedRateId
@ -244,6 +251,7 @@ export function handlePublishMarketFeeChanged(
event.params.swapFee.toBigDecimal(),
BigInt.fromI32(18).toI32()
)
fixedRateExchange.eventIndex = event.logIndex.toI32()
fixedRateExchange.save()
}
}
@ -261,7 +269,7 @@ export function handleTokenCollected(event: TokenCollected): void {
fixedRateExchange.baseTokenBalance.minus(
weiToDecimal(event.params.amount.toBigDecimal(), baseToken.decimals)
)
fixedRateExchange.eventIndex = event.logIndex.toI32()
fixedRateExchange.save()
}
}

View File

@ -280,7 +280,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(minterQuery)
})
await sleep(sleepMs)
const dt = (await minterResponse.json()).data.token
assert(dt.minter[1] === user1, 'incorrect value for: minter')
assert(dt.eventIndex !== null, 'incorrect value for: eventIndex')
@ -351,7 +350,7 @@ describe('Dispenser tests', async () => {
assert(response.createdTimestamp < time + 15, 'incorrect: createdTimestamp')
assert(response.tx === tx.transactionHash, 'incorrect value for: tx')
assert(
response.eventIndex !== null && response.eventIndex === tx.logIndex,
response.eventIndex !== null && response.eventIndex > 0,
'incorrect value for: eventIndex'
)
assert(response.dispenses.length === 0, 'incorrect value for: dispenses')
@ -380,7 +379,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(deactiveQuery)
})
await sleep(sleepMs)
const updatedActive = (await updatedResponse.json()).data.dispenser
assert(updatedActive.active === false, 'incorrect value for: updatedActive')
assert(updatedActive.eventIndex !== null, 'incorrect value for: eventIndex')
@ -398,7 +396,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(activeQuery)
})
await sleep(sleepMs)
const initialActive = (await initialResponse.json()).data.dispenser
assert(initialActive.active === false, 'incorrect value for: initialActive')
assert(initialActive.eventIndex !== null, 'incorrect value for: eventIndex')
@ -412,7 +409,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(activeQuery)
})
await sleep(sleepMs)
const updatedActive = (await updatedResponse.json()).data.dispenser
assert(updatedActive.active === true, 'incorrect value for: updatedActive')
assert(updatedActive.eventIndex !== null, 'incorrect value for: eventIndex')
@ -482,7 +478,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(balanceQuery)
})
await sleep(sleepMs)
const balance = (await response.json()).data.dispenser
assert(balance.balance === '0', 'incorrect value for: balance')
assert(balance.eventIndex !== null, 'incorrect value for: eventIndex')
@ -497,7 +492,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(swapperQuery)
})
await sleep(sleepMs)
const allowedSwapper1 = (await swapperResponse1.json()).data.dispenser
.allowedSwapper
assert(
@ -512,7 +506,6 @@ describe('Dispenser tests', async () => {
method: 'POST',
body: JSON.stringify(swapperQuery)
})
await sleep(sleepMs)
const allowedSwapper2 = (await swapperResponse2.json()).data.dispenser
assert(

View File

@ -151,6 +151,7 @@ describe('Fixed Rate Exchange tests', async () => {
transferable,
createdTimestamp,
tx,
eventIndex,
block,
orderCount}}`
}
@ -191,6 +192,10 @@ describe('Fixed Rate Exchange tests', async () => {
assert(nft.block >= blockNumber, 'incorrect value for: block')
assert(nft.block < blockNumber + 50, 'incorrect value for: block')
assert(nft.orderCount === '0', 'incorrect value for: orderCount')
assert(
nft.eventIndex !== null && nft.eventIndex > 0,
'incorrect value for: eventIndex'
)
})
it('Test DT Fields after deploying Fixed rate exchange', async () => {
@ -220,6 +225,7 @@ describe('Fixed Rate Exchange tests', async () => {
dispensers {id},
createdTimestamp,
tx,
eventIndex,
block,
lastPriceToken,
lastPriceValue
@ -274,6 +280,10 @@ describe('Fixed Rate Exchange tests', async () => {
assert(dt.block >= blockNumber, 'incorrect value for: block')
assert(dt.block < blockNumber + 50, 'incorrect value for: block')
assert(dt.lastPriceValue === '0', 'incorrect value for: lastPriceValue')
assert(
dt.eventIndex !== null && dt.eventIndex > 0,
'incorrect value for: eventIndex'
)
})
it('Test fixedRateExchanges Fields', async () => {
@ -310,6 +320,7 @@ describe('Fixed Rate Exchange tests', async () => {
}
createdTimestamp
tx
eventIndex
block
publishMarketFeeAddress
publishMarketSwapFee
@ -385,6 +396,10 @@ describe('Fixed Rate Exchange tests', async () => {
)
assert(fixedTx.from === publisher, 'incorrect value for: tx')
assert(fixedTx.to === factoryAddress, 'incorrect value for: tx')
assert(
fixed.eventIndex !== null && fixed.eventIndex > 0,
'incorrect value for: eventIndex'
)
})
it('Updates Fixed Rate Price', async () => {
@ -398,6 +413,7 @@ describe('Fixed Rate Exchange tests', async () => {
}
oldPrice
newPrice
eventIndex
}
}}`
}
@ -422,7 +438,7 @@ describe('Fixed Rate Exchange tests', async () => {
// Update price
const newPrice = '999'
await fixedRate.setRate(publisher, exchangeId, newPrice)
const tx = await fixedRate.setRate(publisher, exchangeId, newPrice)
await sleep(sleepMs)
// Check price after first update
@ -441,10 +457,14 @@ describe('Fixed Rate Exchange tests', async () => {
)
assert(updates2.oldPrice === price1, 'incorrect value: 2nd oldPrice')
assert(updates2.newPrice === newPrice, 'incorrect value: 2nd newPrice')
assert(
updates2.eventIndex === tx.events.ExchangeRateChanged.logIndex,
'incorrect value: 2nd eventIndex'
)
// Update price a 2nd time
const newPrice2 = '1' // '5.123'
await fixedRate.setRate(publisher, exchangeId, newPrice2)
const tx2 = await fixedRate.setRate(publisher, exchangeId, newPrice2)
await sleep(sleepMs)
// Check price after 2nd update
@ -464,10 +484,14 @@ describe('Fixed Rate Exchange tests', async () => {
)
assert(updates3.oldPrice === newPrice, 'incorrect value: 3rd oldPrice')
assert(updates3.newPrice === newPrice2, 'incorrect value: 3rd newPrice')
assert(
updates3.eventIndex === tx2.events.ExchangeRateChanged.logIndex,
'incorrect value: 3nd eventIndex'
)
})
it('Deactivates exchange', async () => {
const deactiveQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){active}}`
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
@ -488,13 +512,17 @@ describe('Fixed Rate Exchange tests', async () => {
body: JSON.stringify(deactiveQuery)
})
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
.active
assert(updatedActive === false, 'incorrect value for: updatedActive')
assert(updatedActive.active === false, 'incorrect value for: updatedActive')
assert(
updatedActive.eventIndex !== null && updatedActive.eventIndex > 0,
'incorrect value: eventIndex'
)
})
it('Activates exchange', async () => {
const activeQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){active}}`
query: `query {fixedRateExchange(id: "${fixedRateId}"){active, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
@ -514,13 +542,16 @@ describe('Fixed Rate Exchange tests', async () => {
body: JSON.stringify(activeQuery)
})
const updatedActive = (await updatedResponse.json()).data.fixedRateExchange
.active
assert(updatedActive === true, 'incorrect value for: updatedActive')
assert(updatedActive.active === true, 'incorrect value for: updatedActive')
assert(
updatedActive.eventIndex !== null && updatedActive.eventIndex > 0,
'incorrect value: eventIndex'
)
})
it('Activate Minting', async () => {
const mintingQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint}}`
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
@ -531,7 +562,7 @@ describe('Fixed Rate Exchange tests', async () => {
assert(initialMint === null, 'incorrect value for: initialMint')
// Activate minting
await fixedRate.activateMint(publisher, exchangeId)
const tx = await fixedRate.activateMint(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
@ -541,13 +572,16 @@ describe('Fixed Rate Exchange tests', async () => {
})
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
.withMint
assert(updatedMint === true, 'incorrect value for: updatedMint')
assert(updatedMint.withMint === true, 'incorrect value for: updatedMint')
assert(
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
'incorrect value for: eventIndex'
)
})
it('Deactivate Minting', async () => {
const mintingQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint}}`
query: `query {fixedRateExchange(id: "${fixedRateId}"){withMint, eventIndex}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
@ -558,7 +592,7 @@ describe('Fixed Rate Exchange tests', async () => {
assert(initialMint === true, 'incorrect value for: initialMint')
// Activate minting
await fixedRate.deactivateMint(publisher, exchangeId)
const tx = await fixedRate.deactivateMint(publisher, exchangeId)
await sleep(sleepMs)
// Check the updated value for active
@ -568,8 +602,11 @@ describe('Fixed Rate Exchange tests', async () => {
})
const updatedMint = (await updatedResponse.json()).data.fixedRateExchange
.withMint
assert(updatedMint === false, 'incorrect value for: updatedMint')
assert(updatedMint.withMint === false, 'incorrect value for: updatedMint')
assert(
updatedMint.eventIndex === tx.events.ExchangeMintStateChanged.logIndex,
'incorrect value for: eventIndex'
)
})
it('User1 buys a datatoken', async () => {
@ -584,6 +621,7 @@ describe('Fixed Rate Exchange tests', async () => {
block
createdTimestamp
tx
eventIndex
oceanFeeAmount
marketFeeAmount
consumeMarketFeeAmount
@ -669,6 +707,7 @@ describe('Fixed Rate Exchange tests', async () => {
'wrong consumeMarketFeeAmount'
)
assert(swaps.tx === tx.transactionHash, 'incorrect value for: tx')
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
})
it('User1 sells a datatoken', async () => {
@ -691,6 +730,7 @@ describe('Fixed Rate Exchange tests', async () => {
block
createdTimestamp
tx
eventIndex
oceanFeeAmount
__typename
}
@ -715,12 +755,13 @@ describe('Fixed Rate Exchange tests', async () => {
assert(swaps.createdTimestamp < time + 25, 'incorrect: createdTimestamp 2')
assert(swaps.oceanFeeAmount === oceanFeeAmount, 'incorrect: oceanFeeAmount')
assert(swaps.tx === tx.transactionHash, 'incorrect value for: tx')
assert(swaps.eventIndex === tx.logIndex, 'incorrect value for: eventIndex')
assert(swaps.__typename === 'FixedRateExchangeSwap', 'incorrect __typename')
})
it('Updates allowed swapper', async () => {
const swapperQuery = {
query: `query {fixedRateExchange(id: "${fixedRateId}"){allowedSwapper}}`
query: `query {fixedRateExchange(id: "${fixedRateId}"){allowedSwapper, eventIndex}}`
}
// Check initial allowedSwapper
const swapperResponse1 = await fetch(subgraphUrl, {
@ -734,7 +775,7 @@ describe('Fixed Rate Exchange tests', async () => {
'incorrect value for: allowedSwapper'
)
await fixedRate.setAllowedSwapper(publisher, exchangeId, user1)
const tx = await fixedRate.setAllowedSwapper(publisher, exchangeId, user1)
await sleep(sleepMs)
const swapperResponse2 = await fetch(subgraphUrl, {
@ -742,8 +783,16 @@ describe('Fixed Rate Exchange tests', async () => {
body: JSON.stringify(swapperQuery)
})
const allowedSwapper2 = (await swapperResponse2.json()).data
.fixedRateExchange.allowedSwapper
.fixedRateExchange
assert(allowedSwapper2 === user1, 'incorrect value for: allowedSwapper 2')
assert(
allowedSwapper2.allowedSwapper === user1,
'incorrect value for: allowedSwapper 2'
)
assert(
allowedSwapper2.eventIndex ===
tx.events.ExchangeAllowedSwapperChanged.logIndex,
'incorrect value for: eventIndex'
)
})
})