Skip to content

Commit

Permalink
style: remediate linter errors in examples and test-tooling
Browse files Browse the repository at this point in the history
Some of the fixes were updated by Peter after Alec's internship has
come to an end before he could finish the requested changes.

Signed-off-by: Alec Phong <alecphong@gmail.com>
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>

Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
alec-p-hong and petermetz committed Dec 1, 2022
1 parent c668c41 commit 45fdb80
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,4 @@ export class EmissionsChaincode {
}
}

export const contracts: any[] = [EmissionsChaincode];
export const contracts: unknown[] = [EmissionsChaincode];
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class EmissionsRecordContract {
energyUseUom: string,
url: string,
md5: string,
) {
): Promise<Uint8Array> {
// get emissions factors from eGRID database; convert energy use to emissions factor UOM; calculate energy use
const lookup = await this.utilityLookupState.getUtilityLookupItem(
utilityId,
Expand Down Expand Up @@ -135,15 +135,19 @@ export class EmissionsRecordContract {
);
return Buffer.from(JSON.stringify(records));
}
async importUtilityFactor(factorI: UtilityEmissionsFactorInterface) {
async importUtilityFactor(
factorI: UtilityEmissionsFactorInterface,
): Promise<Uint8Array> {
const factor = new UtilityEmissionsFactor(factorI);
await this.utilityEmissionsFactorState.addUtilityEmissionsFactor(
factor,
factorI.uuid,
);
return factor.toBuffer();
}
async updateUtilityFactor(factorI: UtilityEmissionsFactorInterface) {
async updateUtilityFactor(
factorI: UtilityEmissionsFactorInterface,
): Promise<Uint8Array> {
const factor = new UtilityEmissionsFactor(factorI);
await this.utilityEmissionsFactorState.updateUtilityEmissionsFactor(
factor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
safeStringifyException,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
Expand Down Expand Up @@ -55,7 +56,7 @@ export class GetAllowanceEndpoint implements IWebServiceEndpoint {
};
}

public get oasPath(): { post: any } {
public get oasPath(): typeof OAS.paths["/api/v1/plugins/@hyperledger/cactus-example-carbon-accounting-backend/dao-token/get-allowance"] {
return OAS.paths[
"/api/v1/plugins/@hyperledger/cactus-example-carbon-accounting-backend/dao-token/get-allowance"
];
Expand All @@ -81,10 +82,10 @@ export class GetAllowanceEndpoint implements IWebServiceEndpoint {
const resBody = await Promise.resolve("dummy-response-fixme");
res.status(200);
res.json(resBody);
} catch (ex) {
} catch (ex: unknown) {
this.log.debug(`${tag} Failed to serve request:`, ex);
res.status(500);
res.json({ error: ex.stack });
res.json({ error: safeStringifyException(ex) });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Stream } from "stream";
import { EventEmitter } from "events";
import axios from "axios";
import { v4 as uuidv4 } from "uuid";
Expand Down Expand Up @@ -274,20 +275,24 @@ export class QuorumTestLedger implements ITestLedger {
try {
const res = await axios.get(httpUrl);
reachable = res.status > 199 && res.status < 300;
} catch (ex) {
reachable = false;
if (Date.now() >= startedAt + timeoutMs) {
throw new Error(`${fnTag} timed out (${timeoutMs}ms) -> ${ex.stack}`);
} catch (ex: unknown) {
if (ex instanceof Error) {
reachable = false;
if (Date.now() >= startedAt + timeoutMs) {
throw new Error(
`${fnTag} timed out (${timeoutMs}ms) -> ${ex.stack}`,
);
}
}
}
await new Promise((resolve2) => setTimeout(resolve2, 100));
} while (!reachable);
}

public stop(): Promise<any> {
public stop(): Promise<unknown> {
return new Promise((resolve, reject) => {
if (this.container) {
this.container.stop({}, (err: any, result: any) => {
this.container.stop({}, (err: unknown, result: unknown) => {
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -377,16 +382,16 @@ export class QuorumTestLedger implements ITestLedger {
}
}

private pullContainerImage(containerNameAndTag: string): Promise<any[]> {
private pullContainerImage(containerNameAndTag: string): Promise<unknown[]> {
return new Promise((resolve, reject) => {
const docker = new Docker();
docker.pull(containerNameAndTag, (pullError: any, stream: any) => {
docker.pull(containerNameAndTag, (pullError: unknown, stream: Stream) => {
if (pullError) {
reject(pullError);
} else {
docker.modem.followProgress(
stream,
(progressError: any, output: any[]) => {
(progressError: unknown, output: unknown[]) => {
if (progressError) {
reject(progressError);
} else {
Expand Down

0 comments on commit 45fdb80

Please sign in to comment.