Skip to content

Commit

Permalink
Merge pull request #20 from Once-Upon/fix/old-nfts
Browse files Browse the repository at this point in the history
Fix old nfts
  • Loading branch information
jordanmessina authored Feb 27, 2024
2 parents cc46e37 + 6e67dc2 commit 8317d35
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/blocks/ethereum/18815007_decoded.json

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/transformers/_common/netAssetTransfers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { transform as transactionAssetTransfers } from './assetTransfers';
import { transform as transactionAssetTransfersOldNFTs } from './../ethereum/assetTransfersOldNFTs';
import { transform } from './netAssetTransfers';
import { loadBlockFixture } from '../../helpers/utils';
import { KNOWN_ADDRESSES } from '../../helpers/constants';
Expand Down Expand Up @@ -28,4 +29,37 @@ describe('transactionNetAssetTransfers', () => {
]);
}
});

it('should return net asset transfers for old nfts', () => {
const cryptoKittiesBlock = loadBlockFixture('ethereum', '18815007_decoded');
const cryptoKittiesAssetResult =
transactionAssetTransfers(cryptoKittiesBlock);
const cryptoKittiesResult = transactionAssetTransfersOldNFTs(
cryptoKittiesAssetResult,
);
const assetResult = transform(cryptoKittiesResult);
const cryptoKittiesTx = assetResult.transactions.find(
(tx) =>
tx.hash ===
'0x76a07f3f822f6235372804b2ffab705a79b89dbe6a15ad086b6879aa97d60321',
);
expect(cryptoKittiesTx).toBeDefined();
if (cryptoKittiesTx) {
const ckTransfers = cryptoKittiesTx.netAssetTransfers;
expect(Object.keys(ckTransfers).length).toBe(2);
expect(
ckTransfers['0x82f8cb7e198972e2ef89e0c0cc10ffbd878792a6'].sent.length,
).toBe(0);
expect(
ckTransfers['0x82f8cb7e198972e2ef89e0c0cc10ffbd878792a6'].received,
).toStrictEqual([
{
asset: '0x06012c8cf97bead5deae237070f9587f8e7a266d',
id: '0x06012c8cf97bead5deae237070f9587f8e7a266d-2020925',
tokenId: '2020925',
type: 'erc721',
},
]);
}
});
});
17 changes: 17 additions & 0 deletions src/transformers/_common/parties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ describe('transactionParties', () => {
]);
}

const txResult4 = result1.transactions.find(
(tx) =>
tx.hash ===
'0xe408697db3e84a9287f563dafb8243c0e12ed604cc669a07157d40485d43226b',
);
expect(txResult4).toBeDefined();
if (txResult4) {
expect(txResult4.parties).toStrictEqual([
'0xf074c1652d4ff936effe0087e7ce57c62aa7371d',
'0xd1d2eb1b1e90b638588728b4130137d262c87cae',
'0x8d92a6812b3da2346883f0631910c96cb9c5a5f9',
'0x2906bdda4bde0338cf9af4370d5b838da4a0d08f',
'0x1111111254eeb25477b68fb85ed929f73a960582',
'0x54b50187becd0bbcfd52ec5d538433dab044d2a8',
]);
}

const block2 = loadBlockFixture('ethereum', '18965012_decoded');
const result2 = transform(block2);

Expand Down
27 changes: 27 additions & 0 deletions src/transformers/ethereum/assetTransfersOldNFTs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,31 @@ describe('transactionAssetTransfersOldNFTs', () => {
}
}
});

it('should return asset transfers for Cryptokitties transactions', () => {
const cryptoKittiesBlock = loadBlockFixture('ethereum', '18815007_decoded');
const cryptoKittiesAssetResult =
transactionAssetTransfers(cryptoKittiesBlock);
const cryptoKittiesResult = transform(cryptoKittiesAssetResult);
const cryptoKittiesTx = cryptoKittiesResult.transactions.find(
(tx) =>
tx.hash ===
'0x76a07f3f822f6235372804b2ffab705a79b89dbe6a15ad086b6879aa97d60321',
);
expect(cryptoKittiesTx).toBeDefined();
if (cryptoKittiesTx) {
const cryptoKittiesTransfers = cryptoKittiesTx.assetTransfers;
expect(cryptoKittiesTransfers.length).toBe(1);
if ('tokenId' in cryptoKittiesTransfers[0]) {
expect(cryptoKittiesTransfers[0].tokenId).toBe('2020925');
expect(cryptoKittiesTransfers[0].from).toBe(
'0xd695429819d9dd942b2485c3dedd141a774fc774',
);
expect(cryptoKittiesTransfers[0].to).toBe(
'0x82f8cb7e198972e2ef89e0c0cc10ffbd878792a6',
);
}
expect(cryptoKittiesTransfers[0].type).toBe('erc721');
}
});
});
4 changes: 2 additions & 2 deletions src/transformers/ethereum/assetTransfersOldNFTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function updateTokenTransfers(tx: RawTransaction) {
if (logDescriptor) {
oldNFTsTransfers.push({
asset: log.address,
from: decodeEVMAddress(logDescriptor.args['from']),
to: decodeEVMAddress(logDescriptor.args['to']),
from: logDescriptor.args['from'].toLowerCase(),
to: logDescriptor.args['to'].toLowerCase(),
tokenId: BigInt(logDescriptor.args['value']).toString(),
type: AssetType.ERC721,
});
Expand Down

0 comments on commit 8317d35

Please sign in to comment.