Added eventIndex for order events and for dt events. Added new test commands in package.json.
This commit is contained in:
parent
ed9ee5023a
commit
7b49cf8e4b
|
@ -33,6 +33,8 @@
|
|||
"test-df": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/DFRewards.test.ts'",
|
||||
"test-dt": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Datatoken.test.ts'",
|
||||
"test-zend": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/ZEnding.test.ts'",
|
||||
"test-publish-consume": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/SimplePublishConsume.test.ts'",
|
||||
"test-nft": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Nft.test.ts'",
|
||||
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
|
||||
"lint:fix": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx . --fix",
|
||||
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write",
|
||||
|
|
|
@ -133,6 +133,7 @@ type OrderReuse @entity {
|
|||
caller: String!
|
||||
createdTimestamp: Int!
|
||||
tx: String!
|
||||
eventIndex: Int!
|
||||
block: Int!
|
||||
providerFee: String
|
||||
providerFeeValidUntil: BigInt
|
||||
|
@ -168,6 +169,7 @@ type Order @entity {
|
|||
|
||||
createdTimestamp: Int!
|
||||
tx: String!
|
||||
eventIndex: Int!
|
||||
block: Int!
|
||||
|
||||
lastPriceToken: Token
|
||||
|
|
|
@ -64,6 +64,7 @@ export function handleOrderStarted(event: OrderStarted): void {
|
|||
|
||||
order.createdTimestamp = event.block.timestamp.toI32()
|
||||
order.tx = event.transaction.hash.toHex()
|
||||
order.eventIndex = event.logIndex.toI32()
|
||||
order.block = event.block.number.toI32()
|
||||
const tokenId = token.lastPriceToken
|
||||
if (tokenId) {
|
||||
|
@ -123,6 +124,7 @@ export function handlerOrderReused(event: OrderReused): void {
|
|||
reuseOrder.caller = event.params.caller.toHexString()
|
||||
reuseOrder.createdTimestamp = event.params.timestamp.toI32()
|
||||
reuseOrder.tx = event.transaction.hash.toHex()
|
||||
reuseOrder.eventIndex = event.logIndex.toI32()
|
||||
reuseOrder.block = event.params.number.toI32()
|
||||
|
||||
reuseOrder.save()
|
||||
|
@ -149,6 +151,7 @@ export function handlePublishMarketFeeChanged(
|
|||
event.params.PublishMarketFeeAmount.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
// TODO - shold we have a history
|
||||
}
|
||||
|
@ -163,6 +166,7 @@ export function handleAddedMinter(event: AddedMinter): void {
|
|||
if (!existingRoles.includes(event.params.user.toHexString()))
|
||||
existingRoles.push(event.params.user.toHexString())
|
||||
token.minter = existingRoles
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
}
|
||||
|
||||
|
@ -179,6 +183,7 @@ export function handleRemovedMinter(event: RemovedMinter): void {
|
|||
if (role !== event.params.user.toHexString()) newList.push(role)
|
||||
}
|
||||
token.minter = newList
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
}
|
||||
|
||||
|
@ -190,6 +195,7 @@ export function handleAddedPaymentManager(event: AddedPaymentManager): void {
|
|||
if (!existingRoles.includes(event.params.user.toHexString()))
|
||||
existingRoles.push(event.params.user.toHexString())
|
||||
token.paymentManager = existingRoles
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
}
|
||||
export function handleRemovedPaymentManager(
|
||||
|
@ -207,6 +213,7 @@ export function handleRemovedPaymentManager(
|
|||
if (role !== event.params.user.toHexString()) newList.push(role)
|
||||
}
|
||||
token.paymentManager = newList
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
}
|
||||
export function handleCleanedPermissions(event: CleanedPermissions): void {
|
||||
|
@ -217,12 +224,14 @@ export function handleCleanedPermissions(event: CleanedPermissions): void {
|
|||
const nft = Nft.load(token.nft as string)
|
||||
if (nft) token.paymentCollector = nft.owner
|
||||
else token.paymentCollector = '0x0000000000000000000000000000000000000000'
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
}
|
||||
|
||||
export function handleNewPaymentCollector(event: NewPaymentCollector): void {
|
||||
const token = getToken(event.address, true)
|
||||
token.paymentCollector = event.params._newPaymentCollector.toHexString()
|
||||
token.eventIndex = event.logIndex.toI32()
|
||||
token.save()
|
||||
}
|
||||
|
||||
|
@ -245,6 +254,7 @@ export function handleProviderFee(event: ProviderFee): void {
|
|||
if (order) {
|
||||
order.providerFee = providerFee
|
||||
order.providerFeeValidUntil = event.params.validUntil
|
||||
order.eventIndex = event.logIndex.toI32()
|
||||
order.save()
|
||||
return
|
||||
}
|
||||
|
@ -253,6 +263,7 @@ export function handleProviderFee(event: ProviderFee): void {
|
|||
if (orderReuse) {
|
||||
orderReuse.providerFee = providerFee
|
||||
orderReuse.providerFeeValidUntil = event.params.validUntil
|
||||
orderReuse.eventIndex = event.logIndex.toI32()
|
||||
orderReuse.save()
|
||||
} else {
|
||||
orderReuse = new OrderReuse(event.transaction.hash.toHex())
|
||||
|
@ -261,6 +272,7 @@ export function handleProviderFee(event: ProviderFee): void {
|
|||
orderReuse.order = orderId
|
||||
orderReuse.createdTimestamp = event.block.timestamp.toI32()
|
||||
orderReuse.tx = event.transaction.hash.toHex()
|
||||
orderReuse.eventIndex = event.logIndex.toI32()
|
||||
orderReuse.block = event.block.number.toI32()
|
||||
orderReuse.caller = event.transaction.from.toHex()
|
||||
if (event.transaction.gasPrice)
|
||||
|
|
|
@ -215,7 +215,10 @@ 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')
|
||||
assert(
|
||||
dt.eventIndex !== null && dt.eventIndex > 0,
|
||||
'incorrect value for: eventIndex'
|
||||
)
|
||||
})
|
||||
|
||||
it('Correct Datatoken fields after updating metadata', async () => {
|
||||
|
@ -324,7 +327,10 @@ 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')
|
||||
assert(
|
||||
dt.eventIndex !== null && dt.eventIndex > 0,
|
||||
'incorrect value for: eventIndex'
|
||||
)
|
||||
})
|
||||
|
||||
it('Check datatoken orders are updated correctly after publishing & ordering a datatoken', async () => {
|
||||
|
@ -362,7 +368,7 @@ 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}}, eventIndex}}`
|
||||
query: `query {token(id: "${newDtAddress.toLowerCase()}"){id,orderCount,orders {id, nftOwner{id}, lastPriceToken{id}, eventIndex}, eventIndex}}`
|
||||
}
|
||||
|
||||
await sleep(3000)
|
||||
|
@ -376,7 +382,10 @@ describe('Datatoken tests', async () => {
|
|||
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')
|
||||
assert(
|
||||
initialToken.eventIndex !== null && initialToken.eventIndex > 0,
|
||||
'Invalid eventIndex'
|
||||
)
|
||||
|
||||
const providerData = JSON.stringify({ timeout: 0 })
|
||||
const providerFeeToken = ZERO_ADDRESS
|
||||
|
@ -426,6 +435,11 @@ 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.orders[0].eventIndex === 1, 'invalid order eventIndex')
|
||||
assert(token.eventIndex !== null, 'Invalid eventIndex')
|
||||
assert(
|
||||
token.eventIndex !== token.orders[0].eventIndex,
|
||||
'Invalid log indeces'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -121,7 +121,7 @@ describe('NFT tests', async () => {
|
|||
datatokenAddress = result.events.TokenCreated.returnValues[0]
|
||||
|
||||
// Check values before updating metadata
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
nftAddress = erc721Address.toLowerCase()
|
||||
const initialQuery = {
|
||||
query: `query {
|
||||
|
@ -143,6 +143,7 @@ describe('NFT tests', async () => {
|
|||
transferable,
|
||||
createdTimestamp,
|
||||
tx,
|
||||
eventIndex,
|
||||
block,
|
||||
orderCount}}`
|
||||
}
|
||||
|
@ -150,7 +151,7 @@ describe('NFT tests', async () => {
|
|||
method: 'POST',
|
||||
body: JSON.stringify(initialQuery)
|
||||
})
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
const nft = (await initialResponse.json()).data.nft
|
||||
const tx: TransactionReceipt = await web3.eth.getTransactionReceipt(nft.tx)
|
||||
assert(nft.id === nftAddress, 'incorrect value for: id')
|
||||
|
@ -182,6 +183,10 @@ describe('NFT 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,
|
||||
'Invalid eventIndex for NFT creation'
|
||||
)
|
||||
})
|
||||
|
||||
it('Update metadata', async () => {
|
||||
|
|
|
@ -148,18 +148,24 @@ describe('Simple Publish & consume test', async () => {
|
|||
)
|
||||
|
||||
// graph tests here
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
const graphNftToken = erc721Address.toLowerCase()
|
||||
const query = {
|
||||
query: `query {
|
||||
nft(id:"${graphNftToken}"){symbol,id}}`
|
||||
nft(id:"${graphNftToken}"){symbol,id,eventIndex}}`
|
||||
}
|
||||
const response = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(query)
|
||||
})
|
||||
await sleep(3000)
|
||||
const queryResult = await response.json()
|
||||
assert(queryResult.data.nft.id === graphNftToken)
|
||||
assert(
|
||||
queryResult.data.nft.eventIndex !== null &&
|
||||
queryResult.data.nft.eventIndex > 0,
|
||||
'Invalid eventIndex for NFT creation'
|
||||
)
|
||||
})
|
||||
it('should publish and transfer an NFT', async () => {
|
||||
const nftParams: NftCreateData = {
|
||||
|
@ -184,25 +190,31 @@ describe('Simple Publish & consume test', async () => {
|
|||
nftParams,
|
||||
erc20Params
|
||||
)
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
const erc721Address = result.events.NFTCreated.returnValues[0]
|
||||
const datatokenAddress = result.events.TokenCreated.returnValues[0]
|
||||
const graphNftToken = erc721Address.toLowerCase()
|
||||
|
||||
const queryOriginalOwner = {
|
||||
query: `query {
|
||||
nft(id:"${graphNftToken}"){symbol,id,owner{id}}}`
|
||||
nft(id:"${graphNftToken}"){symbol,id,owner{id},eventIndex}}`
|
||||
}
|
||||
const initialResponse = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(queryOriginalOwner)
|
||||
})
|
||||
await sleep(3000)
|
||||
const initialResult = await initialResponse.json()
|
||||
// Checking original owner account has been set correctly
|
||||
assert(
|
||||
initialResult.data.nft.owner.id.toLowerCase() ===
|
||||
publisherAccount.toLowerCase()
|
||||
)
|
||||
assert(
|
||||
initialResult.data.nft.eventIndex !== null &&
|
||||
initialResult.data.nft.eventIndex > 0,
|
||||
'Invalid eventIndex for NFT creation'
|
||||
)
|
||||
|
||||
// create the files encrypted string
|
||||
let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
||||
|
@ -228,21 +240,27 @@ describe('Simple Publish & consume test', async () => {
|
|||
encryptedResponse,
|
||||
'0x' + metadataHash
|
||||
)
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
|
||||
// Transfer the NFT
|
||||
await nft.transferNft(graphNftToken, publisherAccount, newOwnerAccount)
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
const query2 = {
|
||||
query: `query {
|
||||
nft(id:"${graphNftToken}"){symbol,id,owner{id}, transferable}}`
|
||||
nft(id:"${graphNftToken}"){symbol,id,owner{id}, transferable, eventIndex}}`
|
||||
}
|
||||
const response = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(query2)
|
||||
})
|
||||
await sleep(3000)
|
||||
const queryResult = await response.json()
|
||||
assert(queryResult.data.nft.owner.id === newOwnerAccount)
|
||||
assert(
|
||||
queryResult.data.nft.eventIndex !== null &&
|
||||
queryResult.data.nft.eventIndex > 0,
|
||||
'Invalid eventIndex for NFT creation'
|
||||
)
|
||||
})
|
||||
|
||||
it('should save provider fees after startOrder is called', async () => {
|
||||
|
@ -283,15 +301,15 @@ describe('Simple Publish & consume test', async () => {
|
|||
const orderId = `${orderTx.transactionHash.toLowerCase()}-${datatokenAddress.toLowerCase()}-${user1.toLowerCase()}`
|
||||
|
||||
const query = {
|
||||
query: `query {order(id:"${orderId}"){id, providerFee, lastPriceToken{id}}}`
|
||||
query: `query {order(id:"${orderId}"){id, providerFee, lastPriceToken{id}, eventIndex}}`
|
||||
}
|
||||
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
const response = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(query)
|
||||
})
|
||||
|
||||
await sleep(3000)
|
||||
const queryResult = await response.json()
|
||||
|
||||
const providerFeeJSON = JSON.parse(queryResult.data.order.providerFee)
|
||||
|
@ -314,6 +332,11 @@ describe('Simple Publish & consume test', async () => {
|
|||
setProviderFee.providerFeeToken.toLowerCase(),
|
||||
'Wrong providerFeeToken set'
|
||||
)
|
||||
assert(
|
||||
queryResult.data.order.eventIndex !== null &&
|
||||
queryResult.data.order.eventIndex > 0,
|
||||
'Invalid eventIndex for order'
|
||||
)
|
||||
})
|
||||
|
||||
it('should save provider fees after calling reuseOrder on a using a previous txId', async () => {
|
||||
|
@ -357,13 +380,14 @@ describe('Simple Publish & consume test', async () => {
|
|||
const orderId = `${orderTx.transactionHash.toLowerCase()}-${datatokenAddress.toLowerCase()}-${user4.toLowerCase()}`
|
||||
|
||||
const initialQuery = {
|
||||
query: `query {order(id:"${orderId}"){id, providerFee, lastPriceToken{id}}}`
|
||||
query: `query {order(id:"${orderId}"){id, providerFee, lastPriceToken{id}, eventIndex}}`
|
||||
}
|
||||
await sleep(2000)
|
||||
await sleep(3000)
|
||||
const initialResponse = await fetch(subgraphUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(initialQuery)
|
||||
})
|
||||
await sleep(3000)
|
||||
const initialQueryResult = await initialResponse.json()
|
||||
const initialProviderFeeJSON = JSON.parse(
|
||||
initialQueryResult.data.order.providerFee
|
||||
|
@ -386,6 +410,11 @@ describe('Simple Publish & consume test', async () => {
|
|||
setInitialProviderFee.providerFeeToken.toLowerCase(),
|
||||
'Wrong initial providerFeeToken set'
|
||||
)
|
||||
assert(
|
||||
initialQueryResult.data.order.eventIndex !== null &&
|
||||
initialQueryResult.data.order.eventIndex > 0,
|
||||
'Invalid eventIndex for order'
|
||||
)
|
||||
|
||||
providerFeeAmount = '990000'
|
||||
providerValidUntil = '10000'
|
||||
|
@ -426,7 +455,7 @@ describe('Simple Publish & consume test', async () => {
|
|||
// Check the new provider fee has been set in OrderReuse
|
||||
|
||||
const reuseQuery = {
|
||||
query: `query {orderReuse(id:"${reusedOrder.transactionHash}"){id, providerFee}}`
|
||||
query: `query {orderReuse(id:"${reusedOrder.transactionHash}"){id, providerFee, eventIndex}}`
|
||||
}
|
||||
|
||||
await sleep(2000)
|
||||
|
@ -456,5 +485,18 @@ describe('Simple Publish & consume test', async () => {
|
|||
setNewProviderFee.providerFeeToken.toLowerCase(),
|
||||
'New providerFeeToken set in reuse order is wrong'
|
||||
)
|
||||
assert(
|
||||
reuseQueryResult.data.orderReuse.eventIndex !== null &&
|
||||
reuseQueryResult.data.orderReuse.eventIndex > 0,
|
||||
'Invalid eventIndex for reuse order'
|
||||
)
|
||||
assert(
|
||||
reuseQueryResult.data.orderReuse.eventIndex === 1,
|
||||
'Invalid reuse order event index'
|
||||
)
|
||||
assert(
|
||||
initialQueryResult.data.order.eventIndex === 1,
|
||||
'Invalid start order event index'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue