Organize cosmWasmCodec test code

This commit is contained in:
Simon Warta 2020-02-10 16:25:59 +01:00
parent c0dbdd0a14
commit a763b8a2ea

View File

@ -28,37 +28,41 @@ describe("cosmWasmCodec", () => {
});
});
it("properly generates bytes to sign", () => {
const expected = {
bytes: toUtf8(
'{"account_number":"0","chain_id":"cosmoshub-3","fee":{"amount":[{"amount":"2500","denom":"uatom"}],"gas":"100000"},"memo":"","msgs":[{"type":"cosmos-sdk/MsgSend","value":{"amount":[{"amount":"35997500","denom":"uatom"}],"from_address":"cosmos1txqfn5jmcts0x0q7krdxj8tgf98tj0965vqlmq","to_address":"cosmos1nynns8ex9fq6sjjfj8k79ymkdz4sqth06xexae"}}],"sequence":"99"}',
),
prehashType: PrehashType.Sha256,
};
const bytesToSign = cosmWasmCodec.bytesToSign(sendTxJson, nonce);
expect(bytesToSign).toEqual(expected);
describe("bytesToSign", () => {
it("works for SendTransaction via bank module", () => {
const expected = {
bytes: toUtf8(
'{"account_number":"0","chain_id":"cosmoshub-3","fee":{"amount":[{"amount":"2500","denom":"uatom"}],"gas":"100000"},"memo":"","msgs":[{"type":"cosmos-sdk/MsgSend","value":{"amount":[{"amount":"35997500","denom":"uatom"}],"from_address":"cosmos1txqfn5jmcts0x0q7krdxj8tgf98tj0965vqlmq","to_address":"cosmos1nynns8ex9fq6sjjfj8k79ymkdz4sqth06xexae"}}],"sequence":"99"}',
),
prehashType: PrehashType.Sha256,
};
expect(cosmWasmCodec.bytesToSign(sendTxJson, nonce)).toEqual(expected);
});
});
it("properly encodes transactions", () => {
const encoded = cosmWasmCodec.bytesToPost(signedTxJson);
expect(encoded).toEqual(signedTxEncodedJson);
describe("bytesToPost", () => {
it("works for SendTransaction via bank module", () => {
const encoded = cosmWasmCodec.bytesToPost(signedTxJson);
expect(encoded).toEqual(signedTxEncodedJson);
});
});
it("throws when trying to decode a transaction without a nonce", () => {
expect(() => cosmWasmCodec.parseBytes(signedTxBin as PostableBytes, chainId)).toThrowError(
/nonce is required/i,
);
});
describe("parseBytes", () => {
it("throws when trying to decode a transaction without a nonce", () => {
expect(() => cosmWasmCodec.parseBytes(signedTxBin as PostableBytes, chainId)).toThrowError(
/nonce is required/i,
);
});
it("properly decodes transactions", () => {
const decoded = cosmWasmCodec.parseBytes(signedTxEncodedJson as PostableBytes, chainId, nonce);
expect(decoded).toEqual(signedTxJson);
});
it("properly decodes transactions", () => {
const decoded = cosmWasmCodec.parseBytes(signedTxEncodedJson as PostableBytes, chainId, nonce);
expect(decoded).toEqual(signedTxJson);
});
it("round trip works", () => {
const encoded = cosmWasmCodec.bytesToPost(signedTxJson);
const decoded = cosmWasmCodec.parseBytes(encoded, chainId, nonce);
expect(decoded).toEqual(signedTxJson);
it("round trip works", () => {
const encoded = cosmWasmCodec.bytesToPost(signedTxJson);
const decoded = cosmWasmCodec.parseBytes(encoded, chainId, nonce);
expect(decoded).toEqual(signedTxJson);
});
});
});