Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bungee-hermes): merge and process views tests #3704

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ export class PluginBungeeHermes implements ICactusPlugin, IPluginWebService {
)
) {
this.log.info("Some signature was deemed invalid");
throw Error(
"At least one of they views does not include a valid signature",
);
throw Error("The provided view does not include a valid signature");
}
const prevVersionMetadata = {
viewId: view.getKey(),
Expand Down Expand Up @@ -316,6 +314,7 @@ export class PluginBungeeHermes implements ICactusPlugin, IPluginWebService {
}

sign(msg: string): string {
this.logger.info(this.bungeeSigner.dataHash(msg));
return Buffer.from(this.bungeeSigner.sign(msg)).toString("hex");
}

Expand Down Expand Up @@ -439,6 +438,7 @@ export class PluginBungeeHermes implements ICactusPlugin, IPluginWebService {
view: string,
pubKey: string,
): boolean {
this.logger.info(this.bungeeSigner.dataHash(view));
const sourceSignature = new Uint8Array(Buffer.from(signature, "hex"));
const sourcePubkey = new Uint8Array(Buffer.from(pubKey, "hex"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@hyperledger/cactus-common";
import "jest-extended";
import LockAssetContractJson from "../solidity/lock-asset-contract/LockAsset.json";
import { stringify as safeStableStringify } from "safe-stable-stringify";

import { PluginRegistry } from "@hyperledger/cactus-core";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
Expand Down Expand Up @@ -264,11 +265,11 @@ test("tests bungee api using different strategies", async () => {
const stateProofs = viewFabric1.view
?.getSnapshot()
.getStateBins()
.map((x) => JSON.stringify(x.getStateProof()));
.map((x) => safeStableStringify(x.getStateProof()));
const transactionProofs: string[] = [];
viewFabric1.view
?.getAllTransactions()
.forEach((t) => transactionProofs.push(JSON.stringify(t.getProof())));
.forEach((t) => transactionProofs.push(safeStableStringify(t.getProof())));
const verifyStateRoot = await bungeeApi.verifyMerkleRoot({
input: stateProofs?.reverse(), //check integrity, order should not matter
root: proof?.statesMerkleRoot,
Expand All @@ -294,11 +295,11 @@ test("tests bungee api using different strategies", async () => {
const stateProofs1 = viewEth1.view
?.getSnapshot()
.getStateBins()
.map((x) => JSON.stringify(x.getStateProof()));
.map((x) => safeStableStringify(x.getStateProof()));
const transactionProofs1: string[] = [];
viewEth1.view
?.getAllTransactions()
.forEach((t) => transactionProofs1.push(JSON.stringify(t.getProof())));
.forEach((t) => transactionProofs1.push(safeStableStringify(t.getProof())));
const verifyStateRoot1 = await bungeeApi.verifyMerkleRoot({
input: stateProofs1?.reverse(), //check integrity, order should not matter
root: proof1?.statesMerkleRoot,
Expand Down Expand Up @@ -577,7 +578,7 @@ async function setupFabricTestLedger(): Promise<string> {
expect(createResponse.status).toBeLessThan(300);

log.info(
`BassicAssetTransfer.Create(): ${JSON.stringify(createResponse.data)}`,
`BassicAssetTransfer.Create(): ${safeStableStringify(createResponse.data)}`,
);
return "Fabric Network setup successful";
}
Expand Down Expand Up @@ -614,7 +615,7 @@ async function setupBesuTestLedger(): Promise<string> {

besuKeychainPlugin.set(
besuContractName,
JSON.stringify(LockAssetContractJson),
safeStableStringify(LockAssetContractJson),
);

const pluginRegistry = new PluginRegistry({
Expand Down Expand Up @@ -801,7 +802,7 @@ async function setupEthereumTestLedger(): Promise<string> {
});
keychainPlugin.set(
LockAssetContractJson.contractName,
JSON.stringify(LockAssetContractJson),
safeStableStringify(LockAssetContractJson),
);
const connector = new PluginLedgerConnectorEthereum({
instanceId: uuidv4(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@hyperledger/cactus-common";
import "jest-extended";
import LockAssetContractJson from "../solidity/lock-asset-contract/LockAsset.json";
import { stringify as safeStableStringify } from "safe-stable-stringify";

import { PluginRegistry } from "@hyperledger/cactus-core";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
Expand Down Expand Up @@ -120,7 +121,7 @@ beforeEach(async () => {
});
keychainPlugin.set(
LockAssetContractJson.contractName,
JSON.stringify(LockAssetContractJson),
safeStableStringify(LockAssetContractJson),
);

const pluginRegistry = new PluginRegistry({
Expand Down Expand Up @@ -365,15 +366,15 @@ test.each([{ apiPath: true }, { apiPath: false }])(

const mergeViewsNoPolicyReq = await bungeeApi.mergeViewsV1({
serializedViews: [
JSON.stringify({
view: JSON.stringify(view.view as View),
safeStableStringify({
view: safeStableStringify(view.view as View),
signature: view.signature,
}),
})!,
// eslint-disable-next-line prettier/prettier
JSON.stringify({
view: JSON.stringify(view2.view as View),
safeStableStringify({
view: safeStableStringify(view2.view as View),
signature: view2.signature,
}),
})!,
],
mergePolicy: MergePolicyOpts.NONE,
});
Expand All @@ -398,7 +399,7 @@ test.each([{ apiPath: true }, { apiPath: false }])(
const transactionReceipts: string[] = [];

mergeViewsNoPolicy.integratedView.getAllTransactions().forEach((t) => {
transactionReceipts.push(JSON.stringify(t.getProof()));
transactionReceipts.push(safeStableStringify(t.getProof()));
});
expect(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
Containers,
} from "@hyperledger/cactus-test-tooling";
import { Configuration, Constants } from "@hyperledger/cactus-core-api";
import { stringify as safeStableStringify } from "safe-stable-stringify";

import {
Web3SigningCredentialType,
PluginLedgerConnectorBesu,
Expand Down Expand Up @@ -122,7 +124,7 @@ beforeEach(async () => {
});
keychainPlugin.set(
LockAssetContractJson.contractName,
JSON.stringify(LockAssetContractJson),
safeStableStringify(LockAssetContractJson),
);

const pluginRegistry = new PluginRegistry({
Expand Down Expand Up @@ -352,10 +354,10 @@ test.each([{ apiPath: true }, { apiPath: false }])(
const bungeeApi = new BungeeApi(config);

const processed = await bungeeApi.processViewV1({
serializedView: JSON.stringify({
view: JSON.stringify(view.view as View),
serializedView: safeStableStringify({
view: safeStableStringify(view.view as View),
signature: view.signature,
}),
})!,
policyId: PrivacyPolicyOpts.PruneState,
policyArguments: [BESU_ASSET_ID],
});
Expand All @@ -364,10 +366,10 @@ test.each([{ apiPath: true }, { apiPath: false }])(
expect(processed.data.view).toBeTruthy();
expect(processed.data.signature).toBeTruthy();

const processedView = deserializeView(JSON.stringify(processed.data));
const processedView = deserializeView(safeStableStringify(processed.data));

//check view deserializer
expect(JSON.stringify(processedView)).toEqual(processed.data.view);
expect(safeStableStringify(processedView)).toEqual(processed.data.view);

expect(processedView.getPolicy()).toBeTruthy();
expect(processedView.getOldVersionsMetadata().length).toBe(1);
Expand Down
Loading