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
ba978eed
Unverified
Commit
ba978eed
authored
Sep 18, 2019
by
Aniket
Committed by
GitHub
Sep 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1294 from ethereum/fix/#1293
string with comma handled
parents
30719524
06d35836
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
4 deletions
+76
-4
txFormat.js
remix-lib/src/execution/txFormat.js
+38
-4
txFormat.js
remix-lib/test/txFormat.js
+38
-0
tasks.todo
tasks.todo
+0
-0
No files found.
remix-lib/src/execution/txFormat.js
View file @
ba978eed
...
...
@@ -169,7 +169,7 @@ module.exports = {
* @param {Function} callbackDeployLibrary - callbackDeployLibrary
*/
buildData
:
function
(
contractName
,
contract
,
contracts
,
isConstructor
,
funAbi
,
params
,
callback
,
callbackStep
,
callbackDeployLibrary
)
{
var
funArgs
=
''
var
funArgs
=
[]
var
data
=
''
var
dataHex
=
''
...
...
@@ -179,9 +179,9 @@ module.exports = {
data
=
Buffer
.
from
(
dataHex
,
'hex'
)
}
else
{
try
{
params
=
params
.
replace
(
/
(
^|,
\s
+|,
)(\d
+
)(\s
+,|,|$
)
/g
,
'$1"$2"$3'
)
// replace non quoted number by quoted number
params
=
params
.
replace
(
/
(
^|,
\s
+|,
)(
0
[
xX
][
0-9a-fA-F
]
+
)(\s
+,|,|$
)
/g
,
'$1"$2"$3'
)
// replace non quoted hex string by quoted hex string
funArgs
=
JSON
.
parse
(
'['
+
params
+
']'
)
if
(
params
.
length
>
0
)
{
funArgs
=
this
.
parseFunctionParams
(
params
)
}
}
catch
(
e
)
{
callback
(
'Error encoding arguments: '
+
e
)
return
...
...
@@ -384,6 +384,40 @@ module.exports = {
}
}
return
{}
},
parseFunctionParams
:
function
(
params
)
{
let
args
=
[]
// Segregate params textbox string with respect to comma (,)
params
=
params
.
split
(
','
)
for
(
let
i
=
0
;
i
<
params
.
length
;
i
++
)
{
let
param
=
params
[
i
].
trim
()
// Check if param starts with " , it may be string, address etc.
if
(
param
.
charAt
(
0
)
===
'"'
)
{
// Check if param completes in one location by looking for end quote (case: address data type)
if
(
param
.
charAt
(
param
.
length
-
1
)
===
'"'
)
{
args
.
push
(
param
.
slice
(
1
,
param
.
length
-
1
))
}
else
{
let
lastIndex
=
false
let
paramStr
=
param
.
slice
(
1
,
param
.
length
)
// For a paramter got divided in multiple location(case: string data type containing comma(,))
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
{
args
.
push
(
param
)
}
}
return
args
}
}
remix-lib/test/txFormat.js
View file @
ba978eed
...
...
@@ -46,6 +46,35 @@ 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'
)
testWithStringInput
(
st
,
'"1,2,3,4qwerty,5", "0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8", "1,a,5,34"'
,
'0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000f312c322c332c347177657274792c3500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008312c612c352c3334000000000000000000000000000000000000000000000000'
)
// string with space
testWithStringInput
(
st
,
'"1,2,3,,4qw erty,5", "0xf7a10e525d4b168f45f74db1b61f63d3e7619ea8", "abcdefghijkl"'
,
'0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000f7a10e525d4b168f45f74db1b61f63d3e7619ea800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000012312c322c332c2c3471772020657274792c350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c6162636465666768696a6b6c0000000000000000000000000000000000000000'
)
})
})
function
testWithStringInput
(
st
,
params
,
expected
)
{
txFormat
.
buildData
(
'stringContractTest'
,
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
(
`testWithStringInput. result of buildData
${
data
.
dataHex
}
ends with correct data`
)
}
},
()
=>
{},
()
=>
{})
}
/* tape *********************************************************** */
tape
(
'ContractParameters - (TxFormat.buildData) - link Libraries'
,
function
(
t
)
{
...
...
@@ -236,6 +265,15 @@ var uintContract = `contract uintContractTest {
}
}`
var
stringContract
=
`contract stringContractTest {
string _tp;
address _ap;
function test(string memory _t, address _a, string memory _i) public {
_tp = _t;
_ap = _a;
}
}`
var
deploySimpleLib
=
`pragma solidity ^0.5.0;
library lib1 {
...
...
remix-analyzer/
tasks.todo
→
tasks.todo
View file @
ba978eed
File moved
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