invalid tuple input throws error

pull/5370/head
aniket-engg 5 years ago committed by Aniket
parent 5ca0fcb0ec
commit 5a0056e436
  1. 10
      remix-lib/src/execution/txFormat.js
  2. 1
      remix-lib/test/traceManager.js
  3. 36
      remix-lib/test/txFormat.js

@ -401,8 +401,12 @@ module.exports = {
endQuoteIndex = true
i = j
}
// Throw error if end of params string is arrived but couldn't get end quote
if (!endQuoteIndex && j === params.length - 1) {
throw new Error('invalid params')
}
}
} else if (params.charAt(i) === '[') { // If a array opening bracket is received
} else if (params.charAt(i) === '[') { // If an array/struct opening bracket is received
startIndex = -1
let bracketCount = 1
let j
@ -413,6 +417,10 @@ module.exports = {
} else if (params.charAt(j) === ']') { // // Decrease count if an array closing bracket is received (To handle nested array)
bracketCount--
}
// Throw error if end of params string is arrived but couldn't get end of tuple
if (bracketCount !== 0 && j === params.length - 1) {
throw new Error('invalid tuple params')
}
}
// If bracketCount = 0, it means complete array/nested array parsed, push it to the arguments list
args.push(JSON.parse(params.substring(i, j)))

@ -309,7 +309,6 @@ tape('TraceManager', function (t) {
t.test('TraceManager.getReturnValue', function (st) {
traceManager.getReturnValue(108, function (error, result) {
console.log('result------->', result)
if (error) {
st.fail(error)
} else {

@ -125,6 +125,28 @@ function testWithNestedArrayInput (st, params, expected) {
}, () => {}, () => {})
}
tape('abiEncoderV2InvalidTuple - (TxFormat.buildData) - should throw error for invalid tuple value', function (t) {
let output = compiler.compile(compilerInput(abiEncoderV2InvalidTuple))
output = JSON.parse(output)
let contract = output.contracts['test.sol']['test']
context = { output, contract }
t.test('(TxFormat.buildData)', function (st) {
st.plan(4)
testInvalidTupleInput(st, '[11, 12, "13"')
testInvalidTupleInput(st, '[11, 12, 13')
testInvalidTupleInput(st, '[11, 12, "13')
testInvalidTupleInput(st, '[11, 12, 13"')
})
})
function testInvalidTupleInput (st, params) {
txFormat.buildData('abiEncoderV2InvalidTuple', context.contract, context.output.contracts, true, context.contract.abi[2], params, (error, data) => {
if (error) {
return st.ok(error.includes('Error encoding arguments: Error: invalid tuple params'), 'should fail because of invalid tuple input')
}
}, () => {}, () => {})
}
/* tape *********************************************************** */
tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) {
@ -411,6 +433,20 @@ contract test {
mm.b = 133;
return mm;
}
function t2 (p memory _p) public {}
}`
const abiEncoderV2InvalidTuple = `pragma experimental ABIEncoderV2;
contract test {
struct p {
uint a;
uint b;
string s;
}
function t2 (p memory _p) public {}
}`
const abiEncoderV2ArrayOfTuple = `pragma experimental ABIEncoderV2;

Loading…
Cancel
Save