diff --git a/test/HubPoolClient.DepositToDestinationToken.ts b/test/HubPoolClient.DepositToDestinationToken.ts index 2273ac91..2210422e 100644 --- a/test/HubPoolClient.DepositToDestinationToken.ts +++ b/test/HubPoolClient.DepositToDestinationToken.ts @@ -1,6 +1,8 @@ import { Event } from "ethers"; import { CONFIG_STORE_VERSION, + destinationChainId, + originChainId, randomDestinationToken, randomDestinationToken2, randomL1Token, @@ -12,11 +14,9 @@ import { SignerWithAddress, createSpyLogger, deployConfigStore, - destinationChainId, ethers, expect, getContractFactory, - originChainId, zeroAddress, } from "./utils"; diff --git a/test/HubPoolClient.Utilization.ts b/test/HubPoolClient.Utilization.ts index 01eddbd2..d7359d89 100644 --- a/test/HubPoolClient.Utilization.ts +++ b/test/HubPoolClient.Utilization.ts @@ -1,8 +1,9 @@ import { amountToLp, + originChainId, + repaymentChainId, destinationChainId, mockTreeRoot, - randomAddress, refundProposalLiveness, totalBond, } from "./constants"; @@ -20,8 +21,7 @@ import { expect, hubPoolFixture, mineRandomBlocks, - originChainId, - repaymentChainId, + randomAddress, setupTokensForWallet, toBN, toBNWei, diff --git a/test/SpokePoolClient.DepositRoutes.ts b/test/SpokePoolClient.DepositRoutes.ts index 6fd57feb..998e0f37 100644 --- a/test/SpokePoolClient.DepositRoutes.ts +++ b/test/SpokePoolClient.DepositRoutes.ts @@ -1,16 +1,6 @@ -import { - Contract, - createSpyLogger, - deploySpokePool, - destinationChainId, - enableRoutes, - ethers, - expect, - originChainId, - randomAddress, -} from "./utils"; - import { SpokePoolClient } from "../src/clients"; // tested +import { originChainId, destinationChainId } from "./constants"; +import { Contract, createSpyLogger, deploySpokePool, enableRoutes, ethers, expect, randomAddress } from "./utils"; let spokePool: Contract; diff --git a/test/SpokePoolClient.SpeedUp.ts b/test/SpokePoolClient.SpeedUp.ts index 02d37ad6..54b0e5a2 100644 --- a/test/SpokePoolClient.SpeedUp.ts +++ b/test/SpokePoolClient.SpeedUp.ts @@ -1,4 +1,4 @@ -import { depositRelayerFeePct, destinationChainId, modifyRelayHelper } from "./constants"; +import { depositRelayerFeePct, destinationChainId, originChainId } from "./constants"; import { Contract, SignerWithAddress, @@ -8,7 +8,7 @@ import { enableRoutes, ethers, expect, - originChainId, + modifyRelayHelper, setupTokensForWallet, simpleDeposit, toBNWei, diff --git a/test/SpokePoolClient.ValidateFill.ts b/test/SpokePoolClient.ValidateFill.ts index e6294d85..96ebbc9d 100644 --- a/test/SpokePoolClient.ValidateFill.ts +++ b/test/SpokePoolClient.ValidateFill.ts @@ -8,6 +8,7 @@ import { validateFillForDeposit, queryHistoricalDepositForFill, } from "../src/utils"; +import { CHAIN_ID_TEST_LIST, originChainId, destinationChainId, repaymentChainId } from "./constants"; import { assert, expect, @@ -23,8 +24,6 @@ import { buildModifiedFill, deploySpokePoolWithToken, Contract, - originChainId, - destinationChainId, createSpyLogger, zeroAddress, deployAndConfigureHubPool, @@ -38,7 +37,6 @@ import { winston, lastSpyLogIncludes, } from "./utils"; -import { CHAIN_ID_TEST_LIST, repaymentChainId } from "./constants"; import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient } from "./mocks"; let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract, hubPool: Contract; diff --git a/test/SpokePoolClient.deposits.ts b/test/SpokePoolClient.deposits.ts index 224a0929..d3b1b18f 100644 --- a/test/SpokePoolClient.deposits.ts +++ b/test/SpokePoolClient.deposits.ts @@ -1,15 +1,14 @@ import { SpokePoolClient } from "../src/clients"; import { Deposit } from "../src/interfaces"; +import { originChainId, destinationChainId } from "./constants"; import { Contract, SignerWithAddress, buildFill, createSpyLogger, deploySpokePoolWithToken, - destinationChainId, ethers, expect, - originChainId, setupTokensForWallet, toBNWei, } from "./utils"; diff --git a/test/SpokePoolClient.fills.ts b/test/SpokePoolClient.fills.ts index 8661d200..b34425f0 100644 --- a/test/SpokePoolClient.fills.ts +++ b/test/SpokePoolClient.fills.ts @@ -3,6 +3,7 @@ import { ZERO_ADDRESS, EMPTY_MESSAGE } from "../src/constants"; import { SpokePoolClient } from "../src/clients"; import { Deposit, V3Deposit } from "../src/interfaces"; import { bnOne, findFillBlock, getCurrentTime, getNetworkName } from "../src/utils"; +import { originChainId, destinationChainId } from "./constants"; import { assertPromiseError, Contract, @@ -11,10 +12,8 @@ import { fillV3Relay, createSpyLogger, deploySpokePoolWithToken, - destinationChainId, ethers, expect, - originChainId, setupTokensForWallet, toBNWei, } from "./utils"; diff --git a/test/SpokePoolClient.v3Events.ts b/test/SpokePoolClient.v3Events.ts index 2e78fcfd..fe31dde3 100644 --- a/test/SpokePoolClient.v3Events.ts +++ b/test/SpokePoolClient.v3Events.ts @@ -39,10 +39,10 @@ import { hubPoolFixture, deploySpokePool, ethers, - contractsV2Utils, + modifyRelayHelper, + SignerWithAddress, toBNWei, } from "./utils"; -import { modifyRelayHelper } from "./constants"; type EventSearchConfig = sdkUtils.EventSearchConfig; @@ -53,7 +53,7 @@ describe("SpokePoolClient: Event Filtering", function () { const filledRelayEvents = ["FilledRelay", "FilledV3Relay"]; const executedRelayerRefundEvents = ["ExecutedRelayerRefundRoot", "ExecutedV3RelayerRefundRoot"]; - let owner: contractsV2Utils.SignerWithAddress, depositor: contractsV2Utils.SignerWithAddress; + let owner: SignerWithAddress, depositor: SignerWithAddress; let chainIds: number[]; let originChainId: number, destinationChainId: number, repaymentChainId: number; let hubPoolClient: MockHubPoolClient; diff --git a/test/constants.ts b/test/constants.ts index 843d5ce7..172c07a0 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -1,11 +1,22 @@ +import * as contracts from "@across-protocol/contracts-v2/dist/test-utils"; // Contains all the Across contract constants. import { DEFAULT_CONFIG_STORE_VERSION } from "./mocks"; -import { destinationChainId, originChainId, randomAddress, repaymentChainId, toWei } from "./utils"; +export const { + amountToDeposit, + amountToLp, + depositRelayerFeePct, + originChainId, + destinationChainId, + repaymentChainId, + mockTreeRoot, + refundProposalLiveness, + totalBond, +} = contracts; export const CONFIG_STORE_VERSION = DEFAULT_CONFIG_STORE_VERSION; -export const randomL1Token = randomAddress(); -export const randomOriginToken = randomAddress(); -export const randomDestinationToken = randomAddress(); -export const randomDestinationToken2 = randomAddress(); +export const randomL1Token = contracts.randomAddress(); +export const randomOriginToken = contracts.randomAddress(); +export const randomDestinationToken = contracts.randomAddress(); +export const randomDestinationToken2 = contracts.randomAddress(); // Max number of refunds in relayer refund leaf for a { repaymentChainId, L2TokenAddress }. export const MAX_REFUNDS_PER_RELAYER_REFUND_LEAF = 3; @@ -15,14 +26,12 @@ export const MAX_L1_TOKENS_PER_POOL_REBALANCE_LEAF = 3; // DAI's Rate model. export const sampleRateModel = { - UBar: toWei(0.8).toString(), - R0: toWei(0.04).toString(), - R1: toWei(0.07).toString(), - R2: toWei(0.75).toString(), + UBar: contracts.toWei(0.8).toString(), + R0: contracts.toWei(0.04).toString(), + R1: contracts.toWei(0.07).toString(), + R2: contracts.toWei(0.75).toString(), }; // Add Mainnet chain ID 1 to the chain ID list because the dataworker uses this chain to look up latest GlobalConfig // updates for config variables like MAX_REFUND_COUNT_FOR_RELAYER_REPAYMENT_LEAF. export const CHAIN_ID_TEST_LIST = [originChainId, destinationChainId, repaymentChainId, 1]; - -export * from "@across-protocol/contracts-v2/dist/test-utils"; // Contains all the Across contract constants. diff --git a/test/fixtures/UmaEcosystemFixture.ts b/test/fixtures/UmaEcosystemFixture.ts index 35dc6d10..e9f4ebd4 100644 --- a/test/fixtures/UmaEcosystemFixture.ts +++ b/test/fixtures/UmaEcosystemFixture.ts @@ -1,7 +1,6 @@ -import * as utils from "@across-protocol/contracts-v2/dist/test-utils"; -import { Contract } from "ethers"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { utf8ToHex, identifier, refundProposalLiveness } from "@across-protocol/contracts-v2/dist/test-utils"; +import { identifier } from "@across-protocol/contracts-v2/dist/test-utils"; +import { refundProposalLiveness } from "../constants"; +import { Contract, getContractFactory, SignerWithAddress, utf8ToHex } from "../utils"; export async function setupUmaEcosystem(owner: SignerWithAddress): Promise<{ timer: Contract; @@ -11,18 +10,18 @@ export async function setupUmaEcosystem(owner: SignerWithAddress): Promise<{ }> { // Setup minimum UMA ecosystem contracts. Note that we don't use the umaEcosystemFixture because Hardhat Fixture's // seem to produce non-deterministic behavior between tests. - const timer = await (await utils.getContractFactory("Timer", owner)).deploy(); - const finder = await (await utils.getContractFactory("Finder", owner)).deploy(); - const identifierWhitelist = await (await utils.getContractFactory("IdentifierWhitelist", owner)).deploy(); + const timer = await (await getContractFactory("Timer", owner)).deploy(); + const finder = await (await getContractFactory("Finder", owner)).deploy(); + const identifierWhitelist = await (await getContractFactory("IdentifierWhitelist", owner)).deploy(); const mockOracle = await ( - await utils.getContractFactory("MockOracleAncillary", owner) + await getContractFactory("MockOracleAncillary", owner) ).deploy(finder.address, timer.address); const optimisticOracle = await ( - await utils.getContractFactory("SkinnyOptimisticOracle", owner) + await getContractFactory("SkinnyOptimisticOracle", owner) ).deploy(refundProposalLiveness, finder.address, timer.address); - const collateralWhitelist = await (await utils.getContractFactory("AddressWhitelist", owner)).deploy(); + const collateralWhitelist = await (await getContractFactory("AddressWhitelist", owner)).deploy(); const store = await ( - await utils.getContractFactory("Store", owner) + await getContractFactory("Store", owner) ).deploy({ rawValue: "0" }, { rawValue: "0" }, timer.address); await finder.changeImplementationAddress(utf8ToHex("CollateralWhitelist"), collateralWhitelist.address); await finder.changeImplementationAddress(utf8ToHex("IdentifierWhitelist"), identifierWhitelist.address); diff --git a/test/utils/index.ts b/test/utils/index.ts index f71a332d..0c005d04 100644 --- a/test/utils/index.ts +++ b/test/utils/index.ts @@ -1,12 +1,8 @@ -export * from "@across-protocol/contracts-v2/dist/test-utils"; +export * as contractsV2Utils from "@across-protocol/contracts-v2/dist/test-utils"; +export { ethers } from "hardhat"; +export { smock } from "@defi-wonderland/smock"; export * from "./utils"; export * from "./BlockchainUtils"; export * from "./SpokePoolUtils"; export * from "./SpyTransport"; - -export { smock } from "@defi-wonderland/smock"; - -export { ethers } from "hardhat"; - -export * as contractsV2Utils from "@across-protocol/contracts-v2/dist/test-utils"; diff --git a/test/utils/utils.ts b/test/utils/utils.ts index d273b333..ad5ab2d1 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -1,5 +1,5 @@ import * as utils from "@across-protocol/contracts-v2/dist/test-utils"; -import { BigNumberish, providers } from "ethers"; +import { BigNumber, BigNumberish, Contract, providers } from "ethers"; import { AcrossConfigStoreClient as ConfigStoreClient, GLOBAL_CONFIG_STORE_KEYS, @@ -15,19 +15,17 @@ import { resolveContractFromSymbol, toBN, toBNWei, + toWei, utf8ToHex, } from "../../src/utils"; import { - MAX_L1_TOKENS_PER_POOL_REBALANCE_LEAF, - MAX_REFUNDS_PER_RELAYER_REFUND_LEAF, amountToDeposit, depositRelayerFeePct, + destinationChainId as defaultDestinationChainId, + MAX_L1_TOKENS_PER_POOL_REBALANCE_LEAF, + MAX_REFUNDS_PER_RELAYER_REFUND_LEAF, sampleRateModel, - zeroAddress, } from "../constants"; -import { BigNumber, Contract, SignerWithAddress } from "./index"; -export { sinon, winston }; - import { AcrossConfigStore } from "@across-protocol/contracts-v2"; import chai, { expect } from "chai"; import chaiExclude from "chai-exclude"; @@ -39,9 +37,25 @@ import { EMPTY_MESSAGE, PROTOCOL_DEFAULT_CHAIN_ID_INDICES } from "../../src/cons import { SpyTransport } from "./SpyTransport"; chai.use(chaiExclude); - const assert = chai.assert; -export { assert, chai }; + +export type SignerWithAddress = utils.SignerWithAddress; + +export const { + buildPoolRebalanceLeafTree, + buildPoolRebalanceLeaves, + deploySpokePool, + depositV2, + enableRoutes, + getContractFactory, + getDepositParams, + hubPoolFixture, + modifyRelayHelper, + randomAddress, + zeroAddress, +} = utils; + +export { assert, BigNumber, expect, chai, Contract, sinon, toBN, toBNWei, toWei, utf8ToHex, winston }; const TokenRolesEnum = { OWNER: "0", @@ -230,9 +244,9 @@ export async function simpleDeposit( token: utils.Contract, recipient: utils.SignerWithAddress, depositor: utils.SignerWithAddress, - destinationChainId: number = utils.destinationChainId, - amountToDeposit: utils.BigNumber = utils.amountToDeposit, - depositRelayerFeePct: utils.BigNumber = utils.depositRelayerFeePct + destinationChainId = defaultDestinationChainId, + amount = amountToDeposit, + relayerFeePct = depositRelayerFeePct ): Promise { const depositObject = await utils.depositV2( spokePool, @@ -240,8 +254,8 @@ export async function simpleDeposit( recipient, depositor, destinationChainId, - amountToDeposit, - depositRelayerFeePct + amount, + relayerFeePct ); // Sanity Check: Ensure that the deposit was successful. expect(depositObject).to.not.be.null; @@ -449,8 +463,8 @@ export async function buildDeposit( tokenToDeposit: Contract, recipientAndDepositor: SignerWithAddress, destinationChainId: number, - _amountToDeposit: BigNumber = amountToDeposit, - relayerFeePct: BigNumber = depositRelayerFeePct + _amountToDeposit = amountToDeposit, + relayerFeePct = depositRelayerFeePct ): Promise { const _deposit = await utils.depositV2( spokePool, @@ -692,8 +706,8 @@ export function buildDepositForRelayerFeeTest( return { amount: toBN(amount), depositId: bnUint32Max.toNumber(), - depositor: utils.randomAddress(), - recipient: utils.randomAddress(), + depositor: randomAddress(), + recipient: randomAddress(), relayerFeePct: bnZero, message: EMPTY_MESSAGE, originChainId: 1, diff --git a/test/validatorUtils.test.ts b/test/validatorUtils.test.ts index ecc00588..b56b5ff5 100644 --- a/test/validatorUtils.test.ts +++ b/test/validatorUtils.test.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import { utils, interfaces } from "../src"; import { ZERO_ADDRESS } from "../src/constants"; -import { toBN } from "@across-protocol/contracts-v2"; +import { randomAddress, toBN } from "./utils"; import { cloneDeep } from "lodash"; import { objectWithBigNumberReviver } from "../src/utils"; import { Deposit } from "../src/interfaces"; @@ -39,7 +39,7 @@ describe("validatorUtils", () => { // We should be able to return true for the default deposit expect(utils.isDepositFormedCorrectly(deposit)).to.be.true; // Let's change the recipient to a valid address - deposit.recipient = utils.randomAddress(); + deposit.recipient = randomAddress(); expect(utils.isDepositFormedCorrectly(deposit)).to.be.true; }); it("should return false if deposit is not close to being formed correctly", () => {