Skip to content

Commit 4ded83b

Browse files
committed
add tests
1 parent 9bf9f93 commit 4ded83b

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

packages/telescope/__tests__/__snapshots__/impl-interfaces.test.ts.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`implements interface works toAmino for interface 1`] = `
4+
{
5+
"authorization": {
6+
"spend_limit": [
7+
{
8+
"amount": "1",
9+
"denom": "d",
10+
},
11+
],
12+
},
13+
"expiration": "2020-01-01T00:00:00Z",
14+
}
15+
`;
16+
317
exports[`implements interface works toJson for Any 1`] = `
418
{
519
"authorization": {
@@ -18,3 +32,17 @@ exports[`implements interface works toJson for extended interface 1`] = `
1832
"expiration": "2020-01-01T00:00:00.000Z",
1933
}
2034
`;
35+
36+
exports[`implements interface works toSDK for interface 1`] = `
37+
{
38+
"authorization": {
39+
"spend_limit": [
40+
{
41+
"amount": "1",
42+
"denom": "d",
43+
},
44+
],
45+
},
46+
"expiration": 2020-01-01T00:00:00.000Z,
47+
}
48+
`;

packages/telescope/__tests__/impl-interfaces.test.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Grant,
55
} from "../../../__fixtures__/misc/output-impl-interfaces-gen/cosmos/authz/v1beta1/authz";
66
import { Any } from "../../../__fixtures__/misc/output-impl-interfaces-gen/google/protobuf/any";
7-
7+
import { SendAuthorization } from "../../../__fixtures__/misc/output-impl-interfaces-gen/cosmos/bank/v1beta1/authz";
88

99
describe("implements interface works", () => {
1010
it("encodes and decodes", () => {
@@ -214,4 +214,73 @@ describe("implements interface works", () => {
214214
throw new Error("auth can't be empty");
215215
}
216216
});
217+
218+
it("toSDK for interface", () => {
219+
const data = Grant.encode({
220+
authorization: {
221+
spendLimit: [
222+
{
223+
denom: "d",
224+
amount: "1",
225+
},
226+
],
227+
},
228+
expiration: new Date("2020-01-01"),
229+
}).finish();
230+
231+
const message = Grant.decode(data);
232+
233+
const SDK = Grant.toSDK(message);
234+
235+
expect(SDK).toMatchSnapshot();
236+
});
237+
238+
it("fromSDK for extended interface", () => {
239+
const message = Grant.fromSDK({
240+
authorization: {
241+
spend_limit: [
242+
{
243+
denom: "d",
244+
amount: "1",
245+
},
246+
],
247+
},
248+
expiration: new Date("2020-01-01"),
249+
});
250+
251+
const data = Grant.encode(message).finish();
252+
253+
const decodedMessage = Grant.decode(data);
254+
255+
if (decodedMessage.authorization) {
256+
if (SendAuthorization.is(decodedMessage.authorization)) {
257+
expect(decodedMessage.authorization.spendLimit[0].denom).toBe("d");
258+
expect(decodedMessage.authorization.spendLimit[0].amount).toBe("1");
259+
} else {
260+
throw new Error("should be SendAuthorization");
261+
}
262+
} else {
263+
throw new Error("auth can't be empty");
264+
}
265+
});
266+
267+
it("toAmino for interface", () => {
268+
const data = Grant.encode({
269+
authorization: {
270+
spendLimit: [
271+
{
272+
denom: "d",
273+
amount: "1",
274+
},
275+
],
276+
},
277+
expiration: new Date("2020-01-01"),
278+
}).finish();
279+
280+
const message = Grant.decode(data);
281+
282+
const amino = Grant.toAmino(message);
283+
284+
expect(amino).toMatchSnapshot();
285+
});
217286
});

0 commit comments

Comments
 (0)