This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
/
client.test.ts
151 lines (127 loc) · 5.42 KB
/
client.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import "jest-extended";
import { DateTime } from "@arkecosystem/platform-sdk-intl";
import { BigNumber } from "@arkecosystem/platform-sdk-support";
import nock from "nock";
import { createConfig } from "../../test/helpers";
import { SignedTransactionData, TransactionData, WalletData } from "../dto";
import { ClientService } from "./client";
let subject: ClientService;
beforeEach(async () => (subject = await ClientService.construct(createConfig())));
beforeAll(() => nock.disableNetConnect());
describe("ClientService", function () {
describe("#transaction", () => {
it("should succeed", async () => {
nock("https://stargate.cosmos.network")
.get("/txs/B0DB35EADB3655E954A785B1ED0402222EF8C7061B22E52720AB1CE027ADBD11")
.reply(200, require(`${__dirname}/../../test/fixtures/client/transaction.json`));
const result = await subject.transaction(
"B0DB35EADB3655E954A785B1ED0402222EF8C7061B22E52720AB1CE027ADBD11",
);
expect(result).toBeInstanceOf(TransactionData);
expect(result.id()).toBe("B0DB35EADB3655E954A785B1ED0402222EF8C7061B22E52720AB1CE027ADBD11");
expect(result.type()).toBe("transfer");
expect(result.timestamp()).toBeInstanceOf(DateTime);
expect(result.confirmations()).toEqual(BigNumber.ZERO);
expect(result.sender()).toBe("cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0");
expect(result.recipient()).toBe("cosmos14ddvyl5t0hzmknceuv3zzu5szuum4rkygpq5ln");
expect(result.amount()).toEqual(BigNumber.make(10680));
expect(result.fee()).toEqual(BigNumber.make(36875));
expect(result.memo()).toBe("Hello World");
});
});
describe("#transactions", () => {
it("should succeed", async () => {
nock("https://stargate.cosmos.network")
.get(
"/txs?message.action=send&message.sender=cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0&page=1&limit=100",
)
.reply(200, require(`${__dirname}/../../test/fixtures/client/transactions.json`));
const result = await subject.transactions({ address: "cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0" });
expect(result).toBeObject();
expect(result.items()[0]).toBeInstanceOf(TransactionData);
expect(result.items()[0].id()).toBe("B0DB35EADB3655E954A785B1ED0402222EF8C7061B22E52720AB1CE027ADBD11");
expect(result.items()[0].type()).toBe("transfer");
expect(result.items()[0].timestamp()).toBeInstanceOf(DateTime);
expect(result.items()[0].confirmations()).toEqual(BigNumber.ZERO);
expect(result.items()[0].sender()).toBe("cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0");
expect(result.items()[0].recipient()).toBe("cosmos14ddvyl5t0hzmknceuv3zzu5szuum4rkygpq5ln");
expect(result.items()[0].amount()).toEqual(BigNumber.make(10680));
expect(result.items()[0].fee()).toEqual(BigNumber.make(36875));
expect(result.items()[0].memo()).toBe("Hello World");
});
});
describe("#wallet", () => {
it("should succeed", async () => {
nock("https://stargate.cosmos.network")
.get("/auth/accounts/cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0")
.reply(200, require(`${__dirname}/../../test/fixtures/client/wallet.json`));
const result = await subject.wallet("cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0");
expect(result).toBeInstanceOf(WalletData);
expect(result.address()).toBe("cosmos1de7pk372jkp9vrul0gv5j6r3l9mt3wa6m4h6h0");
expect(result.publicKey()).toBe("Ap65s+Jdgo8BtvTbkc7GyUti8yJ7RpZ7cE1zCuKgNeXY");
expect(result.balance()).toEqual(BigNumber.make(69519574));
expect(result.nonce()).toEqual(BigNumber.make(24242));
});
});
describe("#syncing", () => {
it("should succeed", async () => {
nock("https://stargate.cosmos.network")
.get("/syncing")
.reply(200, require(`${__dirname}/../../test/fixtures/client/syncing.json`));
const result = await subject.syncing();
expect(result).toBeBoolean();
});
});
describe("#broadcast", () => {
const transactionPayload = new SignedTransactionData("id", {
msg: [
{
type: "cosmos-sdk/MsgSend",
value: {
amount: [{ amount: "1", denom: "umuon" }],
from_address: "cosmos1pnc559thh9ks4crsp5p3wta2f2m09t4gluyl2l",
to_address: "cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2",
},
},
],
fee: { amount: [{ amount: "5000", denom: "umuon" }], gas: "200000" },
signatures: [
{
signature:
"naiy71Wa8hPC8wMj2/J4CwnqtR8RThv9Cy3y1EGJVowVtDWJQoUmy3KfYneA2wwLQUlgI/UWgNMClCzbJdD8Ew==",
account_number: "58976",
sequence: "16",
pub_key: {
type: "tendermint/PubKeySecp256k1",
value: "A1wiLscFDRRdEuWx5WmXbXVbMszN2cBHaJFWfJm399Yy",
},
},
],
memo: "",
});
it("should pass", async () => {
nock("https://stargate.cosmos.network")
.post("/txs")
.reply(200, require(`${__dirname}/../../test/fixtures/client/broadcast.json`));
const result = await subject.broadcast([transactionPayload]);
expect(result).toEqual({
accepted: ["25E82BD7E457147DA29FD39E6C155365F07559A7834C7FBB4E9B21DE6A65BFC7"],
rejected: [],
errors: {},
});
});
it("should fail", async () => {
nock("https://stargate.cosmos.network")
.post("/txs")
.reply(200, require(`${__dirname}/../../test/fixtures/client/broadcast-failure.json`));
const result = await subject.broadcast([transactionPayload]);
expect(result).toEqual({
accepted: [],
rejected: ["535C0F6E94506C2D579CCAC76A155472394062FD2D712C662745D93E951164FB"],
errors: {
"535C0F6E94506C2D579CCAC76A155472394062FD2D712C662745D93E951164FB": ["ERR_INSUFFICIENT_FUNDS"],
},
});
});
});
});