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
e14d029c
Commit
e14d029c
authored
Feb 01, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor deployer into a waterfall
parent
30d67d66
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
52 deletions
+59
-52
index.js
index.js
+1
-1
deployer.js
src/deployer.js
+57
-50
testRunner.js
src/testRunner.js
+1
-1
No files found.
index.js
View file @
e14d029c
...
@@ -26,7 +26,7 @@ var runTest = function(filename, web3) {
...
@@ -26,7 +26,7 @@ var runTest = function(filename, web3) {
},
},
function
runTests
(
contracts
,
next
)
{
function
runTests
(
contracts
,
next
)
{
let
test
=
contracts
.
MyTest
;
let
test
=
contracts
.
MyTest
;
TestRunner
.
runTest
(
"SimpleStorage"
,
test
,
accounts
,
next
);
TestRunner
.
runTest
(
"SimpleStorage"
,
test
,
next
);
}
}
],
function
()
{
],
function
()
{
});
});
...
...
src/deployer.js
View file @
e14d029c
...
@@ -5,63 +5,70 @@ var async = require('async');
...
@@ -5,63 +5,70 @@ var async = require('async');
function
deployAll
(
compileResult
,
web3
,
accounts
,
callback
)
{
function
deployAll
(
compileResult
,
web3
,
accounts
,
callback
)
{
let
compiledObject
=
{},
contracts
=
{};
let
compiledObject
=
{},
contracts
=
{};
for
(
let
contractFile
in
compileResult
)
{
async
.
waterfall
([
for
(
let
contractName
in
compileResult
[
contractFile
])
{
function
getContractData
(
next
)
{
let
contract
=
compileResult
[
contractFile
][
contractName
];
for
(
let
contractFile
in
compileResult
)
{
for
(
let
contractName
in
compileResult
[
contractFile
])
{
let
contract
=
compileResult
[
contractFile
][
contractName
];
const
className
=
contractName
;
const
className
=
contractName
;
const
filename
=
contractFile
;
const
filename
=
contractFile
;
let
abi
=
contract
.
abi
;
let
abi
=
contract
.
abi
;
let
code
=
contract
.
evm
.
bytecode
.
object
;
let
code
=
contract
.
evm
.
bytecode
.
object
;
compiledObject
[
className
]
=
{};
compiledObject
[
className
]
=
{};
compiledObject
[
className
].
abi
=
abi
;
compiledObject
[
className
].
abi
=
abi
;
compiledObject
[
className
].
code
=
code
;
compiledObject
[
className
].
code
=
code
;
compiledObject
[
className
].
filename
=
filename
;
compiledObject
[
className
].
filename
=
filename
;
compiledObject
[
className
].
className
=
className
;
compiledObject
[
className
].
className
=
className
;
}
}
}
async
.
eachOfLimit
(
compiledObject
,
1
,
function
(
contract
,
contractName
,
next
)
{
let
contractObject
=
new
web3
.
eth
.
Contract
(
contract
.
abi
);
let
contractCode
=
"0x"
+
contract
.
code
;
// TODO: temporary code, and terrible if the contracts are not in order...
for
(
let
name
in
compiledObject
)
{
let
contractObj
=
compiledObject
[
name
];
let
linkReference
=
'__'
+
contractObj
.
filename
+
":"
+
contractObj
.
className
;
let
toReplace
=
linkReference
+
"_"
.
repeat
(
40
-
linkReference
.
length
);
if
(
contractCode
.
indexOf
(
linkReference
)
<
0
)
{
continue
}
if
(
!
contractObj
.
deployedAddress
)
{
throw
new
Error
(
"linking not found for "
+
name
+
" when deploying "
+
contractName
);
}
}
next
();
contractCode
=
contractCode
.
replace
(
new
RegExp
(
toReplace
,
"g"
),
contractObj
.
deployedAddress
)
},
function
deployContracts
(
next
)
{
async
.
eachOfLimit
(
compiledObject
,
1
,
function
(
contract
,
contractName
,
nextEach
)
{
let
contractObject
=
new
web3
.
eth
.
Contract
(
contract
.
abi
);
let
contractCode
=
"0x"
+
contract
.
code
;
// TODO: temporary code, and terrible if the contracts are not in order...
for
(
let
name
in
compiledObject
)
{
let
contractObj
=
compiledObject
[
name
];
let
linkReference
=
'__'
+
contractObj
.
filename
+
":"
+
contractObj
.
className
;
let
toReplace
=
linkReference
+
"_"
.
repeat
(
40
-
linkReference
.
length
);
if
(
contractCode
.
indexOf
(
linkReference
)
<
0
)
{
continue
}
if
(
!
contractObj
.
deployedAddress
)
{
throw
new
Error
(
"linking not found for "
+
name
+
" when deploying "
+
contractName
);
}
contractCode
=
contractCode
.
replace
(
new
RegExp
(
toReplace
,
"g"
),
contractObj
.
deployedAddress
)
}
contractObject
.
deploy
({
arguments
:
[],
data
:
contractCode
}).
send
({
from
:
accounts
[
0
],
gas
:
4000
*
1000
}).
on
(
'receipt'
,
function
(
receipt
)
{
contractObject
.
options
.
address
=
receipt
.
contractAddress
;
contractObject
.
options
.
from
=
accounts
[
0
];
contractObject
.
options
.
gas
=
4000
*
1000
;
compiledObject
[
contractName
].
deployedAddress
=
receipt
.
contractAddress
;
contracts
[
contractName
]
=
contractObject
;
nextEach
();
});
},
function
()
{
next
(
null
,
contracts
);
});
}
}
],
callback
);
contractObject
.
deploy
({
arguments
:
[],
data
:
contractCode
}).
send
({
from
:
accounts
[
0
],
gas
:
4000
*
1000
}).
on
(
'receipt'
,
function
(
receipt
)
{
contractObject
.
options
.
address
=
receipt
.
contractAddress
;
contractObject
.
options
.
from
=
accounts
[
0
];
contractObject
.
options
.
gas
=
4000
*
1000
;
compiledObject
[
contractName
].
deployedAddress
=
receipt
.
contractAddress
;
contracts
[
contractName
]
=
contractObject
;
next
();
});
},
function
()
{
callback
(
null
,
contracts
);
});
}
}
module
.
exports
=
{
module
.
exports
=
{
...
...
src/testRunner.js
View file @
e14d029c
...
@@ -2,7 +2,7 @@ var async = require('async');
...
@@ -2,7 +2,7 @@ var async = require('async');
var
changeCase
=
require
(
'change-case'
);
var
changeCase
=
require
(
'change-case'
);
require
(
'colors'
);
require
(
'colors'
);
function
runTest
(
testName
,
testObject
,
accounts
,
callback
)
{
function
runTest
(
testName
,
testObject
,
callback
)
{
let
runList
=
[];
let
runList
=
[];
let
specialFunctions
=
[
'beforeAll'
];
let
specialFunctions
=
[
'beforeAll'
];
let
availableFunctions
=
testObject
.
_jsonInterface
.
filter
((
x
)
=>
x
.
type
===
'function'
).
map
((
x
)
=>
x
.
name
);
let
availableFunctions
=
testObject
.
_jsonInterface
.
filter
((
x
)
=>
x
.
type
===
'function'
).
map
((
x
)
=>
x
.
name
);
...
...
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