-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] Test coverage TOOL-2241 (#5826)
Holiday project. Basically trying to improve test coverage, especially in those low-haning-fruit utils files <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing documentation, improving error handling, and adding tests across various modules in the codebase. It also corrects minor typos and ensures better code readability. ### Detailed summary - Added `@internal` documentation comments to `Queue` and `convertViemChain`. - Updated test cases to use `await expect(...)` for consistency. - Fixed typos in file imports and function names. - Introduced new tests for `namehash`, `encodeLabelhash`, and `parseNFT`. - Enhanced error handling in `parseNftUri`. - Improved the `toSemver` function and its tests. - Added tests for `replaceBigInts` and `toHex` functions. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
Showing
33 changed files
with
1,442 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import { USDT_CONTRACT_ADDRESS } from "~test/test-contracts.js"; | ||
import { ethereum } from "../chains/chain-definitions/ethereum.js"; | ||
import { getContract } from "./contract.js"; | ||
|
||
describe("Contract - getContract", () => { | ||
it("should throw error if client is not passed", () => { | ||
expect(() => | ||
// @ts-ignore Test purpose | ||
getContract({ address: "0x", chain: ethereum }), | ||
).toThrowError( | ||
`getContract validation error - invalid client: ${undefined}`, | ||
); | ||
}); | ||
|
||
it("should throw error if address is not valid", () => { | ||
expect(() => | ||
getContract({ address: "0x", chain: ethereum, client: TEST_CLIENT }), | ||
).toThrowError("getContract validation error - invalid address: 0x"); | ||
}); | ||
|
||
it("should throw error if chain is not passed", () => { | ||
expect(() => | ||
// @ts-ignore Test purpose | ||
getContract({ address: USDT_CONTRACT_ADDRESS, client: TEST_CLIENT }), | ||
).toThrowError( | ||
`getContract validation error - invalid chain: ${undefined}`, | ||
); | ||
}); | ||
|
||
it("should throw error if chain doesn't have id", () => { | ||
expect(() => | ||
getContract({ | ||
address: USDT_CONTRACT_ADDRESS, | ||
client: TEST_CLIENT, | ||
// @ts-ignore Test | ||
chain: {}, | ||
}), | ||
).toThrowError(`getContract validation error - invalid chain: ${{}}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { CADIcon } from "../../../icons/currencies/CADIcon.js"; | ||
import { EURIcon } from "../../../icons/currencies/EURIcon.js"; | ||
import { GBPIcon } from "../../../icons/currencies/GBPIcon.js"; | ||
import { JPYIcon } from "../../../icons/currencies/JPYIcon.js"; | ||
import { USDIcon } from "../../../icons/currencies/USDIcon.js"; | ||
import { currencies, getCurrencyMeta, usdCurrency } from "./currencies.js"; | ||
|
||
describe("Currency Utilities", () => { | ||
it("should have correct number of currencies", () => { | ||
expect(currencies.length).toBe(5); | ||
}); | ||
|
||
it("should have USD as the first currency", () => { | ||
expect(currencies[0]).toEqual(usdCurrency); | ||
}); | ||
|
||
it("should have correct properties for each currency", () => { | ||
for (const currency of currencies) { | ||
expect(currency).toHaveProperty("shorthand"); | ||
expect(currency).toHaveProperty("name"); | ||
expect(currency).toHaveProperty("icon"); | ||
} | ||
}); | ||
|
||
describe("getCurrencyMeta function", () => { | ||
it("should return correct currency meta for valid shorthand", () => { | ||
const cadMeta = getCurrencyMeta("CAD"); | ||
expect(cadMeta.shorthand).toBe("CAD"); | ||
expect(cadMeta.name).toBe("Canadian Dollar"); | ||
expect(cadMeta.icon).toBe(CADIcon); | ||
}); | ||
|
||
it("should be case-insensitive", () => { | ||
const eurMeta = getCurrencyMeta("eur"); | ||
expect(eurMeta.shorthand).toBe("EUR"); | ||
expect(eurMeta.name).toBe("Euro"); | ||
expect(eurMeta.icon).toBe(EURIcon); | ||
}); | ||
|
||
it("should return unknown currency for invalid shorthand", () => { | ||
const unknownMeta = getCurrencyMeta("XYZ"); | ||
expect(unknownMeta.shorthand).toBe("XYZ"); | ||
expect(unknownMeta.name).toBe("XYZ"); | ||
expect(unknownMeta.icon).not.toBe(USDIcon); | ||
expect(unknownMeta.icon).not.toBe(CADIcon); | ||
expect(unknownMeta.icon).not.toBe(GBPIcon); | ||
expect(unknownMeta.icon).not.toBe(EURIcon); | ||
expect(unknownMeta.icon).not.toBe(JPYIcon); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.