Merge pull request #4711 from blockscout/np-fix-contract-inputs-error

Add trimming to the contract functions inputs
pull/4745/head
Victor Baranov 3 years ago committed by GitHub
commit 0692487cb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 180
      apps/block_scout_web/assets/__tests__/lib/smart_contract/common_helpers.js
  3. 7
      apps/block_scout_web/assets/js/lib/smart_contract/common_helpers.js

@ -16,6 +16,7 @@
- [#4579](https://github.com/blockscout/blockscout/pull/4579) - Write contract page: Resize inputs; Improve multiplier selector
### Fixes
- [#4711](https://github.com/blockscout/blockscout/pull/4711) - Add trimming to the contract functions inputs
- [#4729](https://github.com/blockscout/blockscout/pull/4729) - Fix bugs with fees in cases of txs with `gas price = 0`
- [#4725](https://github.com/blockscout/blockscout/pull/4725) - Fix hardcoded coin name on transaction's and block's page
- [#4717](https://github.com/blockscout/blockscout/pull/4717) - Contract verification fix: check only success creation tx

@ -0,0 +1,180 @@
import { prepareMethodArgs } from '../../../js/lib/smart_contract/common_helpers'
import $ from 'jquery'
const oneFieldHTML =
'<form data-function-form>' +
' <input type="hidden" name="function_name" value="convertMultiple">' +
' <input type="hidden" name="method_id" value="">' +
' <div>' +
' <input type="text" name="function_input" id="first">' +
' </div>' +
' <input type="submit" value="Write">' +
'</form>'
const twoFieldHTML =
'<form data-function-form>' +
' <input type="hidden" name="function_name" value="convertMultiple">' +
' <input type="hidden" name="method_id" value="">' +
' <div>' +
' <input type="text" name="function_input" id="first">' +
' </div>' +
' <div>' +
' <input type="text" name="function_input" id="second">' +
' </div>' +
' <input type="submit" value="Write">' +
'</form>'
test('prepare contract args | type: address[]*2', () => {
document.body.innerHTML = twoFieldHTML
var inputs = [
{
"type": "address[]",
"name": "arg1",
"internalType": "address[]"
},
{
"type": "address[]",
"name": "arg2",
"internalType": "address[]"
}
]
document.getElementById('first').value = ' 0x0000000000000000000000000000000000000000 , 0x0000000000000000000000000000000000000001 '
document.getElementById('second').value = ' 0x0000000000000000000000000000000000000002 , 0x0000000000000000000000000000000000000003 '
const expectedValue = [
[
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000001'
],
[
'0x0000000000000000000000000000000000000002',
'0x0000000000000000000000000000000000000003'
]
]
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: address', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "address",
"name": "arg1",
"internalType": "address"
}
]
document.getElementById('first').value = ' 0x000000000000000000 0000000000000000000000 '
const expectedValue = ['0x0000000000000000000000000000000000000000']
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: string', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "string",
"name": "arg1",
"internalType": "string"
}
]
document.getElementById('first').value = ' 0x0000000000000000000000000000000000000000 , 0x0000000000000000000000000000000000000001 '
const expectedValue = ['0x0000000000000000000000000000000000000000 , 0x0000000000000000000000000000000000000001']
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: string[]', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "string[]",
"name": "arg1",
"internalType": "string[]"
}
]
document.getElementById('first').value = ' " 0x0000000000000000000000000000000000000000 " , " 0x0000000000000000000000000000000000000001 " '
const expectedValue = [['0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000001']]
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: bool[]', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "bool[]",
"name": "arg1",
"internalType": "bool[]"
}
]
document.getElementById('first').value = ' true , false '
const expectedValue = [[true, false]]
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: bool', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "bool",
"name": "arg1",
"internalType": "bool"
}
]
document.getElementById('first').value = ' fals e '
const expectedValue = [false]
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: uint256', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "uint256",
"name": "arg1",
"internalType": "uint256"
}
]
document.getElementById('first').value = ' 9 876 543 210 '
const expectedValue = ['9876543210']
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})
test('prepare contract args | type: uint256[]', () => {
document.body.innerHTML = oneFieldHTML
var inputs = [
{
"type": "uint256[]",
"name": "arg1",
"internalType": "uint256[]"
}
]
document.getElementById('first').value = ' 156 000 , 10 690 000 , 59874 '
const expectedValue = [['156000', '10690000', '59874']]
const $functionInputs = $('[data-function-form]').find('input[name=function_input]')
expect(prepareMethodArgs($functionInputs, inputs)).toEqual(expectedValue)
})

@ -23,8 +23,8 @@ export function prepareMethodArgs ($functionInputs, inputs) {
const inputType = inputs[ind] && inputs[ind].type
const inputComponents = inputs[ind] && inputs[ind].components
let sanitizedInputValue
sanitizedInputValue = replaceSpaces(inputValue, inputType, inputComponents)
sanitizedInputValue = replaceDoubleQuotes(sanitizedInputValue, inputType, inputComponents)
sanitizedInputValue = replaceDoubleQuotes(inputValue, inputType, inputComponents)
sanitizedInputValue = replaceSpaces(sanitizedInputValue, inputType, inputComponents)
if (isArrayInputType(inputType) || isTupleInputType(inputType)) {
if (sanitizedInputValue === '' || sanitizedInputValue === '[]') {
@ -38,6 +38,7 @@ export function prepareMethodArgs ($functionInputs, inputs) {
const elementInputType = inputType.split('[')[0]
var sanitizedElementValue = replaceDoubleQuotes(elementValue, elementInputType)
sanitizedElementValue = replaceSpaces(sanitizedElementValue, elementInputType)
if (isBoolInputType(elementInputType)) {
sanitizedElementValue = convertToBool(elementValue)
@ -141,7 +142,7 @@ function replaceSpaces (value, type, components) {
})
.join(',')
} else {
return value
return value.trim()
}
}

Loading…
Cancel
Save