Added eventIndex for TokenCreated and NFTCreated events. Increase time sleep for graphql request.

This commit is contained in:
Maria Carmina 2023-03-16 23:20:56 +02:00
parent 6cda426bb5
commit 0e235db3ec
4 changed files with 26 additions and 11 deletions

View File

@ -58,6 +58,7 @@ type Token @entity {
lastPriceToken: Token
lastPriceValue: BigDecimal!
eventIndex: Int!
}
"utility type"
@ -116,6 +117,8 @@ type Nft @entity{
nftData: [NftData!] @derivedFrom(field: "nft")
transferHistory: [NftTransferHistory!] @derivedFrom(field: "nft")
eventIndex: Int!
}
type NftData @entity{

View File

@ -25,6 +25,7 @@ export function handleNftCreated(event: NFTCreated): void {
nft.createdTimestamp = event.block.timestamp.toI32()
nft.tx = event.transaction.hash.toHex()
nft.block = event.block.number.toI32()
nft.eventIndex = event.logIndex.toI32()
nft.transferable = event.params.transferable
nft.save()
@ -39,6 +40,7 @@ export function handleNewToken(event: TokenCreated): void {
token.createdTimestamp = event.block.timestamp.toI32()
token.tx = event.transaction.hash.toHex()
token.block = event.block.number.toI32()
token.eventIndex = event.logIndex.toI32()
token.nft = event.params.creator.toHexString()

View File

@ -30,6 +30,7 @@ export function createToken(address: Address, isDatatoken: boolean): Token {
token.createdTimestamp = 0
token.block = 0
token.tx = ''
token.eventIndex = 0
token.save()
return token
}
@ -60,6 +61,7 @@ export function createNftToken(address: Address): Nft {
token.tx = ''
token.orderCount = BigInt.zero()
token.hasMetadata = false
token.eventIndex = 0
token.save()
addNft()
return token
@ -93,6 +95,7 @@ export function getNftTokenWithID(tokenId: string): Nft {
nftToken.tx = ''
nftToken.orderCount = BigInt.zero()
nftToken.hasMetadata = false
nftToken.eventIndex = 0
nftToken.save()
addNft()
}

View File

@ -135,7 +135,7 @@ describe('Datatoken tests', async () => {
datatokenAddress = result.events.TokenCreated.returnValues[0].toLowerCase()
// Check values before updating metadata
await sleep(2000)
await sleep(3000)
const initialQuery = {
query: `query {
token(id: "${datatokenAddress}"){
@ -162,14 +162,15 @@ describe('Datatoken tests', async () => {
createdTimestamp,
tx,
block,
lastPriceValue
lastPriceValue,
eventIndex
}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(initialQuery)
})
await sleep(2000)
await sleep(3000)
const dt = (await initialResponse.json()).data.token
const tx: TransactionReceipt = await web3.eth.getTransactionReceipt(dt.tx)
@ -214,6 +215,7 @@ describe('Datatoken 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, 'incorrect value for: eventIndex')
})
it('Correct Datatoken fields after updating metadata', async () => {
@ -243,7 +245,7 @@ describe('Datatoken tests', async () => {
)
// Check values before updating metadata
await sleep(2000)
await sleep(3000)
const initialQuery = {
query: `query {
token(id: "${datatokenAddress}"){
@ -270,14 +272,15 @@ describe('Datatoken tests', async () => {
createdTimestamp,
tx,
block,
lastPriceValue
lastPriceValue,
eventIndex
}}`
}
const initialResponse = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(initialQuery)
})
await sleep(2000)
await sleep(3000)
const dt = (await initialResponse.json()).data.token
const tx: TransactionReceipt = await web3.eth.getTransactionReceipt(dt.tx)
@ -321,6 +324,7 @@ describe('Datatoken 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, 'incorrect value for: eventIndex')
})
it('Check datatoken orders are updated correctly after publishing & ordering a datatoken', async () => {
@ -347,7 +351,7 @@ describe('Datatoken tests', async () => {
nftParams,
erc20Params
)
await sleep(2000)
await sleep(3000)
const newDtAddress = result.events.TokenCreated.returnValues[0]
const datatoken = new Datatoken(web3, 8996)
@ -358,20 +362,21 @@ describe('Datatoken tests', async () => {
assert(Number(user2balance) === 0, 'Invalid user2 balance')
const query = {
query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id, nftOwner{id}, lastPriceToken{id}}}}`
query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id, nftOwner{id}, lastPriceToken{id}}, eventIndex}}`
}
await sleep(2000)
await sleep(3000)
let response = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(query)
})
await sleep(3000)
const initialToken = (await response.json()).data.token
assert(initialToken, 'Invalid initialToken')
assert(initialToken.orderCount === '0', 'Invalid initial orderCount')
assert(initialToken.orders.length === 0, 'Invalid initial orders')
assert(initialToken.eventIndex !== null, 'Invalid eventIndex')
const providerData = JSON.stringify({ timeout: 0 })
const providerFeeToken = ZERO_ADDRESS
@ -407,11 +412,12 @@ describe('Datatoken tests', async () => {
assert(orderTx, 'Invalid orderTx')
const orderId = `${orderTx.transactionHash.toLowerCase()}-${newDtAddress.toLowerCase()}-${user1.toLowerCase()}`
await sleep(2000)
await sleep(3000)
response = await fetch(subgraphUrl, {
method: 'POST',
body: JSON.stringify(query)
})
await sleep(3000)
const token = (await response.json()).data.token
@ -420,5 +426,6 @@ describe('Datatoken tests', async () => {
assert(token.orders[0].id === orderId)
assert(token.orders[0].lastPriceToken.id === ZERO_ADDRESS)
assert(token.orders[0].nftOwner.id === publisher, 'invalid nftOwner')
assert(token.eventIndex !== null, 'Invalid eventIndex')
})
})