Skip to content

Commit

Permalink
Merge pull request #659 from poanetwork/validate-imported-whitelist-a…
Browse files Browse the repository at this point in the history
…ddresses-#641

(Feature) Validate imported whitelist addresses
  • Loading branch information
vbaranov committed Mar 12, 2018
2 parents 394c287 + bd4fe39 commit 3e31b35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/utils/processWhitelist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { validateAddress } from './utils'
import Web3 from 'web3'

const isAddress = (address) => validateAddress(address)
const isNumber = (number) => !isNaN(parseFloat(number))

/**
Expand All @@ -18,7 +17,7 @@ export default function (rows, cb) {

const [addr, min, max] = row

if (!isAddress(addr) || !isNumber(min) || !isNumber(max)) return
if (!Web3.utils.isAddress(addr) || !isNumber(min) || !isNumber(max)) return

cb({ addr, min, max })

Expand Down
6 changes: 4 additions & 2 deletions src/utils/processWhitelist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ describe('processWhitelist function', () => {
it('should ignore invalid addresses', () => {
// Given
const rows = [
['0x123456789012345678901234567890123456789', '1', '10'],
['0x12345678901234567890123456789012345678901', '1', '10']
['0x123456789012345678901234567890123456789', '1', '10'], // 41 characters
['0x12345678901234567890123456789012345678901', '1', '10'], // 43 characters
['0x90F8bf6A479f320ead074411a4B0e7944Ea8c9CG', '1', '10'], // invalid character
['0x90F8bf6A479f320ead074411a4B0e7944Ea8c9c1', '1', '10'] // invalid checksum
]
const cb = jest.fn()

Expand Down

0 comments on commit 3e31b35

Please sign in to comment.