diff --git a/remix-lib/src/execution/txFormat.js b/remix-lib/src/execution/txFormat.js index 8a36119059..c335e225ca 100644 --- a/remix-lib/src/execution/txFormat.js +++ b/remix-lib/src/execution/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))) diff --git a/remix-lib/test/traceManager.js b/remix-lib/test/traceManager.js index 7b95234b87..503bf7a75d 100644 --- a/remix-lib/test/traceManager.js +++ b/remix-lib/test/traceManager.js @@ -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 { diff --git a/remix-lib/test/txFormat.js b/remix-lib/test/txFormat.js index 0781eb8901..abb0cf01eb 100644 --- a/remix-lib/test/txFormat.js +++ b/remix-lib/test/txFormat.js @@ -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;