Commit 2203ab4f authored by aniket-engg's avatar aniket-engg Committed by Aniket

invalid tuple input throws error

parent f55409e4
...@@ -401,8 +401,12 @@ module.exports = { ...@@ -401,8 +401,12 @@ module.exports = {
endQuoteIndex = true endQuoteIndex = true
i = j 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 startIndex = -1
let bracketCount = 1 let bracketCount = 1
let j let j
...@@ -413,6 +417,10 @@ module.exports = { ...@@ -413,6 +417,10 @@ module.exports = {
} else if (params.charAt(j) === ']') { // // Decrease count if an array closing bracket is received (To handle nested array) } else if (params.charAt(j) === ']') { // // Decrease count if an array closing bracket is received (To handle nested array)
bracketCount-- 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 // If bracketCount = 0, it means complete array/nested array parsed, push it to the arguments list
args.push(JSON.parse(params.substring(i, j))) args.push(JSON.parse(params.substring(i, j)))
......
...@@ -309,7 +309,6 @@ tape('TraceManager', function (t) { ...@@ -309,7 +309,6 @@ tape('TraceManager', function (t) {
t.test('TraceManager.getReturnValue', function (st) { t.test('TraceManager.getReturnValue', function (st) {
traceManager.getReturnValue(108, function (error, result) { traceManager.getReturnValue(108, function (error, result) {
console.log('result------->', result)
if (error) { if (error) {
st.fail(error) st.fail(error)
} else { } else {
......
...@@ -125,6 +125,28 @@ function testWithNestedArrayInput (st, params, expected) { ...@@ -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 *********************************************************** */
tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) { tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) {
...@@ -411,6 +433,20 @@ contract test { ...@@ -411,6 +433,20 @@ contract test {
mm.b = 133; mm.b = 133;
return mm; 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; const abiEncoderV2ArrayOfTuple = `pragma experimental ABIEncoderV2;
......
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