Skip to content

Commit ce1b5cb

Browse files
authored
Merge pull request #1727 from cosmos/from-koa-cors
Modernize import style of @koa/cors
2 parents 433a4f8 + e7775b2 commit ce1b5cb

File tree

3 files changed

+79
-11
lines changed

3 files changed

+79
-11
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { makeCosmoshubPath } from "@cosmjs/stargate";
2+
import { sleep } from "@cosmjs/utils";
3+
4+
import { Faucet } from "../faucet";
5+
import { TokenConfiguration } from "../tokenmanager";
6+
import { ChainConstants, Webserver } from "./webserver";
7+
8+
function pendingWithoutSimapp(): void {
9+
if (!process.env.SIMAPP47_ENABLED && !process.env.SIMAPP50_ENABLED) {
10+
return pending("Set SIMAPP{47,50}_ENABLED to enabled Stargate node-based tests");
11+
}
12+
}
13+
14+
const defaultTokenConfig: TokenConfiguration = {
15+
bankTokens: ["ucosm", "ustake"],
16+
};
17+
const defaultAddressPrefix = "cosmos";
18+
19+
const faucetMnemonic =
20+
"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";
21+
22+
const testingPort = 62222;
23+
24+
describe("Webserver", () => {
25+
const pathBuilder = makeCosmoshubPath;
26+
27+
const rpcUrl = "http://localhost:26658";
28+
let originalEnvVariable: string | undefined;
29+
30+
beforeAll(() => {
31+
originalEnvVariable = process.env.FAUCET_CREDIT_AMOUNT_USTAKE;
32+
process.env.FAUCET_CREDIT_AMOUNT_USTAKE = "100000";
33+
});
34+
35+
afterAll(() => {
36+
process.env.FAUCET_CREDIT_AMOUNT_USTAKE = originalEnvVariable;
37+
});
38+
39+
it("can be constructed and started", async () => {
40+
pendingWithoutSimapp();
41+
const faucet = await Faucet.make(
42+
rpcUrl,
43+
defaultAddressPrefix,
44+
defaultTokenConfig,
45+
faucetMnemonic,
46+
pathBuilder,
47+
3,
48+
true,
49+
);
50+
expect(faucet).toBeTruthy();
51+
52+
const constants: ChainConstants = {
53+
nodeUrl: rpcUrl,
54+
chainId: "no idea bro",
55+
};
56+
57+
const server = new Webserver(faucet, constants);
58+
expect(server).toBeTruthy();
59+
server.start(testingPort);
60+
await sleep(2_000);
61+
62+
const healthz = await fetch(`http://localhost:${testingPort}/healthz`);
63+
expect(healthz.ok);
64+
65+
const status = await fetch(`http://localhost:${testingPort}/status`);
66+
expect(status.ok);
67+
});
68+
});

packages/faucet/src/api/webserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import cors from "@koa/cors";
12
// eslint-disable-next-line @typescript-eslint/naming-convention
23
import Koa from "koa";
3-
import cors = require("@koa/cors");
44
import bodyParser from "koa-bodyparser";
55

66
import { isValidAddress } from "../addresses";

packages/faucet/src/faucet.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("Faucet", () => {
2828
const pathBuilder = makeCosmoshubPath;
2929

3030
const apiUrl = "http://localhost:26658";
31-
const stargate = true;
31+
const logging = true;
3232
let originalEnvVariable: string | undefined;
3333

3434
beforeAll(() => {
@@ -51,7 +51,7 @@ describe("Faucet", () => {
5151
faucetMnemonic,
5252
pathBuilder,
5353
3,
54-
stargate,
54+
logging,
5555
);
5656
expect(faucet).toBeTruthy();
5757
});
@@ -67,7 +67,7 @@ describe("Faucet", () => {
6767
faucetMnemonic,
6868
pathBuilder,
6969
3,
70-
stargate,
70+
logging,
7171
);
7272
const tickers = await faucet.availableTokens();
7373
expect(tickers).toEqual([]);
@@ -82,7 +82,7 @@ describe("Faucet", () => {
8282
faucetMnemonic,
8383
pathBuilder,
8484
3,
85-
stargate,
85+
logging,
8686
);
8787
const tickers = await faucet.availableTokens();
8888
expect(tickers).toEqual(["ucosm", "ustake"]);
@@ -99,7 +99,7 @@ describe("Faucet", () => {
9999
faucetMnemonic,
100100
pathBuilder,
101101
3,
102-
stargate,
102+
logging,
103103
);
104104
const recipient = makeRandomAddress();
105105
await faucet.send({
@@ -133,7 +133,7 @@ describe("Faucet", () => {
133133
faucetMnemonic,
134134
pathBuilder,
135135
3,
136-
stargate,
136+
logging,
137137
);
138138
await faucet.refill();
139139
const readOnlyClient = await StargateClient.connect(apiUrl);
@@ -162,7 +162,7 @@ describe("Faucet", () => {
162162
faucetMnemonic,
163163
pathBuilder,
164164
3,
165-
stargate,
165+
logging,
166166
);
167167
const recipient = makeRandomAddress();
168168
await faucet.credit(recipient, "ucosm");
@@ -187,7 +187,7 @@ describe("Faucet", () => {
187187
faucetMnemonic,
188188
pathBuilder,
189189
3,
190-
stargate,
190+
logging,
191191
);
192192
const recipient = makeRandomAddress();
193193
await faucet.credit(recipient, "ustake");
@@ -214,7 +214,7 @@ describe("Faucet", () => {
214214
faucetMnemonic,
215215
pathBuilder,
216216
3,
217-
stargate,
217+
logging,
218218
);
219219
const tickers = faucet.configuredTokens();
220220
expect(tickers).toEqual(["ucosm", "ustake"]);
@@ -231,7 +231,7 @@ describe("Faucet", () => {
231231
faucetMnemonic,
232232
pathBuilder,
233233
1,
234-
stargate,
234+
logging,
235235
);
236236
const accounts = await faucet.loadAccounts();
237237

0 commit comments

Comments
 (0)