postchain-client
Version:
Client library for accessing a Postchain node through REST.
59 lines • 4.75 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { ChainConfirmationLevel } from "../../src/blockchainClient/enums";
import { getAnchoringClientAndSystemChainRid, getSystemClient, getUrlsFromEndpoints, } from "../../src/blockchainClient/utils";
import { rawGtvToGtx } from "../../src/gtx/gtx";
import { decodeValue } from "../../src/gtx/serialization";
import { createIccfProofTx } from "../../src/ICCF/IccfProofTxMaterialBuilder";
import { composeProofTransactionObject } from "../../src/ICCF/utils";
import { MERKLE_HASH_VERSIONS } from "../../src/utils/constants";
import { mockBuffer, mockSignatureProvider, mockSignerKeyPair, mockSignerPubKey, unsignedTx, } from "../common/mocks";
import { createClientToChromiaNetwork, createCrosschainClientToChromiaNetwork, } from "../common/setups";
describe("createIccfProofTx", () => {
let sourceClient;
let systemClients;
let directoryClient;
let targetClient;
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
sourceClient = yield createClientToChromiaNetwork();
targetClient = yield createCrosschainClientToChromiaNetwork();
systemClients = yield getAnchoringClientAndSystemChainRid(sourceClient);
directoryClient = yield getSystemClient(getUrlsFromEndpoints(sourceClient.config.endpointPool), sourceClient.config.directoryChainRid);
}));
it("returns iccfTx for intra-network operation", () => __awaiter(void 0, void 0, void 0, function* () {
const transactionReceipt = yield sourceClient.signAndSendUniqueTransaction(unsignedTx, mockSignerKeyPair, true, undefined, ChainConfirmationLevel.SystemAnchoring);
const transactionInfo = yield sourceClient.getTransactionInfo(transactionReceipt.transactionRid);
const iccfProof = yield createIccfProofTx(directoryClient, transactionReceipt.transactionRid, transactionInfo.txHash, [mockSignerPubKey], sourceClient.config.blockchainRid, targetClient.config.blockchainRid, [mockSignerPubKey], true, MERKLE_HASH_VERSIONS.ONE);
const sourceConfirmationProof = yield sourceClient.getConfirmationProof(transactionReceipt.transactionRid);
const anchoringProof = yield systemClients.anchoringClient.getConfirmationProof(transactionReceipt.clusterAnchoredTx.txRid);
const iccfTx = composeProofTransactionObject(sourceClient.config.blockchainRid, transactionInfo.txHash, sourceConfirmationProof, [mockSignerPubKey], transactionReceipt.clusterAnchoredTx, anchoringProof);
expect(iccfProof).toEqual({
iccfTx,
verifiedTx: null,
});
}));
it("returns iccfTx for intra-network operation, mismatch", () => __awaiter(void 0, void 0, void 0, function* () {
const transactionReceipt = yield sourceClient.signAndSendUniqueTransaction(unsignedTx, mockSignatureProvider, true, undefined, ChainConfirmationLevel.SystemAnchoring);
const transactionInfo = yield sourceClient.getTransactionInfo(transactionReceipt.transactionRid);
const txToProveHashMismatch = mockBuffer;
const iccfProof = yield createIccfProofTx(directoryClient, transactionReceipt.transactionRid, txToProveHashMismatch, [mockSignerPubKey], sourceClient.config.blockchainRid, targetClient.config.blockchainRid, [mockSignerPubKey], true, MERKLE_HASH_VERSIONS.ONE);
const rawTx = yield sourceClient.getTransaction(transactionReceipt.transactionRid);
const txGtv = decodeValue(rawTx);
const verifiedTx = rawGtvToGtx(txGtv);
const sourceConfirmationProof = yield sourceClient.getConfirmationProof(transactionReceipt.transactionRid);
const anchoringProof = yield systemClients.anchoringClient.getConfirmationProof(transactionReceipt.clusterAnchoredTx.txRid);
const iccfTx = composeProofTransactionObject(sourceClient.config.blockchainRid, transactionInfo.txHash, sourceConfirmationProof, [mockSignerPubKey], transactionReceipt.clusterAnchoredTx, anchoringProof);
expect(iccfProof).toEqual({
iccfTx: iccfTx,
verifiedTx: verifiedTx,
});
}));
});
//# sourceMappingURL=createIccfProofTx.test.js.map