function params parsing improved

pull/7/head
aniket-engg 5 years ago
parent e16d5b42fc
commit 8a76fa8ae3
  1. 20
      remix-lib/src/execution/txFormat.js
  2. 44
      remix-lib/test/txFormat.js

@ -413,6 +413,26 @@ module.exports = {
}
}
}
} else if (param.charAt(0) === '[') { // Check if param starts with [ , it will be an array.
// Check if array completes in one location by looking for end bracket
if (param.charAt(param.length - 1) === ']') {
args.push(param)
} else {
let lastIndex = false
let paramStr = param
// For an array got divided in multiple location
for (let j = i + 1; !lastIndex; j++) {
// Check if end bracket is reached
if (params[j].charAt(params[j].length - 1) === ']') {
paramStr += ',' + params[j]
i = j
args.push(JSON.parse(paramStr))
lastIndex = true
} else {
paramStr += ',' + params[j]
}
}
}
} else {
args.push(param)
}

@ -50,10 +50,8 @@ function testWithInput (st, params, expected) {
tape('ContractStringParameters - (TxFormat.buildData) - format string input parameters', function (t) {
var output = compiler.compile(compilerInput(stringContract))
output = JSON.parse(output)
console.log('-----------------------------', output)
var contract = output.contracts['test.sol']['stringContractTest']
context = { output, contract }
t.test('(TxFormat.buildData)', function (st) {
st.plan(3)
testWithStringInput(st, '"1,2,3,4qwerty,5", 0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8, "1,a,5,34"', '0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000f312c322c332c347177657274792c3500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008312c612c352c3334000000000000000000000000000000000000000000000000')
@ -75,6 +73,32 @@ function testWithStringInput (st, params, expected) {
}, () => {}, () => {})
}
tape('ContractArrayParameters - (TxFormat.buildData) - format array input parameters', function (t) {
var output = compiler.compile(compilerInput(arrayContract))
output = JSON.parse(output)
var contract = output.contracts['test.sol']['arrayContractTest']
context = { output, contract }
t.test('(TxFormat.buildData)', function (st) {
st.plan(3)
testWithArrayInput(st, '[true, false, true], ["0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8", "0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8"], ["0x0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd", "0x0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd"], [12, 34, 45], "itsremix"', '00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea8000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000020c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000000869747372656d6978000000000000000000000000000000000000000000000000')
testWithArrayInput(st, '[true, false, true], ["0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8", "0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8"], ["0x0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd", "0x0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd"], ["12", "34", "45"], "itsremix"', '00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea8000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000020c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000000869747372656d6978000000000000000000000000000000000000000000000000')
// with complex string containing comma, space and underscore
testWithArrayInput(st, '[true, false, true], ["0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8", "0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8"], ["0x0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd", "0x0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd"], ["12", "34", "45"], "its _ re, m,ix"', '00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea8000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000020c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd0c5d9661b4fb92eb7472f28510ea68d4f369c8fe57b3ed4c2e8dfa4e79e549fd0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000001069747320205f202072652c206d2c697800000000000000000000000000000000')
})
})
function testWithArrayInput (st, params, expected) {
txFormat.buildData('arrayContractTest', context.contract, context.output.contracts, true, context.contract.abi[0], params, (error, data) => {
if (error) { return st.fails(error) }
console.log(data)
if (!data.dataHex.endsWith(expected)) {
st.fail(`result of buildData ${data.dataHex} should end with ${expected} . `)
} else {
st.pass(`testWithArrayInput. result of buildData ${data.dataHex} ends with correct data`)
}
}, () => {}, () => {})
}
/* tape *********************************************************** */
tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) {
@ -274,6 +298,22 @@ var stringContract = `contract stringContractTest {
}
}`
var arrayContract = `contract arrayContractTest {
string _sp;
address _ap;
uint _up;
bytes32 _bp;
bool _flag;
function test(bool[] memory _b, address[] memory _a, bytes32[] memory names, uint[] memory _nums, string memory _i) public {
_up = _nums[0];
_ap = _a[0];
_bp = names[0];
_sp = _i;
_flag = _b[0];
}
}`
var deploySimpleLib = `pragma solidity ^0.5.0;
library lib1 {

Loading…
Cancel
Save