Skip to content
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
7 changes: 4 additions & 3 deletions src/containers/Network/UpgradeStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ export const aggregateData = (
* (https://data.xrpl.org/v1/network/topology/nodes)
*
* Node versions often come in in this format:
* rippled-[version]-[release (optional)]+[rippled hash (optional)]
* (rippled|xrpld)-[version]-[release (optional)]+[hash (optional)]
* Output format:
* [version]-[release (optional)]
* e.g. rippled-1.9.4+ba3c0e51455a88d76d90b996f20c0f102ac3f5a0.DEBUG should returns 1.9.4
* rippled-1.9.4-b1 should returns 1.9.4-b1
* xrpld-3.2.0 should returns 3.2.0
*
* @param version - The version retrieved from source data.
* @returns - The correct version format.
*/
const handleNodeVersion = (version: string | undefined) => {
export const handleNodeVersion = (version: string | undefined) => {
let cleanedVersion = version
if (version?.startsWith('rippled'))
if (version?.startsWith('rippled') || version?.startsWith('xrpld'))
cleanedVersion = `${version.split('-').slice(1).join('-')}`
if (version?.includes('+'))
cleanedVersion = `${cleanedVersion?.split('+')[0]}`
Expand Down
33 changes: 33 additions & 0 deletions src/containers/Network/test/upgradeStatus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
aggregateData,
aggregateNodes,
aggregateValidators,
handleNodeVersion,
} from '../UpgradeStatus'
import { UPGRADE_STATUS_ROUTE } from '../../App/routes'

Expand Down Expand Up @@ -77,6 +78,38 @@ const nodesData = [
},
]

describe('handleNodeVersion', () => {
it('strips the rippled- prefix', () => {
expect(handleNodeVersion('rippled-3.1.3')).toEqual('3.1.3')
})

it('strips the xrpld- prefix', () => {
expect(handleNodeVersion('xrpld-3.2.0')).toEqual('3.2.0')
})

it('preserves the release suffix', () => {
expect(handleNodeVersion('xrpld-3.2.0-b7')).toEqual('3.2.0-b7')
expect(handleNodeVersion('rippled-1.9.4-b1')).toEqual('1.9.4-b1')
})

it('strips the build hash after +', () => {
expect(
handleNodeVersion(
'xrpld-3.3.0-b0+9af4fb521e169c056f9eff16779195b7146e8f92.DEBUG',
),
).toEqual('3.3.0-b0')
expect(
handleNodeVersion(
'rippled-1.9.4+ba3c0e51455a88d76d90b996f20c0f102ac3f5a0.DEBUG',
),
).toEqual('1.9.4')
})

it('leaves an already-clean version untouched', () => {
expect(handleNodeVersion('3.2.0')).toEqual('3.2.0')
})
})

describe('UpgradeStatus test functions', () => {
it('aggregate data works with validators without keys', () => {
const validatorAggregate = aggregateValidators(undefinedValidatorsData)
Expand Down
Loading