Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
bbab1f01
Unverified
Commit
bbab1f01
authored
Sep 25, 2019
by
yann300
Committed by
GitHub
Sep 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1300 from ethereum/params_parsing
function params parsing improved
parents
e16d5b42
63da6453
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
26 deletions
+128
-26
txFormat.js
remix-lib/src/execution/txFormat.js
+48
-24
txFormat.js
remix-lib/test/txFormat.js
+80
-2
No files found.
remix-lib/src/execution/txFormat.js
View file @
bbab1f01
...
@@ -388,36 +388,60 @@ module.exports = {
...
@@ -388,36 +388,60 @@ module.exports = {
parseFunctionParams
:
function
(
params
)
{
parseFunctionParams
:
function
(
params
)
{
let
args
=
[]
let
args
=
[]
//
Segregate params textbox string with respect to comma (,)
//
Check if parameter string starts with array or string
params
=
params
.
split
(
','
)
let
startIndex
=
this
.
isArrayOrStringStart
(
params
,
0
)
?
-
1
:
0
for
(
let
i
=
0
;
i
<
params
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
params
.
length
;
i
++
)
{
let
param
=
params
[
i
].
trim
()
// If a quote is received
// Check if param starts with " , it may be string, address etc.
if
(
params
.
charAt
(
i
)
===
'"'
)
{
if
(
param
.
charAt
(
0
)
===
'"'
)
{
startIndex
=
-
1
// Check if param completes in one location by looking for end quote (case: address data type)
let
endQuoteIndex
=
false
if
(
param
.
charAt
(
param
.
length
-
1
)
===
'"'
)
{
// look for closing quote. On success, push the complete string in arguments list
args
.
push
(
param
.
slice
(
1
,
param
.
length
-
1
))
for
(
let
j
=
i
+
1
;
!
endQuoteIndex
;
j
++
)
{
}
else
{
if
(
params
.
charAt
(
j
)
===
'"'
)
{
let
lastIndex
=
false
args
.
push
(
params
.
substring
(
i
+
1
,
j
))
let
paramStr
=
param
.
slice
(
1
,
param
.
length
)
endQuoteIndex
=
true
// For a paramter got divided in multiple location(case: string data type containing comma(,))
i
=
j
for
(
let
j
=
i
+
1
;
!
lastIndex
;
j
++
)
{
// Check if end quote is reached
if
(
params
[
j
].
charAt
(
params
[
j
].
length
-
1
)
===
'"'
)
{
paramStr
+=
','
+
params
[
j
].
slice
(
0
,
params
[
j
].
length
-
1
)
i
=
j
args
.
push
(
paramStr
)
lastIndex
=
true
}
else
{
paramStr
+=
','
+
params
[
j
]
}
}
}
}
}
}
else
{
}
else
if
(
params
.
charAt
(
i
)
===
'['
)
{
// If a array opening bracket is received
args
.
push
(
param
)
startIndex
=
-
1
let
bracketCount
=
1
let
j
for
(
j
=
i
+
1
;
bracketCount
!==
0
;
j
++
)
{
// Increase count if another array opening bracket is received (To handle nested array)
if
(
params
.
charAt
(
j
)
===
'['
)
{
bracketCount
++
}
else
if
(
params
.
charAt
(
j
)
===
']'
)
{
// // Decrease count if an array closing bracket is received (To handle nested array)
bracketCount
--
}
}
// If bracketCount = 0, it means complete array/nested array parsed, push it to the arguments list
args
.
push
(
JSON
.
parse
(
params
.
substring
(
i
,
j
)))
i
=
j
-
1
}
else
if
(
params
.
charAt
(
i
)
===
','
)
{
// if startIndex >= 0, it means a parameter was being parsed, it can be first or other parameter
if
(
startIndex
>=
0
)
{
args
.
push
(
params
.
substring
(
startIndex
,
i
))
}
// Register start index of a parameter to parse
startIndex
=
this
.
isArrayOrStringStart
(
params
,
i
+
1
)
?
-
1
:
i
+
1
}
else
if
(
startIndex
>=
0
&&
i
===
params
.
length
-
1
)
{
// If start index is registered and string is completed (To handle last parameter)
args
.
push
(
params
.
substring
(
startIndex
,
params
.
length
))
}
}
}
}
args
=
args
.
map
(
e
=>
{
if
(
!
Array
.
isArray
(
e
))
{
return
e
.
trim
()
}
else
{
return
e
}
})
return
args
return
args
},
isArrayOrStringStart
:
function
(
str
,
index
)
{
return
str
.
charAt
(
index
)
===
'"'
||
str
.
charAt
(
index
)
===
'['
}
}
}
}
remix-lib/test/txFormat.js
View file @
bbab1f01
...
@@ -50,10 +50,8 @@ function testWithInput (st, params, expected) {
...
@@ -50,10 +50,8 @@ function testWithInput (st, params, expected) {
tape
(
'ContractStringParameters - (TxFormat.buildData) - format string input parameters'
,
function
(
t
)
{
tape
(
'ContractStringParameters - (TxFormat.buildData) - format string input parameters'
,
function
(
t
)
{
var
output
=
compiler
.
compile
(
compilerInput
(
stringContract
))
var
output
=
compiler
.
compile
(
compilerInput
(
stringContract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
console
.
log
(
'-----------------------------'
,
output
)
var
contract
=
output
.
contracts
[
'test.sol'
][
'stringContractTest'
]
var
contract
=
output
.
contracts
[
'test.sol'
][
'stringContractTest'
]
context
=
{
output
,
contract
}
context
=
{
output
,
contract
}
t
.
test
(
'(TxFormat.buildData)'
,
function
(
st
)
{
t
.
test
(
'(TxFormat.buildData)'
,
function
(
st
)
{
st
.
plan
(
3
)
st
.
plan
(
3
)
testWithStringInput
(
st
,
'"1,2,3,4qwerty,5", 0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8, "1,a,5,34"'
,
'0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000f312c322c332c347177657274792c3500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008312c612c352c3334000000000000000000000000000000000000000000000000'
)
testWithStringInput
(
st
,
'"1,2,3,4qwerty,5", 0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8, "1,a,5,34"'
,
'0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000f312c322c332c347177657274792c3500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008312c612c352c3334000000000000000000000000000000000000000000000000'
)
...
@@ -75,6 +73,56 @@ function testWithStringInput (st, params, expected) {
...
@@ -75,6 +73,56 @@ 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
(
'ContractNestedArrayParameters - (TxFormat.buildData) - format nested array input parameters'
,
function
(
t
)
{
var
output
=
compiler
.
compile
(
compilerInput
(
nestedArrayContract
))
output
=
JSON
.
parse
(
output
)
var
contract
=
output
.
contracts
[
'test.sol'
][
'nestedArrayContractTest'
]
context
=
{
output
,
contract
}
t
.
test
(
'(TxFormat.buildData)'
,
function
(
st
)
{
st
.
plan
(
2
)
testWithNestedArrayInput
(
st
,
'[[true],[false]] , [ [[1,2],[3,4],[5,6]], [[1,2],[3,4],[5,6]], [ [1,2],[3,4],[5,6]] ], "ab ab, a,b", 145'
,
'0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000091000000000000000000000000000000000000000000000000000000000000000a61622061622c20612c6200000000000000000000000000000000000000000000'
)
testWithNestedArrayInput
(
st
,
'[[true],[false]] , [ [["1","2"],["3","4"],["5","6"]], [ ["1","2"],["3","4"],["5","6"]], [ ["1","2"],["3","4"],["5","6"]] ], "ab ab, a,b", "145"'
,
'0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000091000000000000000000000000000000000000000000000000000000000000000a61622061622c20612c6200000000000000000000000000000000000000000000'
)
})
})
function
testWithNestedArrayInput
(
st
,
params
,
expected
)
{
txFormat
.
buildData
(
'nestedArrayContractTest'
,
context
.
contract
,
context
.
output
.
contracts
,
true
,
context
.
contract
.
abi
[
1
],
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
(
`testWithNestedArrayInput. result of buildData
${
data
.
dataHex
}
ends with correct data`
)
}
},
()
=>
{},
()
=>
{})
}
/* tape *********************************************************** */
/* tape *********************************************************** */
tape
(
'ContractParameters - (TxFormat.buildData) - link Libraries'
,
function
(
t
)
{
tape
(
'ContractParameters - (TxFormat.buildData) - link Libraries'
,
function
(
t
)
{
...
@@ -274,6 +322,36 @@ var stringContract = `contract stringContractTest {
...
@@ -274,6 +322,36 @@ 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
nestedArrayContract
=
`contract nestedArrayContractTest {
uint public co;
string public str;
bool public b1;
bool public b2;
function test(bool[1][2] memory _p, uint [2][3][3] memory _u, string memory _s, uint p) public {
co = p;
b1 = _p[0][0];
b2= _p[1][0];
str = _s;
}
}`
var
deploySimpleLib
=
`pragma solidity ^0.5.0;
var
deploySimpleLib
=
`pragma solidity ^0.5.0;
library lib1 {
library lib1 {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment