Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/amino/src/encoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe("encoding", () => {
});
});

it("works for sr25519", () => {
pending("No test data available");
xit("works for sr25519", () => {
// No test data available
});

it("works for multisig", () => {
Expand Down
26 changes: 13 additions & 13 deletions packages/crypto/src/libsodium.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ describe("Libsodium", () => {
// 8 bytes
await Argon2id.execute(password, fromHex("aabbccddeeff0011"), options)
.then(() => {
fail("Argon2id with invalid salt length must not resolve");
throw new Error("Argon2id with invalid salt length must not resolve");
})
.catch((e) => {
expect(e).toMatch(/invalid salt length/);
});
// 15 bytes
await Argon2id.execute(password, fromHex("aabbccddeeff001122334455667788"), options)
.then(() => {
fail("Argon2id with invalid salt length must not resolve");
throw new Error("Argon2id with invalid salt length must not resolve");
})
.catch((e) => {
expect(e).toMatch(/invalid salt length/);
});
// 17 bytes
await Argon2id.execute(password, fromHex("aabbccddeeff00112233445566778899aa"), options)
.then(() => {
fail("Argon2id with invalid salt length must not resolve");
throw new Error("Argon2id with invalid salt length must not resolve");
})
.catch((e) => {
expect(e).toMatch(/invalid salt length/);
Expand All @@ -157,7 +157,7 @@ describe("Libsodium", () => {
options,
)
.then(() => {
fail("Argon2id with invalid salt length must not resolve");
throw new Error("Argon2id with invalid salt length must not resolve");
})
.catch((e) => {
expect(e).toMatch(/invalid salt length/);
Expand Down Expand Up @@ -235,7 +235,7 @@ describe("Libsodium", () => {
const seed = fromHex("43a9c17ccbb0e767ea29ce1f10813afde5f1e0a7a504e89b4d2cc2b952b8e0");
await Ed25519.makeKeypair(seed)
.then(() => {
fail("promise must not resolve");
throw new Error("promise must not resolve");
})
.catch((error) => {
expect(error.message).toContain("key of length 32 expected");
Expand All @@ -247,7 +247,7 @@ describe("Libsodium", () => {
const seed = fromHex("43a9c17ccbb0e767ea29ce1f10813afde5f1e0a7a504e89b4d2cc2b952b8e0b9aa");
await Ed25519.makeKeypair(seed)
.then(() => {
fail("promise must not resolve");
throw new Error("promise must not resolve");
})
.catch((error) => {
expect(error.message).toContain("key of length 32 expected");
Expand Down Expand Up @@ -423,7 +423,7 @@ describe("Libsodium", () => {
const key = fromHex("");
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
.then(() => {
fail("encryption must not succeed");
throw new Error("encryption must not succeed");
})
.catch((error) => {
expect(error).toMatch(/key, got length=0/);
Expand All @@ -434,7 +434,7 @@ describe("Libsodium", () => {
const key = fromHex("1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916");
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
.then(() => {
fail("encryption must not succeed");
throw new Error("encryption must not succeed");
})
.catch((error) => {
expect(error).toMatch(/key, got length=31/);
Expand All @@ -445,7 +445,7 @@ describe("Libsodium", () => {
const key = fromHex("1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916d8aa");
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
.then(() => {
fail("encryption must not succeed");
throw new Error("encryption must not succeed");
})
.catch((error) => {
expect(error).toMatch(/key, got length=33/);
Expand All @@ -458,7 +458,7 @@ describe("Libsodium", () => {
);
await Xchacha20poly1305Ietf.encrypt(message, key, nonce)
.then(() => {
fail("encryption must not succeed");
throw new Error("encryption must not succeed");
})
.catch((error) => {
expect(error).toMatch(/key, got length=64/);
Expand All @@ -484,7 +484,7 @@ describe("Libsodium", () => {
const corruptedCiphertext = ciphertext.map((x, i) => (i === 0 ? x ^ 0x01 : x));
await Xchacha20poly1305Ietf.decrypt(corruptedCiphertext, key, nonce).then(
() => {
fail("promise must not resolve");
throw new Error("promise must not resolve");
},
(error) => {
expect(error.message).toMatch(/invalid tag/i);
Expand All @@ -496,7 +496,7 @@ describe("Libsodium", () => {
const corruptedKey = key.map((x, i) => (i === 0 ? x ^ 0x01 : x));
await Xchacha20poly1305Ietf.decrypt(ciphertext, corruptedKey, nonce).then(
() => {
fail("promise must not resolve");
throw new Error("promise must not resolve");
},
(error) => {
expect(error.message).toMatch(/invalid tag/i);
Expand All @@ -508,7 +508,7 @@ describe("Libsodium", () => {
const corruptedNonce = nonce.map((x, i) => (i === 0 ? x ^ 0x01 : x));
await Xchacha20poly1305Ietf.decrypt(ciphertext, key, corruptedNonce).then(
() => {
fail("promise must not resolve");
throw new Error("promise must not resolve");
},
(error) => {
expect(error.message).toMatch(/invalid tag/i);
Expand Down
5 changes: 2 additions & 3 deletions packages/crypto/src/pbkdf2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ describe("pbkdf2", () => {
describe("pbkdf2Sha512Subtle", () => {
it("works", async () => {
const subtle = await getSubtle();
if (!subtle) {
pending("Subtle is not available in this environment");
return;
if (subtle === undefined) {
throw new Error("Subtle is not available in this environment");
}

{
Expand Down
18 changes: 9 additions & 9 deletions packages/crypto/src/secp256k1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,37 @@ describe("Secp256k1", () => {
// too short and too long
await Secp256k1.makeKeypair(fromHex("e4ade2a5232a7c6f37e7b854a774e25e6047ee7c6d63e8304ae04fa190bc17"))
.then(() => {
fail("promise must be rejected");
throw new Error("promise must be rejected");
})
.catch((error) => {
expect(error.message).toContain("not a valid secp256k1 private key");
});
await Secp256k1.makeKeypair(fromHex("e4ade2a5232a7c6f37e7b854a774e25e6047ee7c6d63e8304ae04fa190bc1732aa"))
.then(() => {
fail("promise must be rejected");
throw new Error("promise must be rejected");
})
.catch((error) => {
expect(error.message).toContain("not a valid secp256k1 private key");
});
// value out of range (too small)
await Secp256k1.makeKeypair(fromHex("0000000000000000000000000000000000000000000000000000000000000000"))
.then(() => {
fail("promise must be rejected");
throw new Error("promise must be rejected");
})
.catch((error) => {
expect(error.message).toContain("not a valid secp256k1 private key");
});
// value out of range (>= n)
await Secp256k1.makeKeypair(fromHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
.then(() => {
fail("promise must be rejected");
throw new Error("promise must be rejected");
})
.catch((error) => {
expect(error.message).toContain("not a valid secp256k1 private key");
});
await Secp256k1.makeKeypair(fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"))
.then(() => {
fail("promise must be rejected");
throw new Error("promise must be rejected");
})
.catch((error) => {
expect(error.message).toContain("not a valid secp256k1 private key");
Expand Down Expand Up @@ -133,7 +133,7 @@ describe("Secp256k1", () => {
const messageHash = new Uint8Array([]);
await Secp256k1.createSignature(messageHash, keypair.privkey)
.then(() => {
fail("must not resolve");
throw new Error("must not resolve");
})
.catch((error) => {
expect(error).toMatch(/message hash must not be empty/i);
Expand All @@ -146,7 +146,7 @@ describe("Secp256k1", () => {
const messageHash = fromHex("11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff11");
await Secp256k1.createSignature(messageHash, keypair.privkey)
.then(() => {
fail("must not resolve");
throw new Error("must not resolve");
})
.catch((error) => {
expect(error).toMatch(/message hash length must not exceed 32 bytes/i);
Expand Down Expand Up @@ -202,7 +202,7 @@ describe("Secp256k1", () => {
const messageHash = new Uint8Array([]);
await Secp256k1.verifySignature(dummySignature, messageHash, keypair.pubkey)
.then(() => {
fail("must not resolve");
throw new Error("must not resolve");
})
.catch((error) => {
expect(error).toMatch(/message hash must not be empty/i);
Expand All @@ -221,7 +221,7 @@ describe("Secp256k1", () => {
const messageHash = fromHex("11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff11");
await Secp256k1.verifySignature(dummySignature, messageHash, keypair.privkey)
.then(() => {
fail("must not resolve");
throw new Error("must not resolve");
})
.catch((error) => {
expect(error).toMatch(/message hash length must not exceed 32 bytes/i);
Expand Down
22 changes: 7 additions & 15 deletions packages/faucet-client/src/faucetclient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { FaucetClient } from "./faucetclient";

function pendingWithoutFaucet(): void {
if (!process.env.FAUCET_ENABLED) {
pending("Set FAUCET_ENABLED to enable tests that need a faucet");
}
}
const enabled = !!globalThis.process?.env.FAUCET_ENABLED;

describe("FaucetClient", () => {
const faucetUrl = "http://localhost:8000";
Expand All @@ -25,39 +21,35 @@ describe("FaucetClient", () => {
expect(new FaucetClient("https://localhost/")).toBeTruthy();
});

it("can be used to credit a wallet", async () => {
pendingWithoutFaucet();
(enabled ? it : xit)("can be used to credit a wallet", async () => {
const faucet = new FaucetClient(faucetUrl);
await faucet.credit(defaultAddress, primaryToken);
});

it("can be used to credit a wallet with a different token", async () => {
pendingWithoutFaucet();
(enabled ? it : xit)("can be used to credit a wallet with a different token", async () => {
const faucet = new FaucetClient(faucetUrl);
await faucet.credit(defaultAddress, secondaryToken);
});

it("throws for invalid ticker", async () => {
pendingWithoutFaucet();
(enabled ? it : xit)("throws for invalid ticker", async () => {
const faucet = new FaucetClient(faucetUrl);
await faucet.credit(defaultAddress, "ETH").then(
() => {
fail("must not resolve");
throw new Error("must not resolve");
},
(error) => {
expect(error).toMatch(/token is not available/i);
},
);
});

it("throws for invalid address", async () => {
pendingWithoutFaucet();
(enabled ? it : xit)("throws for invalid address", async () => {
const faucet = new FaucetClient(faucetUrl);

for (const address of ["be5cc2cc05db2cdb4313c18306a5157291cfdcd1", "1234L"]) {
await faucet.credit(address, primaryToken).then(
() => {
fail("must not resolve");
throw new Error("must not resolve");
},
(error) => {
expect(error).toMatch(/address is not in the expected format for this chain/i);
Expand Down
18 changes: 2 additions & 16 deletions packages/faucet/src/faucet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { assert } from "@cosmjs/utils";
import { Faucet } from "./faucet";
import { TokenConfiguration } from "./tokenmanager";

function pendingWithoutSimapp(): void {
if (!process.env.SIMAPP47_ENABLED && !process.env.SIMAPP50_ENABLED) {
pending("Set SIMAPP{47,50}_ENABLED to enabled Stargate node-based tests");
return;
}
}
const enabled = !!(globalThis.process?.env.SIMAPP47_ENABLED || globalThis.process?.env.SIMAPP50_ENABLED);

const defaultTokenConfig: TokenConfiguration = {
bankTokens: ["ucosm", "ustake"],
Expand All @@ -25,7 +20,7 @@ function makeRandomAddress(): string {
const faucetMnemonic =
"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";

describe("Faucet", () => {
(enabled ? describe : xdescribe)("Faucet", () => {
const pathBuilder = makeCosmoshubPath;

const apiUrl = "http://localhost:26658";
Expand All @@ -44,7 +39,6 @@ describe("Faucet", () => {
describe("stargate", () => {
describe("constructor", () => {
it("can be constructed", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand All @@ -60,7 +54,6 @@ describe("Faucet", () => {

describe("availableTokens", () => {
it("is empty when no tokens are configured", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand All @@ -75,7 +68,6 @@ describe("Faucet", () => {
});

it("is not empty with default token config", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand All @@ -92,7 +84,6 @@ describe("Faucet", () => {

describe("send", () => {
it("can send bank token", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand Down Expand Up @@ -126,7 +117,6 @@ describe("Faucet", () => {

describe("refill", () => {
it("works", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand Down Expand Up @@ -155,7 +145,6 @@ describe("Faucet", () => {

describe("credit", () => {
it("works for fee token", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand All @@ -180,7 +169,6 @@ describe("Faucet", () => {
});

it("works for stake token", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand All @@ -207,7 +195,6 @@ describe("Faucet", () => {

describe("configuredTokens", () => {
it("works", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand All @@ -224,7 +211,6 @@ describe("Faucet", () => {

describe("loadAccounts", () => {
it("works", async () => {
pendingWithoutSimapp();
const faucet = await Faucet.make(
apiUrl,
defaultAddressPrefix,
Expand Down
Loading
Loading