|
| 1 | +require("dotenv").config(); |
| 2 | +import assert from "assert"; |
| 3 | +import * as Client from "./client"; |
| 4 | +import { ethers } from "ethers"; |
| 5 | +import { emp } from ".."; |
| 6 | + |
| 7 | +// multicall contract deployed to mainnet |
| 8 | +const address = "0x5ba1e12693dc8f9c48aad8770482f4739beed696"; |
| 9 | +const empAddress = "0x4E3168Ea1082f3dda1694646B5EACdeb572009F1"; |
| 10 | +// these require integration testing, skip for ci |
| 11 | +describe("multicall2", function () { |
| 12 | + let client: Client.Instance; |
| 13 | + let empClient: emp.Instance; |
| 14 | + |
| 15 | + test("inits", function () { |
| 16 | + const provider = ethers.providers.getDefaultProvider(process.env.CUSTOM_NODE_URL); |
| 17 | + client = Client.connect(address, provider); |
| 18 | + empClient = emp.connect(empAddress, provider); |
| 19 | + assert.ok(client); |
| 20 | + assert.ok(empClient); |
| 21 | + }); |
| 22 | + |
| 23 | + test("multicall2 on emp", async function () { |
| 24 | + const calls = ["priceIdentifier", "tokenCurrency", "collateralCurrency"]; |
| 25 | + const multicalls = calls.map((call: any) => { |
| 26 | + return { |
| 27 | + target: empAddress, |
| 28 | + callData: empClient.interface.encodeFunctionData(call), |
| 29 | + }; |
| 30 | + }); |
| 31 | + const response = await client.callStatic.aggregate(multicalls); |
| 32 | + const decoded = calls.map((call: any, i: number) => { |
| 33 | + const result = response.returnData[i]; |
| 34 | + return empClient.interface.decodeFunctionResult(call, result); |
| 35 | + }); |
| 36 | + assert.equal(decoded.length, calls.length); |
| 37 | + }); |
| 38 | + |
| 39 | + test("multicall2 on emp with no errors", async function () { |
| 40 | + const calls = ["priceIdentifier", "tokenCurrency", "collateralCurrency"]; |
| 41 | + const multicalls = calls.map((call: any) => { |
| 42 | + return { |
| 43 | + target: empAddress, |
| 44 | + callData: empClient.interface.encodeFunctionData(call), |
| 45 | + }; |
| 46 | + }); |
| 47 | + const response = await client.callStatic.tryBlockAndAggregate(false, multicalls); |
| 48 | + const decoded = calls.map((call: any, i: number) => { |
| 49 | + const result = response.returnData[i].returnData; |
| 50 | + return empClient.interface.decodeFunctionResult(call, result); |
| 51 | + }); |
| 52 | + assert.equal(decoded.length, calls.length); |
| 53 | + }); |
| 54 | + |
| 55 | + test("multicall2 on emp with errors", async function () { |
| 56 | + const calls = ["priceIdentifier", "tokenCurrency", "disputeBondPercentage"]; |
| 57 | + const multicalls = calls.map((call) => { |
| 58 | + return { |
| 59 | + target: empAddress, |
| 60 | + callData: empClient.interface.encodeFunctionData(call as any), |
| 61 | + }; |
| 62 | + }); |
| 63 | + const response = await client.callStatic.tryBlockAndAggregate(false, multicalls); |
| 64 | + const decoded = calls.map((call: any, i: number) => { |
| 65 | + const result = response.returnData[i].returnData; |
| 66 | + return response.returnData[i].success ? empClient.interface.decodeFunctionResult(call, result) : {}; |
| 67 | + }); |
| 68 | + assert.equal(decoded.length, calls.length); |
| 69 | + }); |
| 70 | +}); |
0 commit comments