mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Merge pull request #42 from confio/normalize-attribute-value
Normalize unset attribute value to empty string
This commit is contained in:
commit
82447e8afe
@ -8,9 +8,14 @@ describe("logs", () => {
|
||||
expect(attr).toEqual({ key: "a", value: "b" });
|
||||
});
|
||||
|
||||
it("works for unset value", () => {
|
||||
it("works for empty value", () => {
|
||||
const attr = parseAttribute({ key: "foobar", value: "" });
|
||||
expect(attr).toEqual({ key: "foobar", value: "" });
|
||||
});
|
||||
|
||||
it("normalized unset value to empty string", () => {
|
||||
const attr = parseAttribute({ key: "amount" });
|
||||
expect(attr).toEqual({ key: "amount", value: undefined });
|
||||
expect(attr).toEqual({ key: "amount", value: "" });
|
||||
});
|
||||
});
|
||||
|
||||
@ -68,7 +73,7 @@ describe("logs", () => {
|
||||
},
|
||||
{
|
||||
key: "amount",
|
||||
value: undefined,
|
||||
value: "",
|
||||
},
|
||||
],
|
||||
} as const;
|
||||
|
@ -3,7 +3,7 @@ import { isNonNullObject } from "@iov/encoding";
|
||||
|
||||
export interface Attribute {
|
||||
readonly key: string;
|
||||
readonly value: string | undefined;
|
||||
readonly value: string;
|
||||
}
|
||||
|
||||
export interface Event {
|
||||
@ -27,7 +27,7 @@ export function parseAttribute(input: unknown): Attribute {
|
||||
|
||||
return {
|
||||
key: key,
|
||||
value: value,
|
||||
value: value || "",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ describe("RestClient", () => {
|
||||
.find(event => event.type === "message")
|
||||
?.attributes.find(attr => attr.key === "contract_address");
|
||||
if (!contractAddressAttr) throw new Error("Could not find contract_address attribute");
|
||||
contractAddress = contractAddressAttr.value || "";
|
||||
contractAddress = contractAddressAttr.value;
|
||||
|
||||
const balance = (await client.authAccounts(contractAddress)).result.value.coins;
|
||||
expect(balance).toEqual(transferAmount);
|
||||
|
2
packages/sdk/types/logs.d.ts
vendored
2
packages/sdk/types/logs.d.ts
vendored
@ -1,6 +1,6 @@
|
||||
export interface Attribute {
|
||||
readonly key: string;
|
||||
readonly value: string | undefined;
|
||||
readonly value: string;
|
||||
}
|
||||
export interface Event {
|
||||
readonly type: "message" | "transfer";
|
||||
|
Loading…
x
Reference in New Issue
Block a user