Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-86a6438f2-BS Lib - URL Neo Legacy transaction is not found because… #137

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/blockchain-service",
"comment": "Implement denormalizeHash method",
"type": "patch"
}
],
"packageName": "@cityofzion/blockchain-service"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "",
"type": "none"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo-legacy",
"comment": "Use denormalizeHash in buildTransactionUrl method",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-neo-legacy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Fix getTransactionsByAddress test expect",
"type": "none"
}
],
"packageName": "@cityofzion/bs-neo3"
}
4 changes: 4 additions & 0 deletions packages/blockchain-service/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('BlockscoutBDSEthereum', () => {

const blockscoutBDSNeoX = new BlockscoutBDSEthereum(network)
const transactions = await blockscoutBDSNeoX.getTransactionsByAddress({ address })

expect(transactions).toEqual(expectedResponse)
})

Expand Down
10 changes: 9 additions & 1 deletion packages/bs-neo-legacy/src/__tests__/NeoTubeESNeoLegacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
})
})
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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),
}),
}),
]),
})
Expand Down
Loading