Skip to content

Commit

Permalink
Adding Improvements to Lamington for logging and more recent version …
Browse files Browse the repository at this point in the history
…of EOSIO.
  • Loading branch information
dallasjohnson committed Feb 7, 2020
1 parent e229323 commit ee10568
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 29 deletions.
97 changes: 87 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "npm run clean && tsc && npm run copy:scripts",
"build": "npm run clean && tsc && npm run copy:scripts && npm run copy:configs",
"changelog": "auto-changelog --commit-limit false",
"check:types": "tsc --noEmit",
"copy:scripts": "cp -r ./src/scripts/ ./lib/scripts/",
"copy:configs": "cp -R ./src/eosio-config ./lib/eosio-config",
"clean": "rm -rf ./lib",
"docs": "typedoc --out api-docs ./src",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
Expand Down Expand Up @@ -66,8 +67,10 @@
"typescript": "3.7.3"
},
"dependencies": {
"@types/chalk": "^2.2.0",
"axios": "0.19.0",
"chai": "4.2.0",
"chalk": "^3.0.0",
"clarify": "2.1.0",
"colors": "1.4.0",
"commander": "4.0.1",
Expand Down
4 changes: 3 additions & 1 deletion src/accounts/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ export class AccountManager {
});
}
// Execute the transaction
return await EOSManager.transact({ actions }, eos);
return await EOSManager.transact({ actions }, eos, {
logMessage: `Creating account: ${account.name}}`,
});
};

/**
Expand Down
5 changes: 4 additions & 1 deletion src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import * as spinner from './logIndicator';

/** @hidden Current working directory reference */
const WORKING_DIRECTORY = process.cwd();
/** @hidden Config directory for running EOSIO */
const CONFIG_DIRECTORY = path.join(__dirname, '../eosio-config');
/** @hidden Temporary docker resource directory */
const TEMP_DOCKER_DIRECTORY = path.join(__dirname, '.temp-docker');
/** @hidden Slowest Expected test duration */
Expand Down Expand Up @@ -134,6 +136,7 @@ export const startContainer = async () => {
-p 9876:9876
--mount type=bind,src="${WORKING_DIRECTORY}",dst=/opt/eosio/bin/project
--mount type=bind,src="${__dirname}/../scripts",dst=/opt/eosio/bin/scripts
--mount type=bind,src="${CONFIG_DIRECTORY}",dst=/mnt/dev/config
-w "/opt/eosio/bin/"
${await dockerImageName()}
/bin/bash -c "./scripts/init_blockchain.sh"`
Expand Down Expand Up @@ -286,7 +289,7 @@ export const runTests = async () => {
mocha.slow(TEST_EXPECTED_DURATION);
mocha.timeout(TEST_TIMEOUT_DURATION);
mocha.reporter(ConfigManager.testReporter);
mocha.bail(true);
mocha.bail(ConfigManager.bailOnFailure);

// Run the tests.
await new Promise((resolve, reject) =>
Expand Down
61 changes: 57 additions & 4 deletions src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,30 @@ export interface LamingtonConfig {
debug: LamingtonDebugLevel;
reporter?: string;
reporterOptions?: any;
bailOnFailure: boolean;
}

/** Level of debug output */
/**
* Level of debug output
*/
export enum LamingtonDebugLevel {
NONE = 0,
TRANSACTIONS,
ALL,
NONE = 0, // No debug logging
MINIMAL, // Brief summary of actions as executed
VERBOSE, // Verbose output from actions including all transaction output
}

export namespace LamingtonDebugLevel {
export function isNone(debugLevel: LamingtonDebugLevel) {
return debugLevel == LamingtonDebugLevel.NONE;
}

export function isMin(debugLevel: LamingtonDebugLevel) {
return debugLevel == LamingtonDebugLevel.MINIMAL;
}

export function isVerbose(debugLevel: LamingtonDebugLevel) {
return debugLevel == LamingtonDebugLevel.VERBOSE;
}
}

/**
Expand All @@ -56,6 +73,7 @@ const DEFAULT_CONFIG = {
keepAlive: false,
outDir: CACHE_DIRECTORY,
exclude: [],
bailOnFailure: false,
};

/**
Expand Down Expand Up @@ -216,6 +234,31 @@ export class ConfigManager {
);
}

/**
* Returns the container's debugLevel output setting
* @author Dallas Johnson <github.com/dallasjohnson>
*/
static get debugLevel() {
return (ConfigManager.config && ConfigManager.config.debug) || DEFAULT_CONFIG.debug;
}

/**
* Returns the container's debugLevel output setting
* @author Dallas Johnson <github.com/dallasjohnson>
*/

static get debugLevelNone() {
return LamingtonDebugLevel.isNone(this.debugLevel);
}

static get debugLevelMin() {
return LamingtonDebugLevel.isMin(this.debugLevel);
}

static get debugLevelVerbose() {
return LamingtonDebugLevel.isVerbose(this.debugLevel);
}

/**
* Returns the output build directory or [[CACHE_DIRECTORY]]
* @author Mitch Pierias <github.com/MitchPierias>
Expand All @@ -239,4 +282,14 @@ export class ConfigManager {
static get testReporter() {
return (ConfigManager.config && ConfigManager.config.reporter) || Mocha.reporters.Min;
}

/**
* Returns the array of excluded strings or patterns
* @author Dallas Johnson <github.com/dallasjohnson>
*/
static get bailOnFailure() {
return (
(ConfigManager.config && ConfigManager.config.bailOnFailure) || DEFAULT_CONFIG.bailOnFailure
);
}
}
44 changes: 35 additions & 9 deletions src/eosManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { TextEncoder, TextDecoder } from 'util';
import { Api, JsonRpc } from 'eosjs';
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig';
import { Account } from './accounts';
import { ConfigManager } from './configManager';
import { ConfigManager, LamingtonDebugLevel } from './configManager';
import { convertLegacyPublicKey } from 'eosjs/dist/eosjs-numeric';
import { timer } from './utils';
import * as chalk from 'chalk';

interface InitArgs {
adminAccount: Account;
Expand Down Expand Up @@ -95,18 +97,42 @@ export class EOSManager {
static transact = async (
transaction: any,
eos = EOSManager.api,
options?: { debug?: boolean; blocksBehind?: number; expireSeconds?: number }
options?: {
debug?: boolean;
debugLevel?: LamingtonDebugLevel;
blocksBehind?: number;
expireSeconds?: number;
logMessage?: string;
}
) => {
const flattenedOptions = Object.assign({ blocksBehind: 1, expireSeconds: 30 }, options);

if (ConfigManager.debugTransactions || flattenedOptions.debug) {
const calls = transaction.actions.map((action: any) => `${action.account}.${action.name}`);
console.log(`========== Calling ${calls.join(', ')} ==========`);
console.log('Transaction: ', JSON.stringify(transaction, null, 4));
console.log('Options: ', options);
console.log();
const transactionTimer = timer();

async function logOutput(verboseOutput: string) {
const legacyDebugOption = ConfigManager.debugTransactions || flattenedOptions.debug;

if (ConfigManager.debugLevelMin || ConfigManager.debugLevelVerbose || legacyDebugOption) {
let consoleHeader = '';
const calls = transaction.actions.map((action: any) => `${action.account}.${action.name}`);
consoleHeader += `========== Calling ${calls.join(', ')} ==========`;
console.log(chalk.cyan(consoleHeader) + chalk.blue(' (%s)'), transactionTimer.ms);
}
if (ConfigManager.debugLevelVerbose) {
console.log(verboseOutput);
console.log('Options: ', options);
}
}

return await eos.transact(transaction, flattenedOptions);
return await eos
.transact(transaction, flattenedOptions)
.then(value => {
logOutput(chalk.green('Succeeded: ') + JSON.stringify(value, null, 4));
return value;
})
.catch(error => {
logOutput(chalk.red('Threw error: ') + error);
throw error;
});
};
}
23 changes: 23 additions & 0 deletions src/eosio-config/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"initial_timestamp": "2018-06-08T08:08:08.888",
"initial_key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"initial_configuration": {
"max_block_net_usage": 1048576,
"target_block_net_usage_pct": 1000,
"max_transaction_net_usage": 524288,
"base_per_transaction_net_usage": 12,
"net_usage_leeway": 500,
"context_free_discount_net_usage_num": 20,
"context_free_discount_net_usage_den": 100,
"max_block_cpu_usage": 200000,
"target_block_cpu_usage_pct": 1000,
"max_transaction_cpu_usage": 150000,
"min_transaction_cpu_usage": 100,
"max_transaction_lifetime": 3600,
"deferred_trx_expiration_window": 600,
"max_transaction_delay": 3888000,
"max_inline_action_size": 4096,
"max_inline_action_depth": 4,
"max_authority_depth": 6
}
}
4 changes: 3 additions & 1 deletion src/scripts/init_blockchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ rm -rf /mnt/dev/data
# run it in a background job such that docker run could continue
nodeos -e -p eosio -d /mnt/dev/data \
--config-dir /mnt/dev/config \
--max-transaction-time=40 \
--genesis-json /mnt/dev/config/genesis.json \
--max-transaction-time=60 \
--http-validate-host=false \
--http-max-response-time-ms=500 \
--plugin eosio::producer_plugin \
--plugin eosio::producer_api_plugin \
--plugin eosio::chain_api_plugin \
Expand Down
Loading

0 comments on commit ee10568

Please sign in to comment.