From 79151e3359459123cd431b96360208bec2278bf9 Mon Sep 17 00:00:00 2001 From: hotequil Date: Fri, 3 Jan 2025 17:50:45 -0300 Subject: [PATCH] CU-86a6438f2-BS Lib - URL Neo Legacy transaction is not found because there is no 0x in the prefix --- .../CU-86a6438f2_2025-01-03-20-48.json | 10 +++++++ .../CU-86a6438f2_2025-01-03-20-48.json | 10 +++++++ .../CU-86a6438f2_2025-01-03-20-48.json | 10 +++++++ .../CU-86a6438f2_2025-01-03-20-48.json | 10 +++++++ packages/blockchain-service/src/functions.ts | 4 +++ .../__tests__/BlockscoutBDSEthereum.spec.ts | 1 + .../src/__tests__/NeoTubeESNeoLegacy.spec.ts | 10 ++++++- .../services/explorer/NeoTubeESNeoLegacy.ts | 5 ++-- .../blockchain-data/DoraBDSNeo3.spec.ts | 29 ++++++++++++++----- 9 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 common/changes/@cityofzion/blockchain-service/CU-86a6438f2_2025-01-03-20-48.json create mode 100644 common/changes/@cityofzion/bs-ethereum/CU-86a6438f2_2025-01-03-20-48.json create mode 100644 common/changes/@cityofzion/bs-neo-legacy/CU-86a6438f2_2025-01-03-20-48.json create mode 100644 common/changes/@cityofzion/bs-neo3/CU-86a6438f2_2025-01-03-20-48.json diff --git a/common/changes/@cityofzion/blockchain-service/CU-86a6438f2_2025-01-03-20-48.json b/common/changes/@cityofzion/blockchain-service/CU-86a6438f2_2025-01-03-20-48.json new file mode 100644 index 0000000..695a6ee --- /dev/null +++ b/common/changes/@cityofzion/blockchain-service/CU-86a6438f2_2025-01-03-20-48.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/blockchain-service", + "comment": "Implement denormalizeHash method", + "type": "patch" + } + ], + "packageName": "@cityofzion/blockchain-service" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-ethereum/CU-86a6438f2_2025-01-03-20-48.json b/common/changes/@cityofzion/bs-ethereum/CU-86a6438f2_2025-01-03-20-48.json new file mode 100644 index 0000000..b5e710f --- /dev/null +++ b/common/changes/@cityofzion/bs-ethereum/CU-86a6438f2_2025-01-03-20-48.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-ethereum", + "comment": "", + "type": "none" + } + ], + "packageName": "@cityofzion/bs-ethereum" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-neo-legacy/CU-86a6438f2_2025-01-03-20-48.json b/common/changes/@cityofzion/bs-neo-legacy/CU-86a6438f2_2025-01-03-20-48.json new file mode 100644 index 0000000..65eb7c7 --- /dev/null +++ b/common/changes/@cityofzion/bs-neo-legacy/CU-86a6438f2_2025-01-03-20-48.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-neo-legacy", + "comment": "Use denormalizeHash in buildTransactionUrl method", + "type": "patch" + } + ], + "packageName": "@cityofzion/bs-neo-legacy" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/bs-neo3/CU-86a6438f2_2025-01-03-20-48.json b/common/changes/@cityofzion/bs-neo3/CU-86a6438f2_2025-01-03-20-48.json new file mode 100644 index 0000000..0e1351c --- /dev/null +++ b/common/changes/@cityofzion/bs-neo3/CU-86a6438f2_2025-01-03-20-48.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/bs-neo3", + "comment": "Fix getTransactionsByAddress test expect", + "type": "none" + } + ], + "packageName": "@cityofzion/bs-neo3" +} \ No newline at end of file diff --git a/packages/blockchain-service/src/functions.ts b/packages/blockchain-service/src/functions.ts index e442204..5d43f21 100644 --- a/packages/blockchain-service/src/functions.ts +++ b/packages/blockchain-service/src/functions.ts @@ -143,6 +143,10 @@ export function normalizeHash(hash: string): string { return hash.replace('0x', '').toLowerCase() } +export function denormalizeHash(hash: string): string { + return hash.startsWith('0x') ? hash : `0x${hash}` +} + export function countDecimals(value: string | number) { const [, decimals] = value.toString().split('.') return decimals?.length ?? 0 diff --git a/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts b/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts index 98519cb..55f766e 100644 --- a/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts +++ b/packages/bs-ethereum/src/__tests__/BlockscoutBDSEthereum.spec.ts @@ -110,6 +110,7 @@ describe('BlockscoutBDSEthereum', () => { const blockscoutBDSNeoX = new BlockscoutBDSEthereum(network) const transactions = await blockscoutBDSNeoX.getTransactionsByAddress({ address }) + expect(transactions).toEqual(expectedResponse) }) diff --git a/packages/bs-neo-legacy/src/__tests__/NeoTubeESNeoLegacy.spec.ts b/packages/bs-neo-legacy/src/__tests__/NeoTubeESNeoLegacy.spec.ts index cebbf84..9a275ec 100644 --- a/packages/bs-neo-legacy/src/__tests__/NeoTubeESNeoLegacy.spec.ts +++ b/packages/bs-neo-legacy/src/__tests__/NeoTubeESNeoLegacy.spec.ts @@ -6,13 +6,21 @@ let neoTubeESNeoLegacy: NeoTubeESNeoLegacy describe('NeoTubeESNeoLegacy', () => { beforeAll(() => { const network = BSNeoLegacyConstants.DEFAULT_NETWORK + neoTubeESNeoLegacy = new NeoTubeESNeoLegacy(network) }) - it('Should return a transaction url', async () => { + it('Should return a transaction url by hash when call the buildTransactionUrl method', async () => { const hash = '0x0cd2d834d910dcb74c19bbbb1c986a94e292e1160f0d9f138b97ac950a5ac700' const url = neoTubeESNeoLegacy.buildTransactionUrl(hash) expect(url).toEqual(`https://neo2.neotube.io/transaction/${hash}`) }) + + it('Should return a transaction url by normalized hash when call the buildTransactionUrl method', async () => { + const hash = '0cd2d834d910dcb74c19bbbb1c986a94e292e1160f0d9f138b97ac950a5ac700' + const url = neoTubeESNeoLegacy.buildTransactionUrl(hash) + + expect(url).toEqual(`https://neo2.neotube.io/transaction/0x${hash}`) + }) }) diff --git a/packages/bs-neo-legacy/src/services/explorer/NeoTubeESNeoLegacy.ts b/packages/bs-neo-legacy/src/services/explorer/NeoTubeESNeoLegacy.ts index e4cb89f..033fd98 100644 --- a/packages/bs-neo-legacy/src/services/explorer/NeoTubeESNeoLegacy.ts +++ b/packages/bs-neo-legacy/src/services/explorer/NeoTubeESNeoLegacy.ts @@ -1,4 +1,4 @@ -import { BuildNftUrlParams, ExplorerService, Network } from '@cityofzion/blockchain-service' +import { BuildNftUrlParams, denormalizeHash, ExplorerService, Network } from '@cityofzion/blockchain-service' import { BSNeoLegacyNetworkId } from '../../constants/BSNeoLegacyConstants' import { BSNeoLegacyHelper } from '../../helpers/BSNeoLegacyHelper' @@ -11,7 +11,8 @@ export class NeoTubeESNeoLegacy implements ExplorerService { buildTransactionUrl(hash: string): string { if (!BSNeoLegacyHelper.isMainnet(this.#network)) throw new Error('NeoTube is only available on mainnet') - return `https://neo2.neotube.io/transaction/${hash}` + + return `https://neo2.neotube.io/transaction/${denormalizeHash(hash)}` } buildContractUrl(contractHash: string): string { diff --git a/packages/bs-neo3/src/__tests__/services/blockchain-data/DoraBDSNeo3.spec.ts b/packages/bs-neo3/src/__tests__/services/blockchain-data/DoraBDSNeo3.spec.ts index fbec9a5..79df1f7 100644 --- a/packages/bs-neo3/src/__tests__/services/blockchain-data/DoraBDSNeo3.spec.ts +++ b/packages/bs-neo3/src/__tests__/services/blockchain-data/DoraBDSNeo3.spec.ts @@ -31,7 +31,7 @@ describe('DoraBDSNeo3', () => { }) it('Should be able to get transactions of address', async () => { - const address = 'NPB3Cze4wki9J36nnrT45qmi6P52Bhfqph' + const address = 'NRwXs5yZRMuuXUo7AqvetHQ4GDHe3pV7Mb' const response = await doraBDSNeo3.getTransactionsByAddress({ address, nextPageParams: 1 }) response.transactions.forEach(transaction => { @@ -44,20 +44,33 @@ describe('DoraBDSNeo3', () => { notifications: expect.arrayContaining([ expect.objectContaining({ eventName: expect.any(String), - state: expect.arrayContaining([ - { - type: expect.any(String), - value: expect.any(String), - }, - ]), + state: expect.objectContaining({ + type: expect.any(String), + value: expect.arrayContaining([ + expect.objectContaining({ + value: expect.any(String), + }), + expect.objectContaining({ + type: expect.any(String), + value: expect.any(String), + }), + ]), + }), }), ]), transfers: expect.arrayContaining([ expect.objectContaining({ amount: expect.any(String), + contractHash: expect.any(String), from: expect.any(String), to: expect.any(String), - type: 'token', + type: expect.any(String), + token: expect.objectContaining({ + decimals: expect.any(Number), + hash: expect.any(String), + name: expect.any(String), + symbol: expect.any(String), + }), }), ]), })