Tracking templateId (#508)

* Creating a new set of tests for datatokens

* Testing additional fields on datatoken

* Testing value for tx, block and orderCOunt

* Adding additional tests after updating nft metadata

* SPlitting up nft tests and datatoken tests

* Updating tests for additional fields

* Adding tests for remaining datatoken fields

* Adding test for datatoken balances

* Testing if orders are correctly updated in the datatoken

* Adding comment

* Removing comments

* Adding logs

* Updating templateId

* Updating tests + removing comments

* lint:fix
This commit is contained in:
Jamie Hewitt 2022-08-02 16:13:43 +03:00 committed by GitHub
parent bd03b28197
commit fd40e490cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 8 deletions

View File

@ -1,10 +1,15 @@
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
import {
NFTCreated,
TokenCreated,
ERC721Factory
} from '../@types/ERC721Factory/ERC721Factory'
import { decimal } from './utils/constants'
import { weiToDecimal } from './utils/generic'
import { getUser } from './utils/userUtils'
import { getToken, getNftToken } 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())
@ -42,6 +47,24 @@ export function handleNewToken(event: TokenCreated): void {
token.decimals = 18
token.supply = decimal.ZERO
token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18)
const eventTemplateAddress = event.params.templateAddress
.toHexString()
.toLowerCase()
const contract = ERC721Factory.bind(event.address)
const templateCount = contract.try_getCurrentTemplateCount()
if (templateCount.reverted) return
const templateCountNum = templateCount.value.toI32()
for (let i = 0; i < templateCountNum; i++) {
const template = contract.try_getTokenTemplate(BigInt.fromI32(1 + i))
if (template.reverted) return
const templateAddress = template.value.templateAddress
.toHexString()
.toLowerCase()
if (templateAddress == eventTemplateAddress) {
token.templateId = 1 + i
}
}
token.save()
addDatatoken()

View File

@ -79,6 +79,7 @@ describe('Datatoken tests', async () => {
const feeToken = '0x3210000000000000000000000000000000000000'
const publishMarketFeeAmount = '0.1'
const cap = '10000'
const templateIndex = 1
let datatokenAddress: string
let nft: Nft
let Factory: NftFactory
@ -111,13 +112,13 @@ describe('Datatoken tests', async () => {
const nftParams: NftCreateData = {
name: nftName,
symbol: nftSymbol,
templateIndex: 1,
templateIndex,
tokenURI: '',
transferable: true,
owner: publisher
}
const erc20Params: Erc20CreateParams = {
templateIndex: 1,
templateIndex,
cap,
feeAmount: publishMarketFeeAmount,
paymentCollector: '0x0000000000000000000000000000000000000000',
@ -197,7 +198,7 @@ describe('Datatoken tests', async () => {
'incorrect value for: publishMarketFeeAmount'
)
assert(dt.templateId === null, 'incorrect value for: templateId')
assert(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')
@ -309,7 +310,7 @@ describe('Datatoken tests', async () => {
dt.publishMarketFeeAmount === publishMarketFeeAmount,
'incorrect value for: publishMarketFeeAmount'
)
assert(dt.templateId === null, 'incorrect value for: templateId')
assert(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')
@ -337,13 +338,13 @@ describe('Datatoken tests', async () => {
const nftParams: NftCreateData = {
name: 'newNFT',
symbol: 'newTST',
templateIndex: 1,
templateIndex,
tokenURI: '',
transferable: true,
owner: publisher
}
const erc20Params: Erc20CreateParams = {
templateIndex: 1,
templateIndex,
cap: '100000',
feeAmount: '0',
paymentCollector: ZERO_ADDRESS,

View File

@ -24,7 +24,6 @@ const data = JSON.parse(
)
const addresses = data.development
// const aquarius = new Aquarius('http://127.0.0.1:5000')
const web3 = new Web3('http://127.0.0.1:8545')
const providerUrl = 'http://172.15.0.4:8030'