Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Handle incorrect keys to loggy #1112

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/models/network/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default class NetworkController {
Loggy.spin(__filename, '_uploadSolidityLib', `upload-solidity-lib${libName}`, `Uploading ${libName} library`);
const libInstance = await this.project.setImplementation(libClass, libName);
this.networkFile.addSolidityLib(libName, libInstance);
Loggy.succeed(`upload-solidity-lob${libName}`, `${libName} library uploaded`);
Loggy.succeed(`upload-solidity-lib${libName}`, `${libName} library uploaded`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

}

// Contract model
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ useTestProjectFile();
doNotInstallStdlib();
ZWeb3.initialize(web3.currentProvider);
setArtifactDefaults();
Loggy.silent(true);
Loggy.silent(false);
Loggy.testing(true);

require('chai')
.use(require('chai-as-promised'))
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/project/ProxyAdminProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BaseProxyAdminProject extends BaseSimpleProject {
contract,
contractParams,
);
Loggy.spin(__filename, 'upgradeProxy', `action-proxy-${pAddress}`, `Upgrading instance at ${pAddress}`);
await this.proxyAdmin.upgradeProxy(pAddress, implementationAddress, contract, initMethodName, initArgs);
Loggy.succeed(`action-proxy-${pAddress}`, `Instance at ${pAddress} upgraded`);
return contract.at(pAddress);
Expand Down
3 changes: 2 additions & 1 deletion packages/lib/src/project/SimpleProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export default class SimpleProject extends BaseSimpleProject {
contract,
contractParams,
);
Loggy.spin(__filename, 'upgradeProxy', `action-proxy-${pAddress}`, `Upgrading instance at ${pAddress}`);
const proxy = Proxy.at(pAddress, this.txParams);
await proxy.upgradeTo(implementationAddress, initCallData);
Loggy.succeed(`action-proxy-${implementationAddress}`, `Instance at ${pAddress} upgraded`);
Loggy.succeed(`action-proxy-${pAddress}`, `Instance at ${pAddress} upgraded`);
return contract.at(proxyAddress);
}

Expand Down
33 changes: 21 additions & 12 deletions packages/lib/src/utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Loggy: { [key: string]: any } = {
logs: {},
isSilent: true,
isVerbose: false,
isTesting: false,

silent(value: boolean): void {
this.isSilent = value;
Expand All @@ -54,6 +55,10 @@ export const Loggy: { [key: string]: any } = {
this.isVerbose = value;
},

testing(value: boolean): void {
this.isTesting = value;
},

add(
file: string,
fnName: string,
Expand Down Expand Up @@ -113,18 +118,22 @@ export const Loggy: { [key: string]: any } = {
},

_log(reference: string): void {
if (this.isSilent) return;
const { file, fnName, text, spinnerAction, logLevel, logType } = this.logs[reference];
const color = this._getColorFor(logType);
if (this.isVerbose) {
const location = `${path.basename(file)}#${fnName}`;
const message = `[${new Date().toISOString()}@${location}] <${this._actionToText(spinnerAction)}> ${text}`;
const coloredMessage = color ? chalk.keyword(color)(message) : message;
console.error(coloredMessage);
} else if (logLevel === LogLevel.Normal) {
const options = color ? { text, status: spinnerAction, color } : { text, status: spinnerAction };

!spinners.pick(reference) ? spinners.add(reference, options) : spinners.update(reference, options);
try {
if (this.isSilent) return;
const { file, fnName, text, spinnerAction, logLevel, logType } = this.logs[reference];
const color = this._getColorFor(logType);
if (this.isVerbose || this.isTesting) {
const location = `${path.basename(file)}#${fnName}`;
const message = `[${new Date().toISOString()}@${location}] <${this._actionToText(spinnerAction)}> ${text}`;
const coloredMessage = color ? chalk.keyword(color)(message) : message;
if (!this.isTesting) console.error(coloredMessage);
} else if (logLevel === LogLevel.Normal) {
const options = color ? { text, status: spinnerAction, color } : { text, status: spinnerAction };
!spinners.pick(reference) ? spinners.add(reference, options) : spinners.update(reference, options);
}
} catch (err) {
if (this.isTesting) throw new Error(`Error logging ${reference}: ${err}`);
else console.error(`Error logging ${reference}: ${err}`);
}
},

Expand Down
3 changes: 2 additions & 1 deletion packages/lib/test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Contracts from '../src/artifacts/Contracts';
import { helpers } from '../src/test';
import { Loggy } from '../src/utils/Logger';

Loggy.silent(true);
Loggy.silent(false);
Loggy.testing(true);
ZWeb3.initialize(web3.currentProvider);
setArtifactDefaults();

Expand Down
25 changes: 16 additions & 9 deletions packages/lib/test/src/utils/Logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import {
LogType,
} from '../../../src/utils/Logger';

describe('Loggger', function() {
afterEach('restore logger', function() {
Loggy.silent(true);
describe('Logger', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

beforeEach(function () {
Loggy.testing(false);
});

afterEach('restore logger', function() {
Loggy.testing(true);
Loggy.silent(false);
Loggy.verbose(false);
Loggy.logs = {};
sinon.restore();
});

describe('default attributes', function() {
it('is silent and non-verbose by default', function() {
Loggy.isSilent.should.be.true;
Loggy.isVerbose.should.be.false;
});

it(`has a 'logs' object initialized`, function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems to be failing because Loggy.logs is being filled by some other test. I believe it's not even necessary to have it, as it's only testing a variable assignment rather than a behavior.

Loggy.logs.should.be.an('object').that.is.empty;
});
Expand All @@ -41,7 +41,14 @@ describe('Loggger', function() {
describe('#verbose', function() {
it('changes isVerbose property value', function() {
Loggy.verbose(true);
Loggy.isSilent.should.be.true;
Loggy.isVerbose.should.be.true;
});
});

describe('#testing', function() {
it('changes isTesting property value', function() {
Loggy.testing(true);
Loggy.isTesting.should.be.true;
});
});

Expand Down