@@ -7,6 +7,7 @@ const Events = require('../core/events');
77const cloneDeep = require ( 'clone-deep' ) ;
88const AccountParser = require ( '../contracts/accountParser' ) ;
99const Provider = require ( '../contracts/provider' ) ;
10+ const utils = require ( '../utils/utils' ) ;
1011
1112const EmbarkJS = require ( '../../js/embark_node' ) ;
1213
@@ -44,18 +45,29 @@ class Test {
4445
4546 initWeb3Provider ( callback ) {
4647 if ( this . simOptions . host ) {
47- const protocol = ( this . simOptions . type === "rpc" ) ? 'http' : 'ws' ;
48+ let { host, port, type, protocol, accounts} = this . simOptions ;
49+ if ( ! protocol ) {
50+ protocol = ( this . simOptions . type === "rpc" ) ? 'http' : 'ws' ;
51+ }
52+ const endpoint = `${ protocol } ://${ host } :${ port } ` ;
4853 const providerOptions = {
4954 web3 : this . web3 ,
50- type : this . simOptions . type ,
51- accountsConfig : this . simOptions . accounts ,
55+ type,
56+ accountsConfig : accounts ,
5257 blockchainConfig : this . engine . config . blockchainConfig ,
5358 logger : this . engine . logger ,
5459 isDev : false ,
55- web3Endpoint : ` ${ protocol } :// ${ this . simOptions . host } : ${ this . simOptions . port } `
60+ web3Endpoint : endpoint
5661 } ;
57- this . provider = new Provider ( providerOptions ) ;
58- return this . provider . startWeb3Provider ( callback ) ;
62+ console . info ( `Connecting to node at ${ endpoint } ` . cyan ) ;
63+ return utils . pingEndpoint ( host , port , type , protocol , this . engine . config . blockchainConfig . wsOrigins . split ( ',' ) [ 0 ] , ( err ) => {
64+ if ( err ) {
65+ console . error ( `Error connecting to the node, there might be an error in ${ endpoint } ` . red ) ;
66+ return callback ( err ) ;
67+ }
68+ this . provider = new Provider ( providerOptions ) ;
69+ return this . provider . startWeb3Provider ( callback ) ;
70+ } ) ;
5971 }
6072
6173 if ( this . simOptions . accounts ) {
@@ -214,7 +226,12 @@ class Test {
214226 next ( null , accounts ) ;
215227 } ) ;
216228 }
217- ] , callback ) ;
229+ ] , ( err , accounts ) => {
230+ if ( err ) {
231+ process . exit ( 1 ) ;
232+ }
233+ callback ( null , accounts ) ;
234+ } ) ;
218235 }
219236
220237 _deploy ( config , callback ) {
0 commit comments