This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
allow full local testing with anvil integration #27
Open
davisshaver
wants to merge
12
commits into
holic:main
Choose a base branch
from
davisshaver:feat-gh-21-anvil
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ffa696
feat: update wagmi to version w/ foundry chain
davisshaver dcc64db
feat: specify chain by slug instead of id
davisshaver e6ff869
feat: (wip) add example foundry deploy
davisshaver 0dbea96
feat: (wip) add example of local graph node
davisshaver 4e881cb
Merge branch 'main' of https://github.com/holic/web3-scaffold into fe…
davisshaver 1e69de1
feat: improve handling of multi chain configs
davisshaver 8792e22
feat: add helper for get graph host
davisshaver 921dcbe
Merge branch 'main' of https://github.com/holic/web3-scaffold into fe…
davisshaver fa0bc1c
feat: allow subgraph url to be configured, not just host
davisshaver c641540
feat: use new subgraph URL for graph client
davisshaver 5f6d980
feat: allow contract address to be set as env
davisshaver ee06437
feat: use standard address format
davisshaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.ts?$": "ts-jest", | ||
}, | ||
transformIgnorePatterns: ["<rootDir>/node_modules/"], | ||
}; |
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
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,24 @@ | ||
import { getChainStatus } from "./getChainStatus"; | ||
|
||
describe("getChainStatus", () => { | ||
const env = process.env; | ||
|
||
it("should get default chain status when env is empty", () => { | ||
process.env = { ...env, NEXT_PUBLIC_CHAIN_STATUS: "" }; | ||
expect(getChainStatus()).toStrictEqual("icon"); | ||
}); | ||
|
||
it("should get chain status env is set", () => { | ||
process.env = { ...env, NEXT_PUBLIC_CHAIN_STATUS: "none" }; | ||
expect(getChainStatus()).toStrictEqual("none"); | ||
}); | ||
|
||
it("should ignore invalid chain status when set", () => { | ||
process.env = { ...env, NEXT_PUBLIC_CHAIN_STATUS: "fakestatus" }; | ||
expect(getChainStatus()).toStrictEqual("icon"); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = env; | ||
}); | ||
}); |
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,14 @@ | ||
// Note: If RainbowKit ever adds more chain status options, add them here. | ||
const chainStatuses = ["full", "icon", "name", "none"] as const; | ||
type ChainStatus = typeof chainStatuses[number]; | ||
|
||
const isValidChainStatus = (value: string): value is ChainStatus => { | ||
return chainStatuses.includes(value as ChainStatus); | ||
}; | ||
|
||
export const getChainStatus = (): ChainStatus => { | ||
return process.env.NEXT_PUBLIC_CHAIN_STATUS && | ||
isValidChainStatus(process.env.NEXT_PUBLIC_CHAIN_STATUS) | ||
? process.env.NEXT_PUBLIC_CHAIN_STATUS | ||
: "icon"; | ||
}; |
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,30 @@ | ||
import { getChainSlugs } from "./getChains"; | ||
|
||
describe("getChains", () => { | ||
const env = process.env; | ||
|
||
it("should get default chains when chain slugs is empty", () => { | ||
process.env = { ...env, NEXT_PUBLIC_CHAIN_SLUGS: "" }; | ||
expect(getChainSlugs()).toStrictEqual(["goerli", "mainnet"]); | ||
}); | ||
|
||
it("should get chains when chain slugs is set", () => { | ||
process.env = { | ||
...env, | ||
NEXT_PUBLIC_CHAIN_SLUGS: "foundry, mainnet,optimism", | ||
}; | ||
expect(getChainSlugs()).toStrictEqual(["foundry", "mainnet", "optimism"]); | ||
}); | ||
|
||
it("should ignore invalid chain slugs when set", () => { | ||
process.env = { | ||
...env, | ||
NEXT_PUBLIC_CHAIN_SLUGS: "foundry, mainnet,fakechain", | ||
}; | ||
expect(getChainSlugs()).toStrictEqual(["foundry", "mainnet"]); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = env; | ||
}); | ||
}); |
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,32 @@ | ||
import { chain } from "wagmi"; | ||
|
||
const isValidChain = (value: string): value is keyof typeof chain => { | ||
return [ | ||
"mainnet", | ||
"ropsten", | ||
"rinkeby", | ||
"goerli", | ||
"kovan", | ||
"optimism", | ||
"optimismKovan", | ||
"polygon", | ||
"polygonMumbai", | ||
"arbitrum", | ||
"arbitrumRinkeby", | ||
"localhost", | ||
"hardhat", | ||
"foundry", | ||
].includes(value); | ||
}; | ||
|
||
export const getChainSlugs = () => { | ||
const targetChainSlugs = process.env.NEXT_PUBLIC_CHAIN_SLUGS | ||
? process.env.NEXT_PUBLIC_CHAIN_SLUGS.split(",").map((slug) => slug.trim()) | ||
: ["goerli", "mainnet"]; | ||
return targetChainSlugs.filter(isValidChain); | ||
}; | ||
|
||
export const getChains = () => { | ||
const chainSlugs = getChainSlugs(); | ||
return chainSlugs.map((chainSlug) => chain[chainSlug]); | ||
}; |
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,27 @@ | ||
import { getContractAddress } from "./getContractAddress"; | ||
|
||
describe("getContractAddress", () => { | ||
const env = process.env; | ||
|
||
it("should get default contract address", () => { | ||
process.env = { ...env, NEXT_PUBLIC_CONTRACT_ADDRESS: "" }; | ||
expect(getContractAddress()).toBe( | ||
"0xe584409f2ba1ade9895485d90587fd46baa3c0d8" | ||
); | ||
}); | ||
|
||
it("should get contract address from env when set", () => { | ||
process.env = { | ||
...env, | ||
NEXT_PUBLIC_CONTRACT_ADDRESS: | ||
"0x5FbDB2315678afecb367f032d93F642f64180aa3", | ||
}; | ||
expect(getContractAddress()).toBe( | ||
"0x5FbDB2315678afecb367f032d93F642f64180aa3" | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = env; | ||
}); | ||
}); |
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,5 @@ | ||
export const getContractAddress = (): string => { | ||
return process.env.NEXT_PUBLIC_CONTRACT_ADDRESS | ||
? process.env.NEXT_PUBLIC_CONTRACT_ADDRESS | ||
: "0xe584409f2ba1ade9895485d90587fd46baa3c0d8"; | ||
}; |
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,27 @@ | ||
import { getSubgraphURL } from "./getSubgraphURL"; | ||
|
||
describe("getSubgraphURL", () => { | ||
const env = process.env; | ||
|
||
it("should get default graph host", () => { | ||
process.env = { ...env, NEXT_PUBLIC_SUBGRAPH_URL: "" }; | ||
expect(getSubgraphURL()).toBe( | ||
"https://api.thegraph.com/subgraphs/name/holic/example-nft" | ||
); | ||
}); | ||
|
||
it("should get graph host from env when set", () => { | ||
process.env = { | ||
...env, | ||
NEXT_PUBLIC_SUBGRAPH_URL: | ||
"http://127.0.0.1:8000/subgraphs/name/holic/example-nft", | ||
}; | ||
expect(getSubgraphURL()).toBe( | ||
"http://127.0.0.1:8000/subgraphs/name/holic/example-nft" | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = env; | ||
}); | ||
}); |
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,5 @@ | ||
export const getSubgraphURL = (): string => { | ||
return process.env.NEXT_PUBLIC_SUBGRAPH_URL | ||
? process.env.NEXT_PUBLIC_SUBGRAPH_URL | ||
: "https://api.thegraph.com/subgraphs/name/holic/example-nft"; | ||
}; |
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,24 @@ | ||
specVersion: 0.0.4 | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum | ||
name: ExampleNFT | ||
network: foundry | ||
source: | ||
abi: ExampleNFT | ||
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3" | ||
startBlock: 0 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.5 | ||
language: wasm/assemblyscript | ||
entities: | ||
- NFT | ||
abis: | ||
- name: ExampleNFT | ||
file: ../contracts/out/ExampleNFT.sol/ExampleNFT.abi.json | ||
eventHandlers: | ||
- event: Transfer(indexed address,indexed address,indexed uint256) | ||
handler: handleTransfer | ||
file: ./src/mapping.ts |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to figure out a good way of allowing the chain to be specified here. 🤔