faucet: Update tests for denom
This commit is contained in:
parent
795451ee14
commit
445b5065c0
@ -1,7 +1,12 @@
|
||||
import { RequestParser } from "./requestparser";
|
||||
|
||||
describe("RequestParser", () => {
|
||||
it("can process valid credit request", () => {
|
||||
it("can process valid credit request with denom", () => {
|
||||
const body = { address: "abc", denom: "utkn" };
|
||||
expect(RequestParser.parseCreditBody(body)).toEqual({ address: "abc", denom: "utkn" });
|
||||
});
|
||||
|
||||
it("can process valid credit request with ticker", () => {
|
||||
const body = { address: "abc", ticker: "TKN" };
|
||||
expect(RequestParser.parseCreditBody(body)).toEqual({ address: "abc", ticker: "TKN" });
|
||||
});
|
||||
@ -37,16 +42,42 @@ describe("RequestParser", () => {
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(/Property 'address' must not be empty/i);
|
||||
}
|
||||
|
||||
// ticker unset
|
||||
// denom and ticker unset
|
||||
{
|
||||
const body = { address: "abc" };
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(/Property 'ticker' must be a string/i);
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(
|
||||
/Exactly one of properties 'denom' or 'ticker' must be a string/i,
|
||||
);
|
||||
}
|
||||
|
||||
// denom and ticker both set
|
||||
{
|
||||
const body = { address: "abc", denom: "ustake", ticker: "COSM" };
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(
|
||||
/Exactly one of properties 'denom' or 'ticker' must be a string/i,
|
||||
);
|
||||
}
|
||||
|
||||
// denom wrong type
|
||||
{
|
||||
const body = { address: "abc", denom: true };
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(
|
||||
/Exactly one of properties 'denom' or 'ticker' must be a string/i,
|
||||
);
|
||||
}
|
||||
|
||||
// denom empty
|
||||
{
|
||||
const body = { address: "abc", denom: "" };
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(/Property 'denom' must not be empty/i);
|
||||
}
|
||||
|
||||
// ticker wrong type
|
||||
{
|
||||
const body = { address: "abc", ticker: true };
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(/Property 'ticker' must be a string/i);
|
||||
expect(() => RequestParser.parseCreditBody(body)).toThrowError(
|
||||
/Exactly one of properties 'denom' or 'ticker' must be a string/i,
|
||||
);
|
||||
}
|
||||
|
||||
// ticker empty
|
||||
|
||||
@ -53,11 +53,14 @@ describe("Faucet", () => {
|
||||
expect(tickers).toEqual([]);
|
||||
});
|
||||
|
||||
it("is empty when no tokens are configured", async () => {
|
||||
it("is not empty with default token config", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const faucet = await Faucet.make(httpUrl, defaultAddressPrefix, defaultTokenConfig, faucetMnemonic, 3);
|
||||
const tickers = await faucet.availableTokens();
|
||||
expect(tickers).toEqual(["COSM", "STAKE"]);
|
||||
expect(tickers).toEqual([
|
||||
{ denom: "ucosm", tickerSymbol: "COSM", fractionalDigits: 6 },
|
||||
{ denom: "ustake", tickerSymbol: "STAKE", fractionalDigits: 6 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -113,7 +116,7 @@ describe("Faucet", () => {
|
||||
pendingWithoutWasmd();
|
||||
const faucet = await Faucet.make(httpUrl, defaultAddressPrefix, defaultTokenConfig, faucetMnemonic, 3);
|
||||
const recipient = makeRandomAddress();
|
||||
await faucet.credit(recipient, "COSM");
|
||||
await faucet.credit(recipient, "ucosm");
|
||||
|
||||
const readOnlyClient = new CosmosClient(httpUrl);
|
||||
const account = await readOnlyClient.getAccount(recipient);
|
||||
@ -130,7 +133,7 @@ describe("Faucet", () => {
|
||||
pendingWithoutWasmd();
|
||||
const faucet = await Faucet.make(httpUrl, defaultAddressPrefix, defaultTokenConfig, faucetMnemonic, 3);
|
||||
const recipient = makeRandomAddress();
|
||||
await faucet.credit(recipient, "STAKE");
|
||||
await faucet.credit(recipient, "ustake");
|
||||
|
||||
const readOnlyClient = new CosmosClient(httpUrl);
|
||||
const account = await readOnlyClient.getAccount(recipient);
|
||||
|
||||
@ -27,33 +27,33 @@ describe("TokenManager", () => {
|
||||
describe("creditAmount", () => {
|
||||
const tm = new TokenManager(dummyConfig);
|
||||
|
||||
it("returns 10 tokens by default", () => {
|
||||
expect(tm.creditAmount("TOKENZ")).toEqual({
|
||||
it("returns 10_000_000 base tokens by default", () => {
|
||||
expect(tm.creditAmount("utokenz")).toEqual({
|
||||
amount: "10000000",
|
||||
denom: "utokenz",
|
||||
});
|
||||
expect(tm.creditAmount("TRASH")).toEqual({
|
||||
amount: "10000",
|
||||
expect(tm.creditAmount("mtrash")).toEqual({
|
||||
amount: "10000000",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns value from env variable when set", () => {
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "22";
|
||||
expect(tm.creditAmount("TRASH")).toEqual({
|
||||
amount: "22000",
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "22";
|
||||
expect(tm.creditAmount("mtrash")).toEqual({
|
||||
amount: "22",
|
||||
denom: "mtrash",
|
||||
});
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "";
|
||||
});
|
||||
|
||||
it("returns default when env variable is set to empty", () => {
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "";
|
||||
expect(tm.creditAmount("TRASH")).toEqual({
|
||||
amount: "10000",
|
||||
expect(tm.creditAmount("mtrash")).toEqual({
|
||||
amount: "10000000",
|
||||
denom: "mtrash",
|
||||
});
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "";
|
||||
});
|
||||
});
|
||||
|
||||
@ -62,37 +62,37 @@ describe("TokenManager", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.FAUCET_REFILL_FACTOR = "";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "";
|
||||
});
|
||||
|
||||
it("returns 20*10 + '000' by default", () => {
|
||||
expect(tm.refillAmount("TRASH")).toEqual({
|
||||
amount: "200000",
|
||||
it("returns 20*10_000_000' by default", () => {
|
||||
expect(tm.refillAmount("mtrash")).toEqual({
|
||||
amount: "200000000",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns 20*22 + '000' when credit amount is 22", () => {
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "22";
|
||||
expect(tm.refillAmount("TRASH")).toEqual({
|
||||
amount: "440000",
|
||||
it("returns 20*22 when credit amount is 22", () => {
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "22";
|
||||
expect(tm.refillAmount("mtrash")).toEqual({
|
||||
amount: "440",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns 30*10 + '000' when refill factor is 30", () => {
|
||||
it("returns 30*10_000_000' when refill factor is 30", () => {
|
||||
process.env.FAUCET_REFILL_FACTOR = "30";
|
||||
expect(tm.refillAmount("TRASH")).toEqual({
|
||||
amount: "300000",
|
||||
expect(tm.refillAmount("mtrash")).toEqual({
|
||||
amount: "300000000",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns 30*22 + '000' when refill factor is 30 and credit amount is 22", () => {
|
||||
it("returns 30*22 when refill factor is 30 and credit amount is 22", () => {
|
||||
process.env.FAUCET_REFILL_FACTOR = "30";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "22";
|
||||
expect(tm.refillAmount("TRASH")).toEqual({
|
||||
amount: "660000",
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "22";
|
||||
expect(tm.refillAmount("mtrash")).toEqual({
|
||||
amount: "660",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
@ -103,37 +103,37 @@ describe("TokenManager", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.FAUCET_REFILL_THRESHOLD = "";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "";
|
||||
});
|
||||
|
||||
it("returns 8*10 + '000' by default", () => {
|
||||
expect(tm.refillThreshold("TRASH")).toEqual({
|
||||
amount: "80000",
|
||||
it("returns 8*10_000_000 by default", () => {
|
||||
expect(tm.refillThreshold("mtrash")).toEqual({
|
||||
amount: "80000000",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns 8*22 + '000' when credit amount is 22", () => {
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "22";
|
||||
expect(tm.refillThreshold("TRASH")).toEqual({
|
||||
amount: "176000",
|
||||
it("returns 8*22 when credit amount is 22", () => {
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "22";
|
||||
expect(tm.refillThreshold("mtrash")).toEqual({
|
||||
amount: "176",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns 5*10 + '000' when refill threshold is 5", () => {
|
||||
it("returns 5*10_000_000 when refill threshold is 5", () => {
|
||||
process.env.FAUCET_REFILL_THRESHOLD = "5";
|
||||
expect(tm.refillThreshold("TRASH")).toEqual({
|
||||
amount: "50000",
|
||||
expect(tm.refillThreshold("mtrash")).toEqual({
|
||||
amount: "50000000",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns 5*22 + '000' when refill threshold is 5 and credit amount is 22", () => {
|
||||
it("returns 5*22 when refill threshold is 5 and credit amount is 22", () => {
|
||||
process.env.FAUCET_REFILL_THRESHOLD = "5";
|
||||
process.env.FAUCET_CREDIT_AMOUNT_TRASH = "22";
|
||||
expect(tm.refillThreshold("TRASH")).toEqual({
|
||||
amount: "110000",
|
||||
process.env.FAUCET_CREDIT_AMOUNT_MTRASH = "22";
|
||||
expect(tm.refillThreshold("mtrash")).toEqual({
|
||||
amount: "110",
|
||||
denom: "mtrash",
|
||||
});
|
||||
});
|
||||
@ -161,8 +161,8 @@ describe("TokenManager", () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(tm.needsRefill(brokeAccount, "TOKENZ")).toEqual(true);
|
||||
expect(tm.needsRefill(richAccount, "TOKENZ")).toEqual(false);
|
||||
expect(tm.needsRefill(brokeAccount, "utokenz")).toEqual(true);
|
||||
expect(tm.needsRefill(richAccount, "utokenz")).toEqual(false);
|
||||
});
|
||||
|
||||
it("works for missing balance", () => {
|
||||
@ -170,7 +170,7 @@ describe("TokenManager", () => {
|
||||
address: "cosmos1rtfrpqt3yd7c8g73m9rsaen7fft0h52m3v9v5a",
|
||||
balance: [],
|
||||
};
|
||||
expect(tm.needsRefill(emptyAccount, "TOKENZ")).toEqual(true);
|
||||
expect(tm.needsRefill(emptyAccount, "utokenz")).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user