Commit 5a1a469f authored by Moody Salem's avatar Moody Salem

perf(multicall): remove the validation that caused app to feel sluggish

parent 4c28f348
......@@ -2,21 +2,27 @@ import { parseCallKey, toCallKey } from './actions'
describe('actions', () => {
describe('#parseCallKey', () => {
it('throws for invalid address', () => {
expect(() => parseCallKey('0x-0x')).toThrow('Invalid address: 0x')
it('does not throw for invalid address', () => {
expect(parseCallKey('0x-0x')).toEqual({ address: '0x', callData: '0x' })
})
it('does not throw for invalid calldata', () => {
expect(parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-abc')).toEqual({
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
callData: 'abc'
})
it('throws for invalid calldata', () => {
expect(() => parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-abc')).toThrow('Invalid hex: abc')
})
it('throws for invalid format', () => {
expect(() => parseCallKey('abc')).toThrow('Invalid call key: abc')
})
it('throws for uppercase hex', () => {
expect(() => parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-0xabcD')).toThrow('Invalid hex: 0xabcD')
it('throws for uppercase calldata', () => {
expect(parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-0xabcD')).toEqual({
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
callData: '0xabcD'
})
})
it('parses pieces into address', () => {
expect(parseCallKey('0x6b175474e89094c44da98b954eedeac495271d0f-0xabcd')).toEqual({
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
callData: '0xabcd'
})
})
......@@ -44,7 +50,7 @@ describe('actions', () => {
})
it('concatenates address to data', () => {
expect(toCallKey({ address: '0x6b175474e89094c44da98b954eedeac495271d0f', callData: '0xabcd' })).toEqual(
'0x6B175474E89094C44Da98b954EedeAC495271d0F-0xabcd'
'0x6b175474e89094c44da98b954eedeac495271d0f-0xabcd'
)
})
})
......
import { createAction } from '@reduxjs/toolkit'
import { isAddress } from '../../utils'
export interface Call {
address: string
callData: string
}
const ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/
const LOWER_HEX_REGEX = /^0x[a-f0-9]*$/
export function toCallKey(call: Call): string {
const addr = isAddress(call.address)
if (!addr) {
if (!ADDRESS_REGEX.test(call.address)) {
throw new Error(`Invalid address: ${call.address}`)
}
if (!LOWER_HEX_REGEX.test(call.callData)) {
throw new Error(`Invalid hex: ${call.callData}`)
}
return `${addr}-${call.callData}`
return `${call.address}-${call.callData}`
}
export function parseCallKey(callKey: string): Call {
......@@ -23,17 +22,8 @@ export function parseCallKey(callKey: string): Call {
if (pcs.length !== 2) {
throw new Error(`Invalid call key: ${callKey}`)
}
const addr = isAddress(pcs[0])
if (!addr) {
throw new Error(`Invalid address: ${pcs[0]}`)
}
if (!LOWER_HEX_REGEX.test(pcs[1])) {
throw new Error(`Invalid hex: ${pcs[1]}`)
}
return {
address: addr,
address: pcs[0],
callData: pcs[1]
}
}
......
......@@ -3,7 +3,6 @@ import reducer, { MulticallState } from './reducer'
import { Store, createStore } from '@reduxjs/toolkit'
const DAI_ADDRESS = '0x6b175474e89094c44da98b954eedeac495271d0f'
const CHECKSUMMED_DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
describe('multicall reducer', () => {
let store: Store<MulticallState>
......@@ -32,7 +31,7 @@ describe('multicall reducer', () => {
expect(store.getState()).toEqual({
callListeners: {
[1]: {
[`${CHECKSUMMED_DAI_ADDRESS}-0x`]: {
[`${DAI_ADDRESS}-0x`]: {
[1]: 1
}
}
......@@ -82,7 +81,7 @@ describe('multicall reducer', () => {
)
expect(store.getState()).toEqual({
callResults: {},
callListeners: { [1]: { [`${CHECKSUMMED_DAI_ADDRESS}-0x`]: {} } }
callListeners: { [1]: { [`${DAI_ADDRESS}-0x`]: {} } }
})
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment