From 0a1da22fb48675123e4d6b4d54063a03b5ffb0e4 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 13 Oct 2020 12:28:13 +0200 Subject: [PATCH] crypto: Add tests for convenience hash functions --- packages/crypto/src/keccak.spec.ts | 7 ++++++- packages/crypto/src/ripemd.spec.ts | 7 ++++++- packages/crypto/src/sha.spec.ts | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/crypto/src/keccak.spec.ts b/packages/crypto/src/keccak.spec.ts index ee1f20c7..5284063e 100644 --- a/packages/crypto/src/keccak.spec.ts +++ b/packages/crypto/src/keccak.spec.ts @@ -1,6 +1,6 @@ import { fromHex, toHex } from "@cosmjs/encoding"; -import { Keccak256 } from "./keccak"; +import { Keccak256, keccak256 } from "./keccak"; import keccakVectors from "./testdata/keccak.json"; describe("Keccak256", () => { @@ -25,4 +25,9 @@ describe("Keccak256", () => { expect(new Keccak256(fromHex(input)).digest()).toEqual(fromHex(output)); } }); + + it("exposes a convenience function", () => { + const { in: input, out: output } = keccakVectors.keccak256[0]; + expect(keccak256(fromHex(input))).toEqual(fromHex(output)); + }); }); diff --git a/packages/crypto/src/ripemd.spec.ts b/packages/crypto/src/ripemd.spec.ts index 234691c2..72fd2f8a 100644 --- a/packages/crypto/src/ripemd.spec.ts +++ b/packages/crypto/src/ripemd.spec.ts @@ -1,6 +1,6 @@ import { fromHex } from "@cosmjs/encoding"; -import { Ripemd160 } from "./ripemd"; +import { Ripemd160, ripemd160 } from "./ripemd"; import ripemdVectors from "./testdata/ripemd.json"; describe("Ripemd160", () => { @@ -25,4 +25,9 @@ describe("Ripemd160", () => { expect(new Ripemd160(fromHex(input)).digest()).toEqual(fromHex(output)); } }); + + it("exposes a convenience function", () => { + const { in: input, out: output } = ripemdVectors.ripemd160[0]; + expect(ripemd160(fromHex(input))).toEqual(fromHex(output)); + }); }); diff --git a/packages/crypto/src/sha.spec.ts b/packages/crypto/src/sha.spec.ts index 3549164b..311c2597 100644 --- a/packages/crypto/src/sha.spec.ts +++ b/packages/crypto/src/sha.spec.ts @@ -1,6 +1,6 @@ import { fromHex, toHex } from "@cosmjs/encoding"; -import { Sha256 } from "./sha"; +import { Sha256, sha256 } from "./sha"; import shaVectors from "./testdata/sha.json"; describe("Sha256", () => { @@ -25,4 +25,9 @@ describe("Sha256", () => { expect(new Sha256(fromHex(input)).digest()).toEqual(fromHex(output)); } }); + + it("exposes a convenience function", () => { + const { in: input, out: output } = shaVectors.sha256[0]; + expect(sha256(fromHex(input))).toEqual(fromHex(output)); + }); });