Skip to content

Commit 3e3b5a3

Browse files
committed
address comments
1 parent db125ae commit 3e3b5a3

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Up-to-date documentation on Chainlink Functions can be found [here](https://docs
3838

3939
Install Node.js version `18.18.0` or higher _and_ Deno version `1.36.0` or higher.
4040

41-
Starting from ABOVE 0.3.2, Anvil is required to run local tests. A `Makefile` is included to automate the installation and build process. Simply run `make install` to install Anvil and all npm packages.
41+
For version 0.3.2 and above of this functions-toolkit package, Anvil is required to run local tests. A `Makefile` is included to automate the installation and build process. Simply run `make install` to install Anvil and all npm packages.
42+
If you already have anvil and/or foundry (the Foundry toolchain) installed, you would not need to run this. But you may want to run `foundryup` to update your version and `npm install` to install packages.
4243

4344
Chainlink Functions requires signing a terms of service agreement before creating a billing subscription. See this [getting started](https://docs.chain.link/chainlink-functions/getting-started) section in the docs.
4445

@@ -596,7 +597,7 @@ return Functions.encodeString(escape("$hello*world?"));
596597
### Local Functions Testnet
597598

598599
> **Note**
599-
> Starting from above 0.3.2, Anvil is REQUIRED to use `localFunctionsTestnet`. Please run `make install` to install Anvil and all the necessary dependencies.
600+
> For version 0.3.2 and above of this functions-toolkit package, Anvil is REQUIRED to use `localFunctionsTestnet`. Please run `make install` to install Anvil and all the necessary dependencies. If you already have anvil and/or foundry (the Foundry toolchain) installed, you would not need to run this. But you may want to run `foundryup` to update your version and `npm install` to install packages.
600601
601602
For debugging smart contracts and the end-to-end request flow on your local machine, you can use the `localFunctionsTestnet` function. This creates a local testnet RPC node with a mock Chainlink Functions contracts. You can then deploy your own Functions consumer contract to this local network, create and manage subscriptions, and send requests. Request processing will simulate the behavior of an actual DON where the request is executed 4 times and the discrete median response is transmitted back to the consumer contract. (Note that Chainlink Functions uses the following calculation to select the discrete median response: `const medianResponse = responses[responses.length - 1) / 2]`).
602603

src/localFunctionsTestnet.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,26 @@ export const startLocalFunctionsTestnet = async (
3737
simulationConfigPath?: string,
3838
port = 8545,
3939
): Promise<LocalFunctionsTestnet> => {
40-
const anvil = createAnvil({
41-
port,
42-
chainId: 1337,
43-
})
40+
let anvil: any
41+
try {
42+
anvil = createAnvil({
43+
port,
44+
chainId: 1337,
45+
})
46+
} catch (error) {
47+
console.error('Error creating Anvil instance: ', error)
48+
console.error(
49+
'Please refer to README about how to properly set up the environment, including anvil.',
50+
)
51+
throw error
52+
}
4453

4554
await anvil.start()
4655
console.log(`Anvil started on port ${port} with chain ID 1337`)
4756

4857
let privateKey = process.env.PRIVATE_KEY
4958
if (!privateKey) {
50-
// this is a private key provided by anvil
59+
// this is a hardcoded private key provided by anvil
5160
privateKey = 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
5261
}
5362

test/utils/index.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,17 @@ const createTestWallets = (port = 8545): Wallet[] => {
7474
const wallets: Wallet[] = []
7575
const provider = new providers.JsonRpcProvider(`http://127.0.0.1:${port}`)
7676

77-
// these are random private keys provided by anvil
78-
wallets.push(
79-
new Wallet('59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d').connect(
80-
provider,
81-
),
82-
)
83-
wallets.push(
84-
new Wallet('5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a').connect(
85-
provider,
86-
),
87-
)
88-
wallets.push(
89-
new Wallet('7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6').connect(
90-
provider,
91-
),
92-
)
77+
// these are hardcoded private keys provided by anvil. you can see these private keys in the console output if you simply run `anvil`
78+
// using these makes sure that these wallets are properly connected to Anvil local node
79+
const privateKeys = [
80+
'59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',
81+
'5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',
82+
'7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6',
83+
]
84+
85+
for (const privateKey of privateKeys) {
86+
wallets.push(new Wallet(privateKey).connect(provider))
87+
}
9388

9489
return wallets
9590
}

0 commit comments

Comments
 (0)