Skip to content

Commit adafbac

Browse files
committed
Remove hardcoding of localhost to use server assigned loopback and port
1 parent 07924af commit adafbac

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/localFunctionsTestnet.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ export const startLocalFunctionsTestnet = async (
3939
options?: ServerOptions,
4040
port = 8545,
4141
): Promise<LocalFunctionsTestnet> => {
42+
let localhost
4243
const server = Ganache.server(options)
4344

44-
server.listen(port, 'localhost', (err: Error | null) => {
45+
server.listen(port, (err: Error | null) => {
4546
if (err) {
4647
throw Error(`Error starting local Functions testnet server:\n${err}`)
4748
}
48-
console.log(`Local Functions testnet server started on port ${port}`)
49+
const loopbackAddress = server.address().address
50+
const assignedPort = server.address().port
51+
localhost = `http://${loopbackAddress}:${assignedPort}`
52+
console.log(`Local Functions testnet server started at ${localhost}`)
4953
})
5054

5155
const accounts = server.provider.getInitialAccounts()
5256
const firstAccount = Object.keys(accounts)[0]
5357
const admin = new Wallet(
5458
accounts[firstAccount].secretKey.slice(2),
55-
new providers.JsonRpcProvider(`http://localhost:${port}`),
59+
new providers.JsonRpcProvider(localhost),
5660
)
5761

5862
const contracts = await deployFunctionsOracle(admin)

0 commit comments

Comments
 (0)