Skip to content

Commit

Permalink
fix: change ERC1155Transfer id structure
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurka-o committed Aug 8, 2024
1 parent ba4994c commit 3cc6944
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ type ERC1155Token @entity {
}

type ERC1155Transfer @entity {
id: Bytes!
id: Bytes! # transaction hash + log index + index of transaction in a batch
token: ERC1155Token!
from: Account!
to: Account!
Expand Down
12 changes: 6 additions & 6 deletions src/__test__/unit/power-card.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("Transfer Single event", () => {
})

test("creates ERC1155Transfer entity with correct data", () => {
const transferId = transferSingleEvent.transaction.hash.concatI32(0).toHexString()
const transferId = transferSingleEvent.transaction.hash.concatI32(transferSingleEvent.logIndex.toI32()).concatI32(0).toHexString()

assert.fieldEquals("ERC1155Transfer", transferId, "token", tokenAddress.concatI32(tokenId.toI32()).toHexString())
assert.fieldEquals("ERC1155Transfer", transferId, "from", zeroAddress.toHexString())
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("Transfer Single event", () => {
})

test("creates ERC1155Transfer entity with correct data", () => {
const transferId = transferSingleEvent.transaction.hash.concatI32(0).toHexString()
const transferId = transferSingleEvent.transaction.hash.concatI32(transferSingleEvent.logIndex.toI32()).concatI32(0).toHexString()

assert.fieldEquals("ERC1155Transfer", transferId, "token", tokenAddress.concatI32(tokenId.toI32()).toHexString())
assert.fieldEquals("ERC1155Transfer", transferId, "from", user1Address.toHexString())
Expand Down Expand Up @@ -132,7 +132,7 @@ describe("Transfer Single event", () => {
})

test("creates ERC1155Transfer entity with correct data", () => {
const transferId = transferSingleEvent.transaction.hash.concatI32(0).toHexString()
const transferId = transferSingleEvent.transaction.hash.concatI32(transferSingleEvent.logIndex.toI32()).concatI32(0).toHexString()

assert.fieldEquals("ERC1155Transfer", transferId, "token", tokenAddress.concatI32(tokenId.toI32()).toHexString())
assert.fieldEquals("ERC1155Transfer", transferId, "from", user1Address.toHexString())
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("Transfer Batch event", () => {

test("creates ERC1155Transfer entities with correct data", () => {
for (let i = 0; i < tokenIds.length; i++) {
const transferId = transferBatchEvent.transaction.hash.concatI32(i).toHexString()
const transferId = transferSingleEvent.transaction.hash.concatI32(transferSingleEvent.logIndex.toI32()).concatI32(i).toHexString()

assert.fieldEquals("ERC1155Transfer", transferId, "token", tokenAddress.concatI32(tokenIds[i].toI32()).toHexString())
assert.fieldEquals("ERC1155Transfer", transferId, "from", zeroAddress.toHexString())
Expand Down Expand Up @@ -224,7 +224,7 @@ describe("Transfer Batch event", () => {

test("creates ERC1155Transfer entities with correct data", () => {
for (let i = 0; i < tokenIds.length; i++) {
const transferId = transferBatchEvent.transaction.hash.concatI32(i).toHexString()
const transferId = transferSingleEvent.transaction.hash.concatI32(transferSingleEvent.logIndex.toI32()).concatI32(i).toHexString()

assert.fieldEquals("ERC1155Transfer", transferId, "token", tokenAddress.concatI32(tokenIds[i].toI32()).toHexString())
assert.fieldEquals("ERC1155Transfer", transferId, "from", user1Address.toHexString())
Expand Down Expand Up @@ -258,7 +258,7 @@ describe("Transfer Batch event", () => {

test("creates ERC1155Transfer entity with correct data", () => {
for (let i = 0; i < tokenIds.length; i++) {
const transferId = transferBatchEvent.transaction.hash.concatI32(i).toHexString()
const transferId = transferBatchEvent.transaction.hash.concatI32(transferBatchEvent.logIndex.toI32()).concatI32(i).toHexString()

assert.fieldEquals("ERC1155Transfer", transferId, "token", tokenAddress.concatI32(tokenIds[i].toI32()).toHexString())
assert.fieldEquals("ERC1155Transfer", transferId, "from", user1Address.toHexString())
Expand Down
2 changes: 1 addition & 1 deletion src/power-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function loadERC1155Token(tokenAddress: Address, tokenId: BigInt): ERC1155Token
}

function createERC1155Transfer(from: Account, to: Account, tokenAddress: Address, tokenId: BigInt, value: BigInt, event: ethereum.Event, index: i32): void {
const transferId = event.transaction.hash.concatI32(index);
const transferId = event.transaction.hash.concatI32(event.logIndex.toI32()).concatI32(index);
const transfer = new ERC1155Transfer(transferId);

transfer.token = loadERC1155Token(tokenAddress, tokenId).id;
Expand Down

0 comments on commit 3cc6944

Please sign in to comment.