testing dshackle
This commit is contained in:
875
dshackle-cli/package-lock.json
generated
875
dshackle-cli/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -18,8 +18,7 @@
|
|||||||
"@grpc/proto-loader": "^0.7.2",
|
"@grpc/proto-loader": "^0.7.2",
|
||||||
"arg": "^5.0.2",
|
"arg": "^5.0.2",
|
||||||
"cli-color": "^2.0.3",
|
"cli-color": "^2.0.3",
|
||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25"
|
||||||
"inquirer": "^9.1.1"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin/",
|
"bin/",
|
||||||
|
|||||||
@@ -1,47 +1,109 @@
|
|||||||
import {describe} from "./grpc-clent";
|
import {describe, connect, nativeCall} from "./grpc-clent";
|
||||||
import arg from 'arg';
|
import arg from 'arg';
|
||||||
import clc from "cli-color";
|
import clc from "cli-color";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
|
|
||||||
|
const chains = {
|
||||||
|
CHAIN_BSC: 1006,
|
||||||
|
CHAIN_OPTIMISM: 1005,
|
||||||
|
CHAIN_ARBITRUM: 1004,
|
||||||
|
CHAIN_MATIC: 1002,
|
||||||
|
CHAIN_ETHEREUM: 100
|
||||||
|
}
|
||||||
|
|
||||||
export function cli(args) {
|
export function cli(args) {
|
||||||
let opts = parseArgumentsIntoOptions(args);
|
let opts = parseArgumentsIntoOptions(args);
|
||||||
if (!opts.url) {
|
if (!opts.url) {
|
||||||
console.log("Err: URL not specified!!!")
|
console.log("Err: URL not specified!!!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
describe(opts.url, opts.ca, opts.cert, opts.key, (error, response) => {
|
|
||||||
|
const client = connect(opts.url, opts.ca, opts.cert, opts.key)
|
||||||
|
describe(client, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(clc.red('Connection to ' + opts.url + ' failed! [' + error.message + ']'));
|
console.error(clc.red('Connection to ' + opts.url + ' failed: ' + error.message));
|
||||||
} else {
|
return
|
||||||
console.error(clc.green('Connected to ', opts.url));
|
}
|
||||||
|
console.log(clc.green('Connected to ', opts.url));
|
||||||
if (opts.print) {
|
if (opts.print) {
|
||||||
console.log(util.inspect(response, false, null, true /* enable colors */));
|
console.log(util.inspect(response, false, null, true /* enable colors */));
|
||||||
} else {
|
}
|
||||||
response.chains.forEach(function (item) {
|
processDescribe(client, response, opts.testRun)
|
||||||
var state = item.status.availability;
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function processDescribe(client, response, testRun) {
|
||||||
|
let promises = []
|
||||||
|
let statuses = new Map()
|
||||||
|
|
||||||
|
response.chains.forEach((item) => {
|
||||||
|
const state = item.status.availability
|
||||||
|
const chain = item.status.chain
|
||||||
|
let status = {
|
||||||
|
state: 'AVAIL_UNKNOWN',
|
||||||
|
grpc: clc.yellow('UNKNOWN'),
|
||||||
|
failed: false
|
||||||
|
}
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 'AVAIL_OK':
|
case 'AVAIL_OK':
|
||||||
state = clc.green(state);
|
status.state = clc.green(state);
|
||||||
break
|
break
|
||||||
case 'AVAIL_UNKNOWN':
|
case 'AVAIL_UNKNOWN':
|
||||||
case 'AVAIL_UNAVAILABLE':
|
case 'AVAIL_UNAVAILABLE':
|
||||||
state = clc.red(state);
|
status.state = clc.red(state);
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
state = clc.yellow(state);
|
status.state = clc.yellow(state);
|
||||||
}
|
}
|
||||||
console.log(item.status.chain + ' -> ' + clc.bold(state))
|
|
||||||
|
if (state === 'AVAIL_OK') {
|
||||||
|
promises.push(nativeCall(client, chains[chain], chain))
|
||||||
|
} else {
|
||||||
|
status.failed = true
|
||||||
|
}
|
||||||
|
statuses.set(chain, status)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Promise.all(promises).then(responses => {
|
||||||
|
responses.forEach((resp) => {
|
||||||
|
let status = statuses.get(resp.chain)
|
||||||
|
if (resp.error) {
|
||||||
|
status.failed = true
|
||||||
|
status.grpc = clc.red(resp.error.message)
|
||||||
|
} else {
|
||||||
|
if (resp.payload.succeed) {
|
||||||
|
status.grpc = clc.green('OK')
|
||||||
|
} else {
|
||||||
|
status.grpc = clc.red('FAILED')
|
||||||
|
status.failed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let hasError = false
|
||||||
|
statuses.forEach((status, chain) => {
|
||||||
|
printState(chain, status)
|
||||||
|
if (status.failed) {
|
||||||
|
hasError = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (hasError && testRun) {
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function printState(chain, status) {
|
||||||
|
console.log(chain + ' -> ' + "state: " + clc.bold(status.state) + " gRPC: " + clc.bold(status.grpc))
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseArgumentsIntoOptions(rawArgs) {
|
function parseArgumentsIntoOptions(rawArgs) {
|
||||||
const args = arg(
|
const args = arg(
|
||||||
{
|
{
|
||||||
'--print': Boolean,
|
'--print': Boolean,
|
||||||
|
'--test-run': Boolean,
|
||||||
'--ca': String,
|
'--ca': String,
|
||||||
'--cert': String,
|
'--cert': String,
|
||||||
'--key': String,
|
'--key': String,
|
||||||
@@ -53,6 +115,7 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
print: args['--print'] || false,
|
print: args['--print'] || false,
|
||||||
|
testRun: args['--test-run'] || false,
|
||||||
url: args._[0],
|
url: args._[0],
|
||||||
ca: args['--ca'],
|
ca: args['--ca'],
|
||||||
cert: args['--cert'],
|
cert: args['--cert'],
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ const options = {
|
|||||||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
||||||
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
||||||
|
|
||||||
export function describe(url, ca, cert, key, handler) {
|
|
||||||
|
var id = 100
|
||||||
|
|
||||||
|
export function connect(url, ca, cert, key) {
|
||||||
let credentials = grpc.credentials.createInsecure()
|
let credentials = grpc.credentials.createInsecure()
|
||||||
if (ca || cert || key) {
|
if (ca || cert || key) {
|
||||||
console.log("Using TLS")
|
console.log("Using TLS")
|
||||||
@@ -26,11 +29,41 @@ export function describe(url, ca, cert, key, handler) {
|
|||||||
cert ? fs.readFileSync(cert) : null
|
cert ? fs.readFileSync(cert) : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const client = new emerald.Blockchain(
|
console.log('Connecting to: ' + url + '...')
|
||||||
|
return new emerald.Blockchain(
|
||||||
url,
|
url,
|
||||||
credentials
|
credentials
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Connecting to: ' + url + '...')
|
export function describe(client, handler) {
|
||||||
client.Describe({}, handler);
|
client.Describe({}, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function nativeCall(client, chainCode, chain) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const call = client.NativeCall({
|
||||||
|
chain: chainCode,
|
||||||
|
items: [{
|
||||||
|
id: id++,
|
||||||
|
method: "eth_getBalance",
|
||||||
|
payload: "WyIweDhEOTc2ODlDOTgxODg5MkI3MDBlMjdGMzE2Y2MzRTQxZTE3ZkJlYjkiLCAibGF0ZXN0Il0="
|
||||||
|
}],
|
||||||
|
quorum: 1,
|
||||||
|
min_availability: 0
|
||||||
|
})
|
||||||
|
call.on('data', (item) => {
|
||||||
|
resolve(toResult(chain, item, null))
|
||||||
|
})
|
||||||
|
call.on('end', () => resolve(toResult(chain, null, null)))
|
||||||
|
call.on('error', (e) => reject(toResult(chain, null, e)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function toResult(chain, obj, err) {
|
||||||
|
return {
|
||||||
|
chain: chain,
|
||||||
|
payload: obj,
|
||||||
|
error: err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user