From bd46b88926ef7f8d77b6d4775fb4caac998b127b Mon Sep 17 00:00:00 2001 From: vector Date: Fri, 17 Nov 2023 01:29:35 +0800 Subject: [PATCH] test: add unit test for isStdTx function --- packages/amino/src/stdtx.spec.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/amino/src/stdtx.spec.ts b/packages/amino/src/stdtx.spec.ts index 4f194e894b..b1af946ff4 100644 --- a/packages/amino/src/stdtx.spec.ts +++ b/packages/amino/src/stdtx.spec.ts @@ -2,7 +2,7 @@ import { coins } from "./coins"; import { StdSignature } from "./signature"; import { makeSignDoc, StdFee } from "./signdoc"; -import { makeStdTx } from "./stdtx"; +import { isStdTx, makeStdTx, StdTx } from "./stdtx"; describe("makeStdTx", () => { it("can make an StdTx from a SignDoc and one signature", () => { @@ -50,3 +50,29 @@ describe("makeStdTx", () => { }); }); }); + +describe("isStdTx", () => { + const validTx: StdTx = { + memo: "memoe", + msg: [{ type: "test", value: "Test Value" }], + fee: { amount: [{ denom: "ATOM", amount: "10" }], gas: "100000" }, + signatures: [{ signature: "signature", pub_key: { type: "type", value: "value" } }], + }; + + it("should return true for a valid StdTx", () => { + expect(isStdTx(validTx)).toBeTruthy(); + }); + + it("should return false for an invalid StdTx with missing properties", () => { + const { msg, ...invalidTx } = validTx; + expect(isStdTx(invalidTx)).toBeFalsy(); + }); + + it("should return false for an invalid StdTx with incorrect types", () => { + const invalidTx = { + ...validTx, + msg: "Invalid Message", + }; + expect(isStdTx(invalidTx)).toBeFalsy(); + }); +});