-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend transports for public clients (#44)
* extend transports for public clients * add test
- Loading branch information
1 parent
01b35b8
commit a086a2f
Showing
5 changed files
with
69 additions
and
16 deletions.
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
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 @@ | ||
import { AcrossClient } from "../../src/client"; | ||
import { hardhat } from "viem/chains"; | ||
|
||
export const testSDK = AcrossClient.create({ | ||
useTestnet: true, | ||
logLevel: "WARN", | ||
chains: [hardhat], | ||
}); |
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,46 @@ | ||
import { arbitrum, mainnet, optimism, polygon } from "viem/chains"; | ||
import { describe, expect, test } from "vitest"; | ||
import { configurePublicClients } from "../../src"; | ||
|
||
const chains = [...[mainnet, optimism, polygon, arbitrum]]; | ||
|
||
const webSocketArgs: Parameters<typeof configurePublicClients> = [ | ||
chains, | ||
undefined, | ||
{ | ||
[mainnet.id]: "wss://eth-mainnet.g.alchemy.com/v2/123abc123abc", | ||
[optimism.id]: "wss://opt-mainnet.g.alchemy.com/v2/123abc123abc", | ||
[polygon.id]: "wss://polygon-mainnet.g.alchemy.com/v2/123abc123abc", | ||
[arbitrum.id]: "wss://arb-mainnet.g.alchemy.com/v2/123abc123abc", | ||
}, | ||
]; | ||
|
||
const httpArgs: Parameters<typeof configurePublicClients> = [ | ||
chains, | ||
undefined, | ||
{ | ||
[mainnet.id]: "https://eth-mainnet.g.alchemy.com/v2/123abc123abc", | ||
[optimism.id]: "https://opt-mainnet.g.alchemy.com/v2/123abc123abc", | ||
[polygon.id]: "https://polygon-mainnet.g.alchemy.com/v2/123abc123abc", | ||
[arbitrum.id]: "https://arb-mainnet.g.alchemy.com/v2/123abc123abc", | ||
}, | ||
]; | ||
|
||
const webSocketClientsMap = configurePublicClients(...webSocketArgs); | ||
const httpClientsMap = configurePublicClients(...httpArgs); | ||
|
||
describe("Initializes Clients correctly", () => { | ||
test("Resolves web socket url as expected", () => { | ||
const mainnetTransport = webSocketClientsMap.get(mainnet.id); | ||
expect(mainnetTransport).to.not.be.undefined; | ||
const transportType = mainnetTransport?.transport.type; | ||
expect(transportType).toBe("webSocket"); | ||
}); | ||
|
||
test("Resolves http url as expected", () => { | ||
const mainnetTransport = httpClientsMap.get(mainnet.id); | ||
expect(mainnetTransport).to.not.be.undefined; | ||
const transportType = mainnetTransport?.transport.type; | ||
expect(transportType).toBe("http"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,30 +1,23 @@ | ||
import { expect, test, vi } from "vitest"; | ||
import { AcrossClient } from "../../src/client"; | ||
import { hardhat } from "viem/chains"; | ||
|
||
const client = AcrossClient.create({ | ||
useTestnet: true, | ||
logLevel: "WARN", | ||
chains: [hardhat], | ||
}); | ||
import { testSDK } from "./_utils"; | ||
|
||
test("Higher severity is logged", () => { | ||
const consoleLogSpy = vi.spyOn(console, "log"); | ||
client.logger.error("Should be logged"); | ||
testSDK.logger.error("Should be logged"); | ||
|
||
expect(consoleLogSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
test("Equal severity is logged", () => { | ||
const consoleLogSpy = vi.spyOn(console, "log"); | ||
client.logger.warn("Should be logged"); | ||
testSDK.logger.warn("Should be logged"); | ||
|
||
expect(consoleLogSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
test("Lower severity is not logged", () => { | ||
const consoleLogSpy = vi.spyOn(console, "log"); | ||
client.logger.debug("Should not be logged"); | ||
testSDK.logger.debug("Should not be logged"); | ||
|
||
expect(consoleLogSpy).not.toHaveBeenCalled(); | ||
}); |