Merge pull request #42 from confio/normalize-attribute-value

Normalize unset attribute value to empty string
This commit is contained in:
Ethan Frey 2020-02-04 19:22:05 +01:00 committed by GitHub
commit 82447e8afe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

View File

@ -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;

View File

@ -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 || "",
};
}

View File

@ -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);

View File

@ -1,6 +1,6 @@
export interface Attribute {
readonly key: string;
readonly value: string | undefined;
readonly value: string;
}
export interface Event {
readonly type: "message" | "transfer";