mirror of
https://github.com/tornadocash/tornado-relayer.git
synced 2024-10-01 08:25:37 -04:00
fix isKnownContract validation
This commit is contained in:
parent
ed9f003d50
commit
ecdcb545fc
@ -19,7 +19,7 @@ ajv.addKeyword('isAddress', {
|
||||
ajv.addKeyword('isKnownContract', {
|
||||
validate: (schema, data) => {
|
||||
try {
|
||||
return getInstance(data) !== null
|
||||
return !!getInstance(data)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
|
24
src/utils.js
24
src/utils.js
@ -1,16 +1,26 @@
|
||||
const { instances } = require('./config')
|
||||
const { toChecksumAddress, BN } = require('web3-utils')
|
||||
|
||||
const addressMap = new Map()
|
||||
for (const [currency, { instanceAddress, symbol, decimals }] of Object.entries(instances)) {
|
||||
Object.entries(instanceAddress).forEach(([amount, address]) =>
|
||||
addressMap.set(address, {
|
||||
currency,
|
||||
amount,
|
||||
symbol,
|
||||
decimals,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
function getInstance(address) {
|
||||
address = toChecksumAddress(address)
|
||||
for (const currency of Object.keys(instances)) {
|
||||
for (const amount of Object.keys(instances[currency].instanceAddress)) {
|
||||
if (instances[currency].instanceAddress[amount] === address) {
|
||||
return { currency, amount }
|
||||
}
|
||||
}
|
||||
const key = toChecksumAddress(address)
|
||||
if (addressMap.has(key)) {
|
||||
return addressMap.get(key)
|
||||
} else {
|
||||
throw new Error('Unknown contact address')
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function setSafeInterval(func, interval) {
|
||||
|
@ -10,7 +10,6 @@ const {
|
||||
netId,
|
||||
gasPrices,
|
||||
gasLimits,
|
||||
instances,
|
||||
privateKey,
|
||||
proxyLight,
|
||||
httpRpcUrl,
|
||||
@ -74,8 +73,7 @@ function getGasLimit() {
|
||||
}
|
||||
|
||||
async function checkTornadoFee({ args, contract }) {
|
||||
const { currency, amount } = getInstance(contract)
|
||||
const { decimals } = instances[currency]
|
||||
const { amount, decimals } = getInstance(contract)
|
||||
const fee = toBN(args[4])
|
||||
|
||||
const { fast } = await getGasPrices()
|
||||
|
@ -15,7 +15,13 @@ describe('Validator', () => {
|
||||
'.proof should match pattern "^0x[a-fA-F0-9]{512}$"',
|
||||
)
|
||||
})
|
||||
|
||||
it('should throw if unknown contract', () => {
|
||||
const malformedData = { ...withdrawData }
|
||||
malformedData.contract = '0xf17f52151ebef6c7334fad080c5704d77216b732'
|
||||
getTornadoWithdrawInputError(malformedData).should.be.equal(
|
||||
'.contract should pass "isKnownContract" keyword validation',
|
||||
)
|
||||
})
|
||||
it('should throw something is missing', () => {
|
||||
const malformedData = { ...withdrawData }
|
||||
delete malformedData.proof
|
||||
|
Loading…
Reference in New Issue
Block a user