Skip to content

Commit fd40e49

Browse files
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
1 parent bd03b28 commit fd40e49

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/mappings/erc721Factory.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory'
1+
import {
2+
NFTCreated,
3+
TokenCreated,
4+
ERC721Factory
5+
} from '../@types/ERC721Factory/ERC721Factory'
26
import { decimal } from './utils/constants'
37
import { weiToDecimal } from './utils/generic'
48

59
import { getUser } from './utils/userUtils'
610
import { getToken, getNftToken } from './utils/tokenUtils'
711
import { addDatatoken } from './utils/globalUtils'
12+
import { BigInt } from '@graphprotocol/graph-ts'
813

914
export function handleNftCreated(event: NFTCreated): void {
1015
// const nft = new Nft(event.params.newTokenAddress.toHexString())
@@ -42,6 +47,24 @@ export function handleNewToken(event: TokenCreated): void {
4247
token.decimals = 18
4348
token.supply = decimal.ZERO
4449
token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18)
50+
const eventTemplateAddress = event.params.templateAddress
51+
.toHexString()
52+
.toLowerCase()
53+
const contract = ERC721Factory.bind(event.address)
54+
const templateCount = contract.try_getCurrentTemplateCount()
55+
if (templateCount.reverted) return
56+
const templateCountNum = templateCount.value.toI32()
57+
58+
for (let i = 0; i < templateCountNum; i++) {
59+
const template = contract.try_getTokenTemplate(BigInt.fromI32(1 + i))
60+
if (template.reverted) return
61+
const templateAddress = template.value.templateAddress
62+
.toHexString()
63+
.toLowerCase()
64+
if (templateAddress == eventTemplateAddress) {
65+
token.templateId = 1 + i
66+
}
67+
}
4568

4669
token.save()
4770
addDatatoken()

test/integration/Datatoken.test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('Datatoken tests', async () => {
7979
const feeToken = '0x3210000000000000000000000000000000000000'
8080
const publishMarketFeeAmount = '0.1'
8181
const cap = '10000'
82+
const templateIndex = 1
8283
let datatokenAddress: string
8384
let nft: Nft
8485
let Factory: NftFactory
@@ -111,13 +112,13 @@ describe('Datatoken tests', async () => {
111112
const nftParams: NftCreateData = {
112113
name: nftName,
113114
symbol: nftSymbol,
114-
templateIndex: 1,
115+
templateIndex,
115116
tokenURI: '',
116117
transferable: true,
117118
owner: publisher
118119
}
119120
const erc20Params: Erc20CreateParams = {
120-
templateIndex: 1,
121+
templateIndex,
121122
cap,
122123
feeAmount: publishMarketFeeAmount,
123124
paymentCollector: '0x0000000000000000000000000000000000000000',
@@ -197,7 +198,7 @@ describe('Datatoken tests', async () => {
197198
'incorrect value for: publishMarketFeeAmount'
198199
)
199200

200-
assert(dt.templateId === null, 'incorrect value for: templateId')
201+
assert(dt.templateId === templateIndex, 'incorrect value for: templateId')
201202
assert(dt.holderCount === '0', 'incorrect value for: holderCount')
202203
assert(dt.orderCount === '0', 'incorrect value for: orderCount')
203204
assert(dt.orders, 'incorrect value for: orders')
@@ -309,7 +310,7 @@ describe('Datatoken tests', async () => {
309310
dt.publishMarketFeeAmount === publishMarketFeeAmount,
310311
'incorrect value for: publishMarketFeeAmount'
311312
)
312-
assert(dt.templateId === null, 'incorrect value for: templateId')
313+
assert(dt.templateId === templateIndex, 'incorrect value for: templateId')
313314
assert(dt.holderCount === '0', 'incorrect value for: holderCount')
314315
assert(dt.orderCount === '0', 'incorrect value for: orderCount')
315316
assert(dt.orders, 'incorrect value for: orders')
@@ -337,13 +338,13 @@ describe('Datatoken tests', async () => {
337338
const nftParams: NftCreateData = {
338339
name: 'newNFT',
339340
symbol: 'newTST',
340-
templateIndex: 1,
341+
templateIndex,
341342
tokenURI: '',
342343
transferable: true,
343344
owner: publisher
344345
}
345346
const erc20Params: Erc20CreateParams = {
346-
templateIndex: 1,
347+
templateIndex,
347348
cap: '100000',
348349
feeAmount: '0',
349350
paymentCollector: ZERO_ADDRESS,

test/integration/Nft.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const data = JSON.parse(
2424
)
2525

2626
const addresses = data.development
27-
// const aquarius = new Aquarius('http://127.0.0.1:5000')
2827
const web3 = new Web3('http://127.0.0.1:8545')
2928

3029
const providerUrl = 'http://172.15.0.4:8030'

0 commit comments

Comments
 (0)