Skip to content

Commit

Permalink
refactor(SATP-Hermes): fix cspell and lint
Browse files Browse the repository at this point in the history
Signed-off-by: André Augusto <[email protected]>
  • Loading branch information
AndreAugusto11 authored and RafaelAPB committed Mar 5, 2024
1 parent 4ed1f66 commit 7462170
Show file tree
Hide file tree
Showing 26 changed files with 242 additions and 265 deletions.
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"celo",
"cids",
"clsx",
"connectrpc",
"commenceack",
"configtx",
"Corda",
Expand Down Expand Up @@ -114,6 +115,7 @@
"myroot",
"mysecretpassword",
"myvolume",
"nanos",
"Nerc",
"NETWORKSCOPEALLFORTX",
"NETWORKSCOPEANYFORTX",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
} from "../besu-helper";
import AssetReferenceContractJson from "../../../../solidity/asset-reference-contract/AssetReferenceContract.json";
import CBDCcontractJson from "../../../../solidity/cbdc-erc-20/CBDCcontract.json";
import { getEthAddress, getPrvKey, assertEqual, assertStringContains } from "./common";
import {
getEthAddress,
getPrvKey,
assertEqual,
assertStringContains,
} from "./common";

const BESU_CONTRACT_CBDC_ERC20_NAME = CBDCcontractJson.contractName;
const BESU_CONTRACT_ASSET_REF_NAME = AssetReferenceContractJson.contractName;
Expand Down Expand Up @@ -156,7 +161,8 @@ Then(
getPrvKey(user),
assetRefID,
).catch((err) => {
assertStringContains(err.response.data.error,
assertStringContains(
err.response.data.error,
`Transaction has been reverted by the EVM`,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ Then(
Then(
"{string} fails to initiate bridge back of {int} CBDC referenced by id {string}",
{ timeout: 60 * 1000 },
async function (
user: string,
amount: number,
assetRefID: string,
) {
async function (user: string, amount: number, assetRefID: string) {
const address = getEthAddress(user);
const fabricID = getFabricId(user);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { When, Then } from "cucumber";
import axios from "axios";
import CryptoMaterial from "../../../../crypto-material/crypto-material.json";
import { getUserFromPseudonim, getFabricId, getEthAddress, assertEqual, assertStringContains } from "./common";
import {
getUserFromPseudonim,
getFabricId,
getEthAddress,
assertEqual,
assertStringContains,
} from "./common";

const MAX_RETRIES = 5;
const MAX_TIMEOUT = 5000;
Expand Down Expand Up @@ -87,7 +93,7 @@ When(
recipientLedgerAssetID: "FABRIC_ASSET_ID",
},
);

assertEqual(response.status, 200);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ export function getPrvKey(user: string): string {
}
}

export function assertEqual(
value_1: unknown,
value_2: unknown,
) {
export function assertEqual(value_1: unknown, value_2: unknown) {
if (value_1 !== value_2) {
throw Error(`Expected ${value_1} to be equal to ${value_2}`);
}
Expand All @@ -66,7 +63,7 @@ export function assertStringContains(
subString: string,
): void {
if (!mainString.includes(subString)) {
throw new Error(`String "${mainString}" does not contain "${subString}"`);
throw new Error(`String "${mainString}" does not contain "${subString}"`);
}
}

Expand All @@ -76,4 +73,4 @@ export function assertNonNullish<TValue>(
if (value === null || value === undefined) {
throw Error(`${value} was expected to be non-null`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getUserFromPseudonim,
assertEqual,
assertNonNullish,
assertStringContains
assertStringContains,
} from "./common";
import {
deleteFabricAssetReference,
Expand Down Expand Up @@ -94,7 +94,7 @@ When(

When(
"bob refunds {int} CBDC to {string} in the source chain",
{ timeout: 10 * 1000 },
{ timeout: 10 * 1000 },
async function (amount: number, userTo: string) {
const finalUserFabricID = getFabricId(userTo);
const finalUserEthAddress = getEthAddress(userTo);
Expand Down Expand Up @@ -123,14 +123,17 @@ Then(
},
)
.catch((err) => {
assertStringContains(err.response.data.error, `client is not authorized to perform the operation`);
assertStringContains(
err.response.data.error,
`client is not authorized to perform the operation`,
);
});
},
);

Then(
"{string} fails to transfer {int} CBDC to {string}",
{ timeout: 10 * 1000 },
{ timeout: 10 * 1000 },
async function (userFrom: string, amount: number, userTo: string) {
const recipient = getFabricId(userTo);

Expand All @@ -157,32 +160,32 @@ Then(

Then(
"{string} has {int} CBDC available in the source chain",
{ timeout: 10 * 1000 },
{ timeout: 10 * 1000 },
async function (user: string, amount: number) {
assertEqual((await getFabricBalance(getFabricId(user))), amount)
assertEqual(await getFabricBalance(getFabricId(user)), amount);
},
);

Then(
"the asset reference chaincode has an asset reference with id {string}",
{ timeout: 10 * 1000 },
{ timeout: 10 * 1000 },
async function (assetRefID: string) {
assertNonNullish((await readFabricAssetReference(assetRefID)));
assertNonNullish(await readFabricAssetReference(assetRefID));
},
);

Then(
"the asset reference with id {string} is locked in the source chain",
{ timeout: 10 * 1000 },
{ timeout: 10 * 1000 },
async function (assetRefID: string) {
assertEqual((await readFabricAssetReference(assetRefID)).isLocked, true)
assertEqual((await readFabricAssetReference(assetRefID)).isLocked, true);
},
);

Then(
"the asset reference chaincode has no asset reference with id {string}",
{ timeout: 10 * 1000 },
{ timeout: 10 * 1000 },
async function (assetRefID: string) {
assertEqual(await fabricAssetReferenceExists(assetRefID), "false")
assertEqual(await fabricAssetReferenceExists(assetRefID), "false");
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,33 @@ export class PluginBUNGEEBenchmark {
private level: LogLevelDesc;
private logger: Logger;
public pluginRegistry: PluginRegistry;
private tIgetAllAssetsKey: number;
private tFgetAllAssetsKey: number;
private tIgetAllTxByKey: number;
private tFgetAllTxByKey: number;
private tIfabricGetTxReceiptByTxIDV1: number;
private tFfabricGetTxReceiptByTxIDV1: number;
private tIgenerateLedgerStates: number;
private tFgenerateLedgerStates: number;
private tIgenerateSnapshot: number;
private tFgenerateSnapshot: number;
private tIgenerateView: number;
private tFgenerateView: number;
private tsStartGetAllAssetsKey: number;
private tsEndGetAllAssetsKey: number;
private tsStartGetAllTxByKey: number;
private tsEndGetAllTxByKey: number;
private tsStartfabricGetTxReceiptByTxIDV1: number;
private tsEndfabricGetTxReceiptByTxIDV1: number;
private tsStartgenerateLedgerStates: number;
private tsEndgenerateLedgerStates: number;
private tsStartgenerateSnapshot: number;
private tsEndgenerateSnapshot: number;
private tsStartGenerateView: number;
private tsEndGenerateView: number;
private fileNameDate = Date.now();

constructor(public readonly options: IPluginBUNGEEOptions) {
this.tIgetAllAssetsKey = 0;
this.tFgetAllAssetsKey = 0;
this.tIgetAllTxByKey = 0;
this.tFgetAllTxByKey = 0;
this.tIfabricGetTxReceiptByTxIDV1 = 0;
this.tFfabricGetTxReceiptByTxIDV1 = 0;
this.tIgenerateLedgerStates = 0;
this.tFgenerateLedgerStates = 0;
this.tIgenerateSnapshot = 0;
this.tFgenerateSnapshot = 0;
this.tIgenerateView = 0;
this.tFgenerateView = 0;
this.tsStartGetAllAssetsKey = 0;
this.tsEndGetAllAssetsKey = 0;
this.tsStartGetAllTxByKey = 0;
this.tsEndGetAllTxByKey = 0;
this.tsStartfabricGetTxReceiptByTxIDV1 = 0;
this.tsEndfabricGetTxReceiptByTxIDV1 = 0;
this.tsStartgenerateLedgerStates = 0;
this.tsEndgenerateLedgerStates = 0;
this.tsStartgenerateSnapshot = 0;
this.tsEndgenerateSnapshot = 0;
this.tsStartGenerateView = 0;
this.tsEndGenerateView = 0;

this.className = "pluginBUNGEE";
this.level = options.logLevel || "INFO";
Expand Down Expand Up @@ -187,7 +187,7 @@ export class PluginBUNGEEBenchmark {
* @abstract Create ledger state. Get all keys, iterate every key and get the respective transactions. For each transaction get the receipt
* */
public async generateLedgerStates(): Promise<string> {
this.tIgenerateLedgerStates = performance.now();
this.tsStartgenerateLedgerStates = performance.now();
this.logger.info(`Generating ledger snapshot`);

const assetsKey = await this.getAllAssetsKey();
Expand Down Expand Up @@ -254,7 +254,7 @@ export class PluginBUNGEEBenchmark {
this.tF = asset9.getFinalTime();
}

this.tFgenerateLedgerStates = performance.now();
this.tsEndgenerateLedgerStates = performance.now();

return "";
}
Expand All @@ -264,10 +264,10 @@ export class PluginBUNGEEBenchmark {
* @abstract Returns Snapshot
* */
public generateSnapshot(): Snapshot {
this.tIgenerateSnapshot = performance.now();
this.tsStartgenerateSnapshot = performance.now();
const snapShotId = uuidv4();
const snapshot = new Snapshot(snapShotId, this.participant, this.states);
this.tFgenerateSnapshot = performance.now();
this.tsEndgenerateSnapshot = performance.now();
return snapshot;
}

Expand All @@ -278,7 +278,7 @@ export class PluginBUNGEEBenchmark {
* @param snapshot - Ledger Snapshot
* */
public generateView(snapshot: Snapshot): string {
this.tIgenerateView = performance.now();
this.tsStartGenerateView = performance.now();
const crypto = require("crypto");

this.logger.warn(this.pubKeyBungee);
Expand All @@ -302,7 +302,7 @@ export class PluginBUNGEEBenchmark {
JSON.stringify(signedView, null, 2),
);

this.tFgenerateView = performance.now();
this.tsEndGenerateView = performance.now();
return JSON.stringify(signedView);
}

Expand All @@ -313,7 +313,7 @@ export class PluginBUNGEEBenchmark {
* @param transactionId - Transaction id to return the receipt
* */
async fabricGetTxReceiptByTxIDV1(transactionId: string): Promise<string> {
this.tIfabricGetTxReceiptByTxIDV1 = performance.now();
this.tsStartfabricGetTxReceiptByTxIDV1 = performance.now();

const receiptLockRes = await this.fabricApi?.getTransactionReceiptByTxIDV1({
signingCredential: this.fabricSigningCredential,
Expand All @@ -324,7 +324,7 @@ export class PluginBUNGEEBenchmark {
params: [this.fabricChannelName, transactionId],
} as FabricRunTransactionRequest);

this.tFfabricGetTxReceiptByTxIDV1 = performance.now();
this.tsEndfabricGetTxReceiptByTxIDV1 = performance.now();
return JSON.stringify(receiptLockRes?.data);
}

Expand All @@ -333,7 +333,7 @@ export class PluginBUNGEEBenchmark {
* @abstract Returns all assets key found in the world state.
* */
async getAllAssetsKey(): Promise<string> {
this.tIgetAllAssetsKey = performance.now();
this.tsStartGetAllAssetsKey = performance.now();
const response = await this.fabricApi?.runTransactionV1({
signingCredential: this.fabricSigningCredential,
channelName: this.fabricChannelName,
Expand All @@ -344,7 +344,7 @@ export class PluginBUNGEEBenchmark {
} as FabricRunTransactionRequest);

if (response != undefined) {
this.tFgetAllAssetsKey = performance.now();
this.tsEndGetAllAssetsKey = performance.now();
return response.data.functionOutput;
}

Expand All @@ -358,7 +358,7 @@ export class PluginBUNGEEBenchmark {
* @param key - Key used to get correspondent transactions
* */
async getAllTxByKey(key: string): Promise<Transaction[]> {
this.tIgetAllTxByKey = performance.now();
this.tsStartGetAllTxByKey = performance.now();
const response = await this.fabricApi?.runTransactionV1({
signingCredential: this.fabricSigningCredential,
channelName: this.fabricChannelName,
Expand All @@ -369,7 +369,7 @@ export class PluginBUNGEEBenchmark {
} as FabricRunTransactionRequest);

if (response != undefined) {
this.tFgetAllTxByKey = performance.now();
this.tsEndGetAllTxByKey = performance.now();
return Utils.txsStringToTxs(response.data.functionOutput);
}

Expand Down Expand Up @@ -401,29 +401,29 @@ export class PluginBUNGEEBenchmark {

public generateBenchmarkReport(
numberOfTransactions: number,
tItotalTime: number,
tFtotalTime: number,
tItransactionsTime: number,
tFtransactionsTime: number,
tsStartTotalTime: number,
tsEndTotalTime: number,
tsStartTransactionsTime: number,
tsEndTransactionsTime: number,
): void {
const report = {
tIgetAllAssetsKey: this.tIgetAllAssetsKey,
tFgetAllAssetsKey: this.tFgetAllAssetsKey,
tIgetAllTxByKey: this.tIgetAllTxByKey,
tFgetAllTxByKey: this.tFgetAllTxByKey,
tIfabricGetTxReceiptByTxIDV1: this.tIfabricGetTxReceiptByTxIDV1,
tsStartGetAllAssetsKey: this.tsStartGetAllAssetsKey,
tsEndGetAllAssetsKey: this.tsEndGetAllAssetsKey,
tsStartGetAllTxByKey: this.tsStartGetAllTxByKey,
tsEndGetAllTxByKey: this.tsEndGetAllTxByKey,
tsStartfabricGetTxReceiptByTxIDV1: this.tsStartfabricGetTxReceiptByTxIDV1,
numberOfTransactions: numberOfTransactions,
tFfabricGetTxReceiptByTxIDV1: this.tFfabricGetTxReceiptByTxIDV1,
tIgenerateLedgerStates: this.tIgenerateLedgerStates,
tFgenerateLedgerStates: this.tFgenerateLedgerStates,
tIgenerateSnapshot: this.tIgenerateSnapshot,
tFgenerateSnapshot: this.tFgenerateSnapshot,
tIgenerateView: this.tIgenerateView,
tFgenerateView: this.tFgenerateView,
tItotalTime: tItotalTime,
tFtotalTime: tFtotalTime,
tItransactionsTime: tItransactionsTime,
tFtransactionsTime: tFtransactionsTime,
tsEndfabricGetTxReceiptByTxIDV1: this.tsEndfabricGetTxReceiptByTxIDV1,
tsStartgenerateLedgerStates: this.tsStartgenerateLedgerStates,
tsEndgenerateLedgerStates: this.tsEndgenerateLedgerStates,
tsStartgenerateSnapshot: this.tsStartgenerateSnapshot,
tsEndgenerateSnapshot: this.tsEndgenerateSnapshot,
tsStartGenerateView: this.tsStartGenerateView,
tsEndGenerateView: this.tsEndGenerateView,
tsStartTotalTime: tsStartTotalTime,
tsEndTotalTime: tsEndTotalTime,
tsStartTransactionsTime: tsStartTransactionsTime,
tsEndTransactionsTime: tsEndTransactionsTime,
};
const reportString = JSON.stringify(report, null, 2);
this.saveToFile(
Expand Down
Loading

0 comments on commit 7462170

Please sign in to comment.