This commit is contained in:
alexcos20 2023-07-29 19:28:33 +03:00
parent a31ac25971
commit 733d39d8b2
5 changed files with 45 additions and 27 deletions

View File

@ -9,14 +9,8 @@ import { decimal } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getUser } from './utils/userUtils'
import {
getToken,
getNftToken,
getErc721TemplateId,
getErc20TemplateId
} from './utils/tokenUtils'
import { getToken, getNftToken, getErc20TemplateId } from './utils/tokenUtils'
import { addDatatoken } from './utils/globalUtils'
import { BigInt } from '@graphprotocol/graph-ts'
export function handleNftCreated(event: NFTCreated): void {
// const nft = new Nft(event.params.newTokenAddress.toHexString())
@ -63,22 +57,20 @@ export function handleNewToken(event: TokenCreated): void {
}
export function handleNew721Template(event: Template721Added): void {
const dbId = getErc721TemplateId(event.params._templateAddress)
if (dbId === BigInt.zero()) {
const template = new Erc721Template(
event.params._templateAddress.toHexString()
)
let template = Erc721Template.load(
event.params._templateAddress.toHexString()
)
if (template === null) {
template = new Erc721Template(event.params._templateAddress.toHexString())
template.templateId = event.params.nftTemplateCount
template.save()
}
}
export function handleNew20Template(event: Template20Added): void {
const dbId = getErc20TemplateId(event.params._templateAddress)
if (dbId === BigInt.zero()) {
const template = new Erc20Template(
event.params._templateAddress.toHexString()
)
let template = Erc20Template.load(event.params._templateAddress.toHexString())
if (template === null) {
template = new Erc20Template(event.params._templateAddress.toHexString())
template.templateId = event.params.nftTemplateCount
template.save()
}

View File

@ -197,8 +197,10 @@ describe('Datatoken tests', async () => {
dt.publishMarketFeeAmount === publishMarketFeeAmount,
'incorrect value for: publishMarketFeeAmount'
)
assert(dt.templateId === templateIndex, 'incorrect value for: templateId')
assert(
parseInt(dt.templateId) === templateIndex,
'incorrect value for: templateId'
)
assert(dt.holderCount === '0', 'incorrect value for: holderCount')
assert(dt.orderCount === '0', 'incorrect value for: orderCount')
assert(dt.orders, 'incorrect value for: orders')
@ -314,7 +316,10 @@ describe('Datatoken tests', async () => {
dt.publishMarketFeeAmount === publishMarketFeeAmount,
'incorrect value for: publishMarketFeeAmount'
)
assert(dt.templateId === templateIndex, 'incorrect value for: templateId')
assert(
parseInt(dt.templateId) === templateIndex,
'incorrect value for: templateId'
)
assert(dt.holderCount === '0', 'incorrect value for: holderCount')
assert(dt.orderCount === '0', 'incorrect value for: orderCount')
assert(dt.orders, 'incorrect value for: orders')

View File

@ -110,6 +110,7 @@ describe('Dispenser tests', async () => {
nftParams,
erc20Params
)
const nftTemplate = await Factory.getNFTTemplate(nftParams.templateIndex)
assert(tx.events.NFTCreated.event === 'NFTCreated')
assert(tx.events.TokenCreated.event === 'TokenCreated')
nftAddress = tx.events.NFTCreated.returnValues.newTokenAddress.toLowerCase()
@ -163,7 +164,10 @@ describe('Dispenser tests', async () => {
)
assert(nft.storeUpdateRole === null, 'incorrect value for: storeUpdateRole')
assert(nft.metadataRole === null, 'incorrect value for: metadataRole')
assert(nft.template === '', 'incorrect value for: template')
assert(
nft.template === nftTemplate.templateAddress.toLowerCase(),
'incorrect value for: template'
)
assert(nft.transferable === true, 'incorrect value for: transferable')
assert(nft.createdTimestamp >= time, 'incorrect value: createdTimestamp')
assert(nft.createdTimestamp < time + 5, 'incorrect value: createdTimestamp')
@ -243,7 +247,10 @@ describe('Dispenser tests', async () => {
'incorrect value for: publishMarketFeeAmount'
)
assert(dt.templateId === templateIndex, 'incorrect value for: templateId')
assert(
parseInt(dt.templateId) === templateIndex,
'incorrect value for: templateId'
)
assert(dt.holderCount === '0', 'incorrect value for: holderCount')
assert(dt.orderCount === '0', 'incorrect value for: orderCount')
assert(dt.orders, 'incorrect value for: orders')

View File

@ -127,6 +127,7 @@ describe('Fixed Rate Exchange tests', async () => {
result.events.NewFixedRate.returnValues.exchangeId.toLowerCase()
fixedRateId = `${exchangeContract}-${exchangeId}`
const nftTemplate = await Factory.getNFTTemplate(nftParams.templateIndex)
// Check NFT values
await sleep(sleepMs)
@ -176,7 +177,10 @@ describe('Fixed Rate Exchange tests', async () => {
)
assert(nft.storeUpdateRole === null, 'incorrect value for: storeUpdateRole')
assert(nft.metadataRole === null, 'incorrect value for: metadataRole')
assert(nft.template === '', 'incorrect value for: template')
assert(
nft.template === nftTemplate.templateAddress.toLowerCase(),
'incorrect value for: template'
)
assert(nft.transferable === true, 'incorrect value for: transferable')
assert(
nft.createdTimestamp >= time,
@ -263,7 +267,10 @@ describe('Fixed Rate Exchange tests', async () => {
'incorrect value for: publishMarketFeeAmount'
)
assert(dt.templateId === templateIndex, 'incorrect value for: templateId')
assert(
parseInt(dt.templateId) === templateIndex,
'incorrect value for: templateId'
)
assert(dt.holderCount === '0', 'incorrect value for: holderCount')
assert(dt.orderCount === '0', 'incorrect value for: orderCount')
assert(dt.orders, 'incorrect value for: orders')

View File

@ -66,6 +66,7 @@ const ddo = {
}
]
}
let nftTemplate
describe('NFT tests', async () => {
const nftName = 'testNFT'
@ -119,7 +120,7 @@ describe('NFT tests', async () => {
)
erc721Address = result.events.NFTCreated.returnValues[0]
datatokenAddress = result.events.TokenCreated.returnValues[0]
nftTemplate = await Factory.getNFTTemplate(nftParams.templateIndex)
// Check values before updating metadata
await sleep(3000)
nftAddress = erc721Address.toLowerCase()
@ -167,7 +168,10 @@ describe('NFT tests', async () => {
)
assert(nft.storeUpdateRole === null, 'incorrect value for: storeUpdateRole')
assert(nft.metadataRole === null, 'incorrect value for: metadataRole')
assert(nft.template === '', 'incorrect value for: template')
assert(
nft.template === nftTemplate.templateAddress.toLowerCase(),
'incorrect value for: template'
)
assert(nft.transferable === true, 'incorrect value for: transferable')
assert(
nft.createdTimestamp >= time,
@ -276,7 +280,10 @@ describe('NFT tests', async () => {
updatedNft.metadataRole === null,
'incorrect value for: metadataRole'
)
assert(updatedNft.template === '', 'incorrect value for: template')
assert(
updatedNft.template === nftTemplate.templateAddress.toLowerCase(),
'incorrect value for: template'
)
assert(
updatedNft.transferable === true,
'incorrect value for: transferable'