Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix(test): remove websocket hanging test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Sep 1, 2022
1 parent 31300ed commit a6f31d8
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions test/index.spec.ts
Expand Up @@ -5,11 +5,8 @@ import { EthersMulticall, MULTICALL_ADDRESSES } from "../src";
import MorphoAbi from "./abis/Morpho.json";
import UniswapAbi from "./abis/Uni.json";

const rpcProvider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/eth");
const rpcBatchProvider = new ethers.providers.JsonRpcBatchProvider("https://rpc.ankr.com/eth");
const wsProvider = new ethers.providers.WebSocketProvider(
"wss://eth-mainnet.nodereal.io/ws/v1/1659dfb40aa24bbb8153a677b98064d7"
);
const httpRpcUrl = "https://rpc.ankr.com/eth";
const rpcProvider = new ethers.providers.JsonRpcProvider(httpRpcUrl, 1);

const _morpho = new ethers.Contract("0x8888882f8f843896699869179fB6E4f7e3B58888", MorphoAbi);
const _uni = new ethers.Contract("0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", UniswapAbi);
Expand All @@ -29,6 +26,7 @@ describe("index", () => {
});

it("should work given a JsonRpcBatchProvider", async () => {
const rpcBatchProvider = new ethers.providers.JsonRpcBatchProvider(httpRpcUrl, 1);
const multicall = new EthersMulticall(rpcBatchProvider);

expect(multicall.contract.provider).toBe(rpcBatchProvider);
Expand All @@ -39,33 +37,24 @@ describe("index", () => {
expect(wrappedMorpho.address).toBe(_morpho.address);
expect(await wrappedMorpho.cEth()).toBe("0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5");
});

it("should work given a WebSocketProvider", async () => {
const multicall = new EthersMulticall(wsProvider);

expect(multicall.contract.provider).toBe(wsProvider);
expect(multicall.contract.address).toBe(MULTICALL_ADDRESSES[1]);

const wrappedMorpho = multicall.wrap(_morpho);

expect(wrappedMorpho.address).toBe(_morpho.address);
expect(await wrappedMorpho.cEth()).toBe("0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5");
});
});

describe("Calls batching", () => {
it("should batch UNI calls", async () => {
const multicall = new EthersMulticall(wsProvider);
const multicall = new EthersMulticall(rpcProvider);
const wrappedUni = multicall.wrap(_uni);

jest.spyOn(wsProvider, "send").mockImplementation(async () => "");
const send = rpcProvider.send.bind(rpcProvider);

jest
.spyOn(rpcProvider, "send")
.mockImplementation(async (method, ...args) => send(method, ...args));

try {
await Promise.all([wrappedUni.name(), wrappedUni.symbol(), wrappedUni.decimals()]);
} catch {}
await Promise.all([wrappedUni.name(), wrappedUni.symbol(), wrappedUni.decimals()]);

expect(wsProvider.send).toBeCalledTimes(1);
expect(wsProvider.send).toBeCalledWith("eth_call", [
expect(rpcProvider.send).toBeCalledTimes(2);
expect(rpcProvider.send).toBeCalledWith("eth_chainId", []);
expect(rpcProvider.send).toBeCalledWith("eth_call", [
{
data: "0x17352e13000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001600000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000406fdde03000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000495d89b41000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004313ce56700000000000000000000000000000000000000000000000000000000",
to: "0x5eb3fa2dfecdde21c950813c665e9364fa609bd2",
Expand Down

0 comments on commit a6f31d8

Please sign in to comment.