This commit is contained in:
alexcos20 2023-07-29 19:52:06 +03:00
parent 1434cab3b0
commit de36363438
6 changed files with 46 additions and 38 deletions

View File

@ -1,7 +1,6 @@
import {
NFTCreated,
TokenCreated,
ERC721Factory,
Template721Added,
Template20Added
} from '../@types/ERC721Factory/ERC721Factory'
@ -17,7 +16,6 @@ import {
getToken,
getNftToken,
getPredictContract,
getErc721TemplateId,
getErc20TemplateId
} from './utils/tokenUtils'
import { BigInt } from '@graphprotocol/graph-ts'
@ -77,36 +75,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)
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)
template.templateId = event.params.nftTemplateCount
template.save()
}
}
export function handleNew721Template(event: Template721Added): void {
const dbId = getErc721TemplateId(event.params._templateAddress)
if (dbId === BigInt.zero()) {
const template = new Erc721Template(event.params._templateAddress)
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)
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

@ -139,7 +139,7 @@ export function getPredictContract(address: Address): PredictContract {
}
export function getErc721TemplateId(address: Address): BigInt {
const template = Erc721Template.load(address)
const template = Erc721Template.load(address.toHexString())
if (template) {
return template.templateId
}
@ -147,7 +147,7 @@ export function getErc721TemplateId(address: Address): BigInt {
}
export function getErc20TemplateId(address: Address): BigInt {
const template = Erc20Template.load(address)
const template = Erc20Template.load(address.toHexString())
if (template) {
return template.templateId
}

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'