Skip to content

Commit

Permalink
Merge pull request #721 from nymtech/update/bond-form-state-management
Browse files Browse the repository at this point in the history
update state management and validation
  • Loading branch information
fmtabbara authored Aug 9, 2021
2 parents ebeac73 + efc5035 commit 132d550
Show file tree
Hide file tree
Showing 11 changed files with 20,194 additions and 4,433 deletions.
3 changes: 3 additions & 0 deletions wallet-web/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel", "@babel/preset-typescript"]
}
5 changes: 5 additions & 0 deletions wallet-web/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
13 changes: 4 additions & 9 deletions wallet-web/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,10 @@ export const validateIdentityKey = (key: string): boolean => {
}
}

export const validateRawPort = (rawPort: string): boolean => {
// first of all it must be an integer
const port = parseInt(rawPort)
if (port == null) {
return false
}
// and it must be a non-zero 16 bit unsigned integer
return port >= 1 && port <= 65535
}
export const validateRawPort = (rawPort: number): boolean =>
!isNaN(rawPort) && rawPort >= 1 && rawPort <= 65535
// first of all it must be an integer
// and it must be a non-zero 16 bit unsigned integer

export const basicRawCoinValueValidation = (rawAmount: string): boolean => {
let amountFloat = parseFloat(rawAmount)
Expand Down
63 changes: 63 additions & 0 deletions wallet-web/components/bond/BondNodeForm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { validateRawPort } from '../../common/helpers'
import {
isValidHostname,
validateAmount,
validateKey,
validateVersion,
} from './utils'

test('correctly validates ipv4', () => {
expect(isValidHostname('0.0.0.0')).toBe(true)
expect(isValidHostname('192.168.1.1')).toBe(true)
expect(isValidHostname('255.255.255.255')).toBe(true)

expect(isValidHostname('10.168.0001.100')).toBe(false)
expect(isValidHostname('192.168.224.0 1')).toBe(false)
expect(isValidHostname('256.0.0.0')).toBe(false)
})

test('correctly validates ipv6', () => {
expect(isValidHostname('2001:0db8:0000:85a3:0000:0000:ac1f:8001')).toBe(true)
expect(isValidHostname('0000:0000:0000:0000:0000:0000:0000:0000')).toBe(true)
expect(isValidHostname('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')).toBe(true)

expect(isValidHostname('2001:0000:1234: 0000:0000:C1C0:ABCD:0876')).toBe(
false
)
expect(isValidHostname('::1111:2222:3333:4444:5555:6666::')).toBe(false)
expect(isValidHostname('3ffe:b00::1::a')).toBe(false)
expect(isValidHostname('?.?.?')).toBe(false)
})

test('correctly validates hostnames', () => {
expect(isValidHostname('nymtech.net')).toBe(true)
expect(isValidHostname('foo.com')).toBe(true)

expect(isValidHostname('nymtech.?')).toBe(false)
})

test('correctly validates an amount', () => {
expect(validateAmount('100.0625', '100000000')).toBe(true)

expect(validateAmount('100.12343445', '100000000')).toBe(false)
expect(validateAmount('99', '100000000')).toBe(false)
})

test('correctly validates a key', () => {
expect(validateKey('ABCEdoLgy4ETLRa11uDDmtff9tFZZVoKAW4wneQuEyR1')).toBe(true)

expect(validateKey('Agy4ETLRa11uDDmtff9tFZZVoKAeQuEyR1')).toBe(false)
})

test('correctly validates a version', () => {
expect(validateVersion('0.11.0')).toBe(true)

expect(validateVersion('1.2.3')).toBe(false)
})

test('correctly validates a raw port', () => {
expect(validateRawPort(1)).toBe(true)
expect(validateRawPort(3000)).toBe(true)

expect(validateRawPort(9000000)).toBe(false)
})
Loading

0 comments on commit 132d550

Please sign in to comment.