Skip to content

Commit

Permalink
test: add test for env var names
Browse files Browse the repository at this point in the history
just a snapshot so we can use this as a reference
when passing env vars.
  • Loading branch information
boredland committed Nov 5, 2024
1 parent bd7c67a commit 043df81
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Alchemy API key

If given, the action substitute missing RPC_URLs with one constructed from the given key.

### Supported Environment Variables

The supported environment variables are documented in [this](src/lib.test.ts) test.

#### Usage

```yaml
Expand Down
40 changes: 39 additions & 1 deletion src/lib.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe } from "node:test";
import { expect, it } from "vitest";
import { networkMap } from "./alchemyIds";
import { ChainId, getRPCUrl, supportedChainIds } from "./lib";
import { ChainId, getNetworkEnv, getRPCUrl, supportedChainIds } from "./lib";

describe("lib", () => {
it("should use env var if given", () => {
Expand All @@ -28,4 +28,42 @@ describe("lib", () => {
it.each(supportedChainIds)("should return supported chain %s", (chainId) => {
expect(getRPCUrl(chainId, "abc")).toMatchSnapshot(networkMap[chainId]);
});

it("has sensible env names for RPC_", () => {
const envs = Object.fromEntries(
supportedChainIds.map((chainId) => [
getNetworkEnv(chainId),
getRPCUrl(chainId, "abc"),
]),
);

expect(envs).toMatchInlineSnapshot(`
{
"RPC_ARBITRUM_GOERLI": "https://arb-goerli.g.alchemy.com/v2/abc",
"RPC_ARBITRUM_ONE": "https://arb-mainnet.g.alchemy.com/v2/abc",
"RPC_ARBITRUM_SEPOLIA": "https://arb-sepolia.g.alchemy.com/v2/abc",
"RPC_AVALANCHE": "https://avax-mainnet.g.alchemy.com/v2/abc",
"RPC_BASE": "https://base-mainnet.g.alchemy.com/v2/abc",
"RPC_BASE_SEPOLIA": "https://base-sepolia.g.alchemy.com/v2/abc",
"RPC_BNB": "https://bnb-mainnet.g.alchemy.com/v2/abc",
"RPC_FANTOM": "https://fantom-mainnet.g.alchemy.com/v2/abc",
"RPC_FANTOM_TESTNET": "https://fantom-testnet.g.alchemy.com/v2/abc",
"RPC_FUJI": "https://avax-fuji.g.alchemy.com/v2/abc",
"RPC_GNOSIS": "https://gnosis-mainnet.g.alchemy.com/v2/abc",
"RPC_GOERLI": "https://eth-goerli.g.alchemy.com/v2/abc",
"RPC_MAINNET": "https://eth-mainnet.g.alchemy.com/v2/abc",
"RPC_METIS": "https://metis-mainnet.g.alchemy.com/v2/abc",
"RPC_MUMBAI": "https://polygon-mumbai.g.alchemy.com/v2/abc",
"RPC_OPTIMISM": "https://opt-mainnet.g.alchemy.com/v2/abc",
"RPC_OPTIMISM_GOERLI": "https://opt-goerli.g.alchemy.com/v2/abc",
"RPC_OPTIMISM_SEPOLIA": "https://opt-sepolia.g.alchemy.com/v2/abc",
"RPC_POLYGON": "https://polygon-mainnet.g.alchemy.com/v2/abc",
"RPC_SCROLL": "https://scroll-mainnet.g.alchemy.com/v2/abc",
"RPC_SCROLL_SEPOLIA": "https://scroll-sepolia.g.alchemy.com/v2/abc",
"RPC_SEPOLIA": "https://eth-sepolia.g.alchemy.com/v2/abc",
"RPC_ZKEVM": "https://polygonzkevm-mainnet.g.alchemy.com/v2/abc",
"RPC_ZKSYNC": "https://zksync-mainnet.g.alchemy.com/v2/abc",
}
`);
});
});

0 comments on commit 043df81

Please sign in to comment.