diff --git a/tests/erc1155/transfer-batch-handler.test.ts b/tests/erc1155/transfer-batch-handler.test.ts index ab4b9fc..feba0f0 100644 --- a/tests/erc1155/transfer-batch-handler.test.ts +++ b/tests/erc1155/transfer-batch-handler.test.ts @@ -24,7 +24,7 @@ describe('ERC-1155 Transfer Batch Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) } }) @@ -45,7 +45,7 @@ describe('ERC-1155 Transfer Batch Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) } }) }) @@ -68,7 +68,7 @@ describe('ERC-1155 Transfer Batch Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) } }) @@ -82,7 +82,7 @@ describe('ERC-1155 Transfer Batch Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[i].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[i].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) } const event2 = createTransferBatchEvent(Addresses[0], Addresses[1], Addresses[2], TokenIds, Amounts, ZERO_ADDRESS) @@ -94,7 +94,7 @@ describe('ERC-1155 Transfer Batch Handler', () => { assert.fieldEquals('Nft', _id2, 'tokenId', TokenIds[i].toString()) assert.fieldEquals('Nft', _id2, 'owner', Addresses[2]) assert.fieldEquals('Nft', _id2, 'amount', Amounts[i].toString()) - assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155) } }) }) diff --git a/tests/erc1155/transfer-single-handler.test.ts b/tests/erc1155/transfer-single-handler.test.ts index b9d0b64..1a6b7f2 100644 --- a/tests/erc1155/transfer-single-handler.test.ts +++ b/tests/erc1155/transfer-single-handler.test.ts @@ -28,7 +28,7 @@ describe('ERC-1155 Transfer Single Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[0].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) }) test('should transfer NFT and create Account when NFT exist Account does not', () => { @@ -53,7 +53,7 @@ describe('ERC-1155 Transfer Single Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[0].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) }) }) describe('When NFT or Account exists', () => { @@ -79,7 +79,7 @@ describe('ERC-1155 Transfer Single Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[0].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) }) test('should transfer NFT and update amount after two transfers', () => { @@ -98,7 +98,7 @@ describe('ERC-1155 Transfer Single Handler', () => { assert.fieldEquals('Nft', _id, 'tokenId', TokenIds[0].toString()) assert.fieldEquals('Nft', _id, 'owner', Addresses[1]) assert.fieldEquals('Nft', _id, 'amount', Amounts[1].toString()) - assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id, 'type', NftType.ERC1155) const event2 = createTransferSingleEvent( Addresses[0], @@ -115,7 +115,7 @@ describe('ERC-1155 Transfer Single Handler', () => { assert.fieldEquals('Nft', _id2, 'tokenId', TokenIds[0].toString()) assert.fieldEquals('Nft', _id2, 'owner', Addresses[2]) assert.fieldEquals('Nft', _id2, 'amount', Amounts[0].toString()) - assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155.toString()) + assert.fieldEquals('Nft', _id2, 'type', NftType.ERC1155) }) }) }) diff --git a/tests/helpers/entities.ts b/tests/helpers/entities.ts index 9df4c30..afeb501 100644 --- a/tests/helpers/entities.ts +++ b/tests/helpers/entities.ts @@ -14,7 +14,7 @@ export function createMockNft(tokenAddress: string, tokenId: string, ownerAddres const nft = new Nft(generateERC721NftId(tokenAddress, BigInt.fromString(tokenId))) nft.tokenAddress = tokenAddress nft.tokenId = BigInt.fromString(tokenId) - nft.type = NftType.ERC721.toString() + nft.type = NftType.ERC721 const nftOwner = createMockAccount(ownerAddress) diff --git a/utils/entities/nft/erc-1155.ts b/utils/entities/nft/erc-1155.ts index d2af597..f266f9d 100644 --- a/utils/entities/nft/erc-1155.ts +++ b/utils/entities/nft/erc-1155.ts @@ -16,7 +16,7 @@ export function upsertERC1155Nft(tokenAddress: string, tokenId: BigInt, amount: nft.tokenId = tokenId nft.tokenAddress = tokenAddress nft.owner = findOrCreateAccount(to).id - nft.type = NftType.ERC1155.toString() + nft.type = NftType.ERC1155 } return updateERC1155Balance(findOrCreateAccount(from), findOrCreateAccount(to), nft, amount) @@ -30,7 +30,7 @@ export function findOrCreateERC1155Nft(tokenAddress: string, tokenId: BigInt, to nft = new Nft(nftId) nft.tokenId = tokenId nft.tokenAddress = tokenAddress - nft.type = NftType.ERC1155.toString() + nft.type = NftType.ERC1155 nft.owner = to.id nft.save() } diff --git a/utils/entities/nft/erc-721.ts b/utils/entities/nft/erc-721.ts index 5b6160c..c917c6a 100644 --- a/utils/entities/nft/erc-721.ts +++ b/utils/entities/nft/erc-721.ts @@ -1,5 +1,5 @@ -import { NftType } from '../../enums' import { Nft } from '../../../generated/schema' +import { NftType } from '../../enums' import { findOrCreateAccount } from '../account' import { BigInt } from '@graphprotocol/graph-ts' @@ -14,7 +14,7 @@ export function upsertERC721Nft(tokenAddress: string, tokenId: BigInt, to: strin nft = new Nft(nftId) nft.tokenId = tokenId nft.tokenAddress = tokenAddress - nft.type = NftType.ERC721.toString() + nft.type = NftType.ERC721 } nft.owner = findOrCreateAccount(to).id diff --git a/utils/enums/nft.ts b/utils/enums/nft.ts index 8e24bfe..e7dbff6 100644 --- a/utils/enums/nft.ts +++ b/utils/enums/nft.ts @@ -1,4 +1,7 @@ -export enum NftType { - ERC721, - ERC1155, +// We are using a class instead of an enum because we need to use the values as string, but we need to map it enum alike +export class NftType { + // eslint-disable-next-line @typescript-eslint/no-inferrable-types + static ERC721: string = 'ERC721' + // eslint-disable-next-line @typescript-eslint/no-inferrable-types + static ERC1155: string = 'ERC1155' }