Skip to content

Commit 8e97853

Browse files
committed
replace ganache with anvil
1 parent ff0de2b commit 8e97853

File tree

6 files changed

+78
-256
lines changed

6 files changed

+78
-256
lines changed

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"test:package": "jest --config jest.config.package.js",
1313
"lint:check": "eslint '{src,test}/**/*.ts' && tsc --noEmit",
1414
"lint:fix": "eslint '{src,test}/**/*.ts' --fix",
15-
"lint:ci": "eslint '{src,test}/**/*.ts' --max-warnings=0 -f json -o eslint-report.json"
15+
"lint:ci": "eslint '{src,test}/**/*.ts' --max-warnings=0 -f json -o eslint-report.json",
16+
"anvil": "anvil --port 8545 --chain-id 900000001"
1617
},
1718
"repository": {
1819
"type": "git",
@@ -42,15 +43,15 @@
4243
"@types/jest": "^29.5.1",
4344
"@types/node": "^18.16.3",
4445
"@types/prettier": "^2.7.3",
45-
"babel-loader": "9.1.2",
46-
"browserify": "17.0.0",
4746
"@typescript-eslint/eslint-plugin": "^6.7.5",
4847
"@typescript-eslint/parser": "^6.7.5",
48+
"babel-loader": "9.1.2",
49+
"browserify": "17.0.0",
4950
"cpy-cli": "^5.0.0",
50-
"esmify": "2.1.1",
5151
"eslint": "^8.51.0",
5252
"eslint-config-prettier": "^9.0.0",
5353
"eslint-plugin-prettier": "^5.0.1",
54+
"esmify": "2.1.1",
5455
"jest": "^29.5.0",
5556
"nock": "^13.3.1",
5657
"prettier": "^3.0.3",
@@ -72,12 +73,12 @@
7273
"proseWrap": "preserve"
7374
},
7475
"dependencies": {
76+
"@ethersproject/abstract-provider": "^5.7.0",
7577
"axios": "^1.4.0",
7678
"bcrypto": "^5.4.0",
7779
"cbor": "^9.0.1",
7880
"eth-crypto": "^2.6.0",
7981
"ethers": "^5.7.2",
80-
"ganache": "^7.9.1",
8182
"uniq": "^1.0.1"
8283
}
8384
}

src/localFunctionsTestnet.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Wallet, Contract, ContractFactory, utils, providers } from 'ethers'
2-
import Ganache from 'ganache'
2+
// import Ganache from 'ganache'
33
import cbor from 'cbor'
44

55
import { simulateScript } from './simulateScript'
@@ -24,7 +24,7 @@ import {
2424
TermsOfServiceAllowListSource,
2525
} from './v1_contract_sources'
2626

27-
import type { ServerOptions } from 'ganache'
27+
// import type { ServerOptions } from 'ganache'
2828

2929
import type {
3030
FunctionsRequestParams,
@@ -37,22 +37,26 @@ import type {
3737

3838
export const startLocalFunctionsTestnet = async (
3939
simulationConfigPath?: string,
40-
options?: ServerOptions,
40+
// options?: ServerOptions,
4141
port = 8545,
4242
): Promise<LocalFunctionsTestnet> => {
43-
const server = Ganache.server(options)
43+
// const server = Ganache.server(options)
4444

45-
server.listen(port, 'localhost', (err: Error | null) => {
46-
if (err) {
47-
throw Error(`Error starting local Functions testnet server:\n${err}`)
48-
}
49-
console.log(`Local Functions testnet server started on port ${port}`)
50-
})
45+
// server.listen(port, 'localhost', (err: Error | null) => {
46+
// if (err) {
47+
// throw Error(`Error starting local Functions testnet server:\n${err}`)
48+
// }
49+
// console.log(`Local Functions testnet server started on port ${port}`)
50+
// })
51+
52+
// const randWallet = Wallet.createRandom()
53+
// const accounts = server.provider.getInitialAccounts()
54+
// const firstAccount = Object.keys(accounts)[0]
5155

52-
const accounts = server.provider.getInitialAccounts()
53-
const firstAccount = Object.keys(accounts)[0]
56+
// this is a private key provided by anvil
5457
const admin = new Wallet(
55-
accounts[firstAccount].secretKey.slice(2),
58+
// accounts[firstAccount].secretKey.slice(2),
59+
'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
5660
new providers.JsonRpcProvider(`http://localhost:${port}`),
5761
)
5862

@@ -124,11 +128,11 @@ export const startLocalFunctionsTestnet = async (
124128

125129
const close = async (): Promise<void> => {
126130
contracts.functionsMockCoordinatorContract.removeAllListeners('OracleRequest')
127-
await server.close()
131+
// await server.close()
128132
}
129133

130134
return {
131-
server,
135+
// server,
132136
adminWallet: {
133137
address: admin.address,
134138
privateKey: admin.privateKey,

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Overrides, Contract, providers } from 'ethers'
2-
import type { Server } from 'ganache'
2+
// import type { Server } from 'ganache'
33

44
export enum Location {
55
Inline = 0,
@@ -237,7 +237,7 @@ export type GetFunds = (
237237
) => Promise<void>
238238

239239
export type LocalFunctionsTestnet = {
240-
server: Server
240+
// server: Server
241241
adminWallet: {
242242
address: string
243243
privateKey: string

test/integration/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Functions toolkit classes', () => {
2727
let subFunder_A: Wallet
2828

2929
beforeAll(async () => {
30-
const testSetup = await setupLocalTestnetFixture(8001)
30+
const testSetup = await setupLocalTestnetFixture(8545)
3131
donId = testSetup.donId
3232
linkTokenContract = testSetup.linkTokenContract
3333
linkTokenAddress = testSetup.linkTokenAddress

test/utils/index.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Wallet, providers, ContractFactory, utils } from 'ethers'
88
import type { GetFunds } from '../../src'
99

1010
import type { Contract } from 'ethers'
11-
import type { Server } from 'ganache'
11+
// import type { Server } from 'ganache'
1212

1313
export const setupLocalTestnetFixture = async (
1414
port: number,
@@ -28,13 +28,13 @@ export const setupLocalTestnetFixture = async (
2828
}> => {
2929
const localFunctionsTestnet = await startLocalFunctionsTestnet(
3030
path.join(__dirname, 'testSimulationConfig.ts'),
31-
{
32-
logging: {
33-
debug: false,
34-
verbose: false,
35-
quiet: true,
36-
},
37-
},
31+
// {
32+
// logging: {
33+
// debug: false,
34+
// verbose: false,
35+
// quiet: true,
36+
// },
37+
// },
3838
port,
3939
)
4040

@@ -54,7 +54,7 @@ export const setupLocalTestnetFixture = async (
5454

5555
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5656
const [_admin, user_A, user_B_NoLINK, subFunder, _] = createTestWallets(
57-
localFunctionsTestnet.server,
57+
// localFunctionsTestnet.server,
5858
port,
5959
)
6060

@@ -82,15 +82,38 @@ export const setupLocalTestnetFixture = async (
8282
}
8383
}
8484

85-
const createTestWallets = (server: Server, port = 8545): Wallet[] => {
86-
const accounts = server.provider.getInitialAccounts()
85+
const createTestWallets = (port = 8545): Wallet[] => {
86+
// const accounts = server.provider.getInitialAccounts()
8787

8888
const wallets: Wallet[] = []
8989
const provider = new providers.JsonRpcProvider(`http://localhost:${port}`)
9090

91-
for (const addr of Object.keys(accounts)) {
92-
wallets.push(new Wallet(accounts[addr].secretKey.slice(2), provider))
93-
}
91+
// for (let i = 0; i < 4; i++) {
92+
// const randomWallet = Wallet.createRandom().connect(provider)
93+
// wallets.push(Wallet.createRandom().connect(provider))
94+
// }
95+
96+
// these are random private keys provided by anvil
97+
wallets.push(
98+
new Wallet('59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d').connect(
99+
provider,
100+
),
101+
)
102+
wallets.push(
103+
new Wallet('5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a').connect(
104+
provider,
105+
),
106+
)
107+
wallets.push(
108+
new Wallet('7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6').connect(
109+
provider,
110+
),
111+
)
112+
wallets.push(
113+
new Wallet('47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a').connect(
114+
provider,
115+
),
116+
)
94117

95118
return wallets
96119
}

0 commit comments

Comments
 (0)