Comparing version 0.0.15 to 0.0.16
@@ -23,10 +23,36 @@ let doExecSync = null; | ||
const proc = doSpawn(command, [], { | ||
env: { | ||
...process.env, | ||
...envVars, | ||
} | ||
return await new Promise((res,rej)=>{ | ||
let success = true; | ||
let e = null; | ||
const proc = doSpawn(command, [], { | ||
env: { | ||
...process.env, | ||
...envVars, | ||
} | ||
}); | ||
proc.on('error', function(err) { | ||
success = false; | ||
e = err; | ||
}); | ||
setTimeout(()=>{ | ||
if (success) { | ||
res(proc); | ||
} else { | ||
rej(e); | ||
} | ||
}, 100); | ||
}); | ||
return proc; | ||
// const proc = doSpawn(command, [], { | ||
// env: { | ||
// ...process.env, | ||
// ...envVars, | ||
// } | ||
// }); | ||
// proc.on('error', function(err) { | ||
// console.log('Oh noez, teh errurz: ' + err); | ||
// }); | ||
// return proc; | ||
} | ||
@@ -33,0 +59,0 @@ |
@@ -14,3 +14,3 @@ const SuiCommonMethods = require('./SuiCommonMethods.js'); | ||
this._defaultChain = 'sui:devnet'; | ||
this._defaultChain = params.defaultChain || 'sui:devnet'; | ||
@@ -17,0 +17,0 @@ this._activeAdapter = null; |
// const { spawn } = require('child_process'); | ||
const SuiCliCommands = require('./SuiCliCommands.js'); | ||
const SuiCommonMethods = require('./SuiCommonMethods.js'); | ||
const { JsonRpcProvider, localnetConnection, devnetConnection } = require('@mysten/sui.js'); | ||
@@ -11,4 +12,26 @@ class SuiLocalTestValidator extends SuiCommonMethods { | ||
this._active = false; | ||
this._testFallbackEnabled = false; | ||
if (params.testFallbackEnabled) { | ||
// option for unit tests to fallback to sui:dev network in case | ||
// there is no local validator installed | ||
this._testFallbackEnabled = true; | ||
} | ||
this._providerName = 'sui:localnet'; | ||
} | ||
get providerName() { | ||
return this._providerName; | ||
} | ||
get provider() { | ||
if (this._providerName === 'sui:localnet') { | ||
return new JsonRpcProvider(localnetConnection); | ||
} else if (this._providerName === 'sui:devnet') { | ||
// if testFallbackEnabled == true and we can't start local node | ||
return new JsonRpcProvider(devnetConnection); | ||
} | ||
} | ||
get active() { | ||
@@ -34,3 +57,3 @@ return this._active; | ||
async launch() { | ||
if (this._child && this._active) { | ||
if (this._active) { | ||
return this; | ||
@@ -41,4 +64,19 @@ } | ||
this._child = await SuiCliCommands.spawn('sui-test-validator', { RUST_LOG: 'consensus=off' }); | ||
try { | ||
this._child = await SuiCliCommands.spawn('sui-test-validator', { RUST_LOG: 'consensus=off' }); | ||
} catch (e) { | ||
if (this._testFallbackEnabled) { | ||
// can't start local node. Let's switch to sui:dev | ||
this.log('can not start local node. Fallback to sui:dev...'); | ||
this._child = null; | ||
this._active = true; | ||
this._providerName = 'sui:devnet'; | ||
return this; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
this.__readyLaunchedPromiseResolver = null; | ||
@@ -73,2 +111,3 @@ this.__readyLaunchedPromise = new Promise((res)=>{ | ||
process.on('exit', ()=>{ | ||
console.log('this._testFallbackEnabled', this._testFallbackEnabled); | ||
if (this._child) { | ||
@@ -75,0 +114,0 @@ this._child.kill(); |
@@ -37,4 +37,12 @@ const sui = require('@mysten/sui.js'); | ||
if (params.provider == 'local' || (params.provider.constructor && params.provider.constructor.name && params.provider.constructor.name == 'SuiLocalTestValidator')) { | ||
this._provider = new sui.JsonRpcProvider(sui.localnetConnection); | ||
this._providerName = 'sui:localnet'; | ||
if (params.provider == 'local') { | ||
this._provider = new sui.JsonRpcProvider(sui.localnetConnection); | ||
this._providerName = 'sui:localnet'; | ||
} else { | ||
// SuiLocalTestValidator | ||
this._providerName = params.provider.providerName; | ||
this._provider = params.provider.provider; | ||
} | ||
// this._provider = new sui.JsonRpcProvider(sui.localnetConnection); | ||
// this._providerName = 'sui:localnet'; | ||
} else if (params.provider == 'test' || params.provider == 'testnet') { | ||
@@ -41,0 +49,0 @@ this._provider = new sui.JsonRpcProvider(sui.testnetConnection); |
{ | ||
"name": "suidouble", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,2 +20,3 @@ # suidouble | ||
Also take a look at sample Vue dapp application [source code](https://github.com/suidouble/suidouble-sample-app) or [check it online](https://suidouble-sample-app.herokuapp.com/). | ||
@@ -22,0 +23,0 @@ ### installation |
@@ -19,3 +19,3 @@ 'use strict' | ||
test('spawn local test node', async t => { | ||
suiLocalTestValidator = await SuiLocalTestValidator.launch(); | ||
suiLocalTestValidator = await SuiLocalTestValidator.launch({ testFallbackEnabled: true }); | ||
t.ok(suiLocalTestValidator.active); | ||
@@ -29,3 +29,3 @@ | ||
test('init suiMaster and connect it to local test validator', async t => { | ||
suiMaster = new SuiMaster({provider: suiLocalTestValidator, as: 'somebody'}); | ||
suiMaster = new SuiMaster({provider: suiLocalTestValidator, as: 'somebody', debug: false}); | ||
await suiMaster.initialize(); | ||
@@ -32,0 +32,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166946
27
2465
314