Skip to content

Commit

Permalink
use loadFixture to reduce unittest time
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhe8x committed Dec 13, 2023
1 parent 8096242 commit 09bfab3
Show file tree
Hide file tree
Showing 23 changed files with 438 additions and 351 deletions.
11 changes: 8 additions & 3 deletions test/ConsumerHost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { expect } from 'chai';
import { BigNumber, BigNumberish, BytesLike, Wallet } from 'ethers';
import { ethers } from 'hardhat';
import { ethers, waffle } from 'hardhat';
import {
ConsumerHost,
IndexerRegistry,
Expand Down Expand Up @@ -180,9 +180,14 @@ describe('ConsumerHost Contract', () => {
};
};

beforeEach(async () => {

const deployer = ()=>deployContracts(wallet_0, indexer);
before(async ()=>{
[wallet_0, indexer, consumer, consumer2, hoster] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, indexer);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
indexerRegistry = deployment.indexerRegistry;
staking = deployment.staking;
token = deployment.token;
Expand Down
9 changes: 7 additions & 2 deletions test/ConsumerRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ describe('ConsumerRegistry Contract', () => {
let consumerRegistry: ConsumerRegistry;
let consumerHost: ConsumerHost;

beforeEach(async () => {

const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1, wallet_2, wallet_3] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, wallet_1);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
consumerRegistry = deployment.consumerRegistry;
consumerHost = deployment.consumerHost;
});
Expand Down
9 changes: 7 additions & 2 deletions test/DisputeManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ describe('Dispute Manager Contract', () => {
let rewardsStaking: RewardsStaking;
let rewardsHelper: RewardsHelper;

beforeEach(async () => {

const deployer = ()=>deployContracts(root, root);
before(async ()=>{
[root, indexer, fisherman] = await ethers.getSigners();
const deployment = await deployContracts(root, root);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
disputeManager = deployment.disputeManager;
token = deployment.token;
staking = deployment.staking;
Expand Down
8 changes: 6 additions & 2 deletions test/EraManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ describe('Era Manager Contract', () => {
let wallet_0, wallet_1;
let eraManager: EraManager;

beforeEach(async () => {
const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, wallet_1);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
eraManager = deployment.eraManager;
});

Expand Down
10 changes: 7 additions & 3 deletions test/IndexerRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

import { expect } from 'chai';
import { ethers } from 'hardhat';
import { ethers, waffle } from 'hardhat';
import { IndexerRegistry, ProjectRegistry, RewardsStaking, ERC20, Staking, StakingManager } from '../src';
import { DEPLOYMENT_ID, METADATA_1_HASH, METADATA_HASH, VERSION } from './constants';
import { etherParse, registerIndexer } from './helper';
Expand All @@ -25,9 +25,13 @@ describe('IndexerRegistry Contract', () => {
expect(await indexerRegistry.getController(wallet_0.address)).to.equal(constants.ZERO_ADDRESS);
};

beforeEach(async () => {
const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1, wallet_2] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, wallet_1);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
token = deployment.token;
staking = deployment.staking;
stakingManager = deployment.stakingManager;
Expand Down
14 changes: 5 additions & 9 deletions test/InflationController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ describe('Inflation Controller Contract', () => {
.mul(inflationRate)
.div(PER_MILL * YEAR_SECONDS)
.mul(block.timestamp-lastInflationTimestamp.toNumber());

// const distance = expectValue.sub(newSupply).abs();
//
// // distance need to less the threshold, `0xDE0B6B3A7640000` -> `1e18`
// expect(distance.div(ethers.BigNumber.from('0xDE0B6B3A7640000'))).to.be.lt(
// ethers.BigNumber.from(inflationRate.toNumber() / 10)
// );
};

beforeEach(async () => {
const deployer = ()=>deployRootContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1, wallet_2] = await ethers.getSigners();
});

beforeEach(async () => {
inflationDestination = wallet_1.address;
const deployer = ()=>deployRootContracts(wallet_0, wallet_1);
const deployment = await waffle.loadFixture(deployer);
inflationController = deployment.inflationController;
polygonDestination = deployment.polygonDestination;
Expand Down
8 changes: 6 additions & 2 deletions test/Maintenance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ describe('Maintenance Mode Test', () => {
let purchaseOfferMarket: PurchaseOfferMarket;
let stakingManager: StakingManager;

before(async () => {
const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1, wallet_2] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, wallet_0);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
token = deployment.token;
settings = deployment.settings;
staking = deployment.staking;
Expand Down
13 changes: 10 additions & 3 deletions test/PlanManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { DEPLOYMENT_ID, METADATA_HASH, VERSION, deploymentIds, metadatas } from './constants';
import { Wallet, constants, deploySUSD, etherParse, eventFrom, registerIndexer, startNewEra, time } from './helper';
import { deployContracts } from './setup';
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";

describe('PlanManger Contract', () => {
const mockProvider = waffle.provider;
Expand All @@ -42,10 +43,16 @@ describe('PlanManger Contract', () => {
let priceOracle: PriceOracle;
let SUSD: Contract;

beforeEach(async () => {
const deployer = async ()=>{
SUSD = await deploySUSD(consumer as SignerWithAddress);
return deployContracts(indexer, consumer);
};
before(async ()=>{
[indexer, consumer] = await ethers.getSigners();
SUSD = await deploySUSD(consumer);
const deployment = await deployContracts(indexer, consumer);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
indexerRegistry = deployment.indexerRegistry;
projectRegistry = deployment.projectRegistry;
planManager = deployment.planManager;
Expand Down
9 changes: 7 additions & 2 deletions test/PriceOracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ describe('PriceOracle Contract', () => {
const assetTo = '0x0000000000000000000000000000000000000001';
const price = 100; // 1 assetA to 100 assetB

beforeEach(async () => {

const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1, wallet_2] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, wallet_1);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
priceOracle = deployment.priceOracle;
await priceOracle.setAssetPrice(assetFrom, assetTo, 1, price);
});
Expand Down
8 changes: 6 additions & 2 deletions test/ProjectRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ describe('Project Registry Contract', () => {
expect(await projectRegistry.tokenURI(tokenId)).to.equal(`ipfs://${uri}`);
}

beforeEach(async () => {
const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1] = await ethers.getSigners();
const deployment = await deployContracts(wallet_0, wallet_1);
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
token = deployment.token;
staking = deployment.staking;
indexerRegistry = deployment.indexerRegistry;
Expand Down
8 changes: 6 additions & 2 deletions test/PurchaseOfferMarket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ describe('Purchase Offer Market Contract', () => {
const planTemplateId = 0;
let offerId: BigNumber;

beforeEach(async () => {
const deployer = ()=>deployContracts(wallet_0, wallet_1);
before(async ()=>{
[wallet_0, wallet_1, wallet_2] = await ethers.getSigners();
});

beforeEach(async () => {
const deployment = await waffle.loadFixture(deployer);
futureDate = await futureTimestamp(mockProvider);
const deployment = await deployContracts(wallet_0, wallet_1);
purchaseOfferMarket = deployment.purchaseOfferMarket;
serviceAgreementRegistry = deployment.serviceAgreementRegistry;
indexerRegistry = deployment.indexerRegistry;
Expand Down
Loading

0 comments on commit 09bfab3

Please sign in to comment.