postchain-client
Version:
Client library for accessing a Postchain node through REST.
60 lines • 3.21 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 { checkExistingGTXSignatures, checkGTXSignatures, getDigestToSign, sign, } from "../../../src/gtx/gtx";
import { signers, sigProv } from "../../common/signatures";
const blockchainRid = Buffer.from("DEADBEEF94");
describe("Check GTX Signature", () => {
function test(txHash, gtx) {
const checkResult = checkGTXSignatures(txHash, gtx);
expect(checkResult).toStrictEqual(true);
}
function tx(calls, signers, signaturesCount) {
return __awaiter(this, void 0, void 0, function* () {
const tx = { blockchainRid, operations: calls, signers };
for (let i = 0; i < signaturesCount; i++) {
const signatureProvider = sigProv(i);
yield sign(tx, signatureProvider, 1);
}
if (!tx.signatures)
tx.signatures = [];
return tx;
});
}
it("checkGTXSignatures without gtx signatures returns false", () => __awaiter(void 0, void 0, void 0, function* () {
const aTx = yield tx([], [], 0);
const txHash = getDigestToSign(aTx, 1);
const checkResult = checkGTXSignatures(txHash, aTx);
expect(checkResult).toStrictEqual(false);
}));
it("single call with one of two signatures works", () => __awaiter(void 0, void 0, void 0, function* () {
const aTx = yield tx([{ opName: "func1åäö", args: [] }], signers(2), 1);
const txHash = getDigestToSign(aTx, 1);
expect(checkExistingGTXSignatures(txHash, aTx)).toBe(true);
}));
it("single call with enough signatures works", () => __awaiter(void 0, void 0, void 0, function* () {
const aTx = yield tx([{ opName: "func1åääö", args: [] }], signers(1), 1);
const txHash = getDigestToSign(aTx, 1);
test(txHash, aTx);
}));
it("single call with enough multiple signatures work", () => __awaiter(void 0, void 0, void 0, function* () {
const aTx = yield tx([{ opName: "func1åääö", args: [] }], signers(2), 2);
const txHash = getDigestToSign(aTx, 1);
test(txHash, aTx);
}));
it("multiple calls with enough multiple signatures work", () => __awaiter(void 0, void 0, void 0, function* () {
const aTx = yield tx([
{ opName: "func1åääö", args: [] },
{ opName: "guess_the_function", args: ["John Doe", 2222] },
], signers(3), 3);
const txHash = getDigestToSign(aTx, 1);
test(txHash, aTx);
}));
});
//# sourceMappingURL=checkGTXSignature.test.js.map