Skip to content

Commit

Permalink
enum to string
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Oct 31, 2023
1 parent 805fb91 commit 838bf3d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
10 changes: 5 additions & 5 deletions tests/erc1155/transfer-batch-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand All @@ -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)
}
})
})
Expand All @@ -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)
}
})

Expand All @@ -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)
Expand All @@ -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)
}
})
})
Expand Down
10 changes: 5 additions & 5 deletions tests/erc1155/transfer-single-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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],
Expand All @@ -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)
})
})
})
2 changes: 1 addition & 1 deletion tests/helpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions utils/entities/nft/erc-1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions utils/entities/nft/erc-721.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions utils/enums/nft.ts
Original file line number Diff line number Diff line change
@@ -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'
}

0 comments on commit 838bf3d

Please sign in to comment.