Skip to content

Commit

Permalink
chore: make async fn with no await an error (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris authored Oct 4, 2023
1 parent 9d1c568 commit ae9873c
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
ecmaVersion: "latest",
sourceType: "module",
project: "./tsconfig.lint.json",
include: ["./src/**/*.ts", "./test/**/*.ts", ".eslintrc.js"],
include: ["./src/**/*.ts", "./test/**/*.ts", ".eslintrc.js", "./e2e/**/*.ts"],
},
plugins: ["node", "prettier", "@typescript-eslint", "mocha", "chai-expect"],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion e2e/acrossConfigStore.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const wethAddress = ethers.utils.getAddress("0xc02aaa39b223fe8d0a0e5c4f27ead9083
describe("AcrossConfigStore", function () {
let provider: Provider;
let client: Client;
beforeEach(async () => {
beforeEach(() => {
provider = ethers.getDefaultProvider(process.env.NODE_URL_1);
client = new Client(configStoreAddress, provider);
});
Expand Down
4 changes: 2 additions & 2 deletions e2e/client.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("Client e2e tests", () => {
});

it("should fetch pending transfers from chain", async (done) => {
client.startFetchingTransfers("0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D");
await client.startFetchingTransfers("0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D");
client.on(TransfersHistoryEvent.TransfersUpdated, (data) => {
console.log(data);
const pendingTransfers = client.getPendingTransfers("0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D");
Expand All @@ -68,7 +68,7 @@ describe("Client e2e tests", () => {

it("should fetch all transfers", async (done) => {
let iteration = 0;
client.startFetchingTransfers("all");
await client.startFetchingTransfers("all");
client.on(TransfersHistoryEvent.TransfersUpdated, () => {
iteration++;
const pendingTransfers = client.getPendingTransfers("all");
Expand Down
4 changes: 2 additions & 2 deletions e2e/poolClient.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const endBlock = 30477298;
describe("PoolEventState", function () {
let provider: Provider;
let client: PoolEventState;
before(async () => {
before(() => {
provider = ethers.getDefaultProvider(process.env.CUSTOM_NODE_URL);
const instance = hubPool.connect(hubPoolAddress, provider);
client = new PoolEventState(instance, startBlock);
Expand All @@ -41,7 +41,7 @@ describe("PoolClient", function () {
const state = {};
let provider: Provider;
let client: Client;
before(async () => {
before(() => {
provider = ethers.getDefaultProvider(process.env.CUSTOM_NODE_URL);
client = new Client(
{
Expand Down
17 changes: 10 additions & 7 deletions e2e/priceClient.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ class TestBaseHTTPAdapter extends BaseHTTPAdapter {
super(name, host, { timeout, retries });
}

async _query(path: string, urlArgs?: object): Promise<unknown> {
_query(path: string, urlArgs?: object): Promise<unknown> {
return this.query(path, urlArgs);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected override async sleep(_ms: number): Promise<void> {
++this.nRetries;
protected override sleep(_ms: number): Promise<void> {
return new Promise((next) => {
++this.nRetries;
next();
});
}
}

Expand All @@ -47,12 +50,12 @@ class TestPriceFeed implements PriceFeedAdapter {
return tokenPrices[0];
}

async getPricesByAddress(addresses: string[], currency = "usd"): Promise<TokenPrice[]> {
getPricesByAddress(addresses: string[], currency = "usd"): Promise<TokenPrice[]> {
this.priceRequest = addresses;
const _addresses = addresses.map((address) => address.toLowerCase());

// Return each cached price that overlaps with the requested list of addresses.
return (
return Promise.resolve(
Object.entries(this.prices[currency])
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([address, _]) => _addresses.includes(address.toLowerCase()))
Expand Down Expand Up @@ -141,7 +144,7 @@ describe("PriceClient", function () {
beginTs = msToS(Date.now());
});

it("Price feed ordering", async function () {
it("Price feed ordering", function () {
// Generate a list with ~random names; nb. names are not (currently?) required to be unique.
const feedNames = Array(3)
.fill("Test PriceFeed")
Expand Down Expand Up @@ -258,7 +261,7 @@ describe("PriceClient", function () {
}
});

it("getPriceByAddress: Address case insensitivity", async function () {
it("getPriceByAddress: Address case insensitivity", function () {
// Instantiate a custom subclass of PriceClient.
const pc: TestPriceClient = new TestPriceClient(dummyLogger, [
new acrossApi.PriceFeed({ name: "Across API (expect fail)", host: "127.0.0.1", retries: 0 }),
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk-v2",
"author": "UMA Team",
"version": "0.17.0",
"version": "0.17.1",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/v/developer-docs/developers/across-sdk",
"files": [
Expand All @@ -19,8 +19,8 @@
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"test": "hardhat test",
"test:watch": "hardhat watch test",
"lint": "eslint --fix src",
"lint-check": "eslint src",
"lint": "eslint --fix src test e2e",
"lint-check": "eslint src test e2e",
"prepare": "yarn build && husky install",
"size": "size-limit",
"analyze": "size-limit --why",
Expand Down
2 changes: 1 addition & 1 deletion test/BaseClass.isUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("BaseAbstractClient.isUpdated", () => {
await ubaClient.update();
expect(ubaClient.isUpdated).to.be.true;
});
it("should return false if the client is not updated", async () => {
it("should return false if the client is not updated", () => {
expect(ubaClient.isUpdated).to.be.false;
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigStoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const tokenConfigToUpdate = JSON.stringify({
spokeTargetBalances: sampleSpokeTargetBalances,
});

describe("AcrossConfigStoreClient", async function () {
describe("AcrossConfigStoreClient", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();
({ dai: l1Token, weth: l2Token } = await hubPoolFixture());
Expand Down
2 changes: 1 addition & 1 deletion test/HubPoolClient.DepositToDestinationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let hubPool: Contract, lpTokenFactory: Contract, mockAdapter: Contract;
let owner: SignerWithAddress;
let hubPoolClient: HubPoolClient;

describe("HubPoolClient: Deposit to Destination Token", async function () {
describe("HubPoolClient: Deposit to Destination Token", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();

Expand Down
2 changes: 1 addition & 1 deletion test/HubPoolClient.L1Tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let hubPool: Contract, lpTokenFactory: Contract;
let owner: SignerWithAddress;
let hubPoolClient: HubPoolClient;

describe("HubPoolClient: L1Tokens", async function () {
describe("HubPoolClient: L1Tokens", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();

Expand Down
4 changes: 2 additions & 2 deletions test/HubPoolClient.RootBundleEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function constructSimpleTree(runningBalance: BigNumber) {
return { leaves, tree };
}

describe("HubPoolClient: RootBundle Events", async function () {
describe("HubPoolClient: RootBundle Events", function () {
beforeEach(async function () {
({ hubPool, l1Token_1, l1Token_2, timer, owner, dataworker } = await setupHubPool(
ethers,
Expand Down Expand Up @@ -425,7 +425,7 @@ describe("HubPoolClient: RootBundle Events", async function () {
);
});

describe("HubPoolClient: UBA-specific runningBalances tests", async function () {
describe("HubPoolClient: UBA-specific runningBalances tests", function () {
const hubPoolChainId = 1;
const chainIds = [10, 137, 42161];
const maxConfigStoreVersion = constants.CONFIG_STORE_VERSION + 1;
Expand Down
2 changes: 1 addition & 1 deletion test/HubPoolClient.Utilization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const tokenConfigToUpdate = JSON.stringify({
spokeTargetBalances: sampleSpokeTargetBalances,
});

describe("HubPool Utilization", async function () {
describe("HubPool Utilization", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();
const getNetwork = owner?.provider?.getNetwork();
Expand Down
2 changes: 1 addition & 1 deletion test/SpokePool.Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const generateValidRefundRequest = async (
return { deposit: deposit as DepositWithBlock, fill: fill as FillWithBlock, refundRequest: refundRequest };
};

describe("SpokePoolClient: Event Filtering", async function () {
describe("SpokePoolClient: Event Filtering", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();

Expand Down
2 changes: 1 addition & 1 deletion test/SpokePoolClient.DepositRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let owner: SignerWithAddress;

let spokePoolClient: SpokePoolClient;

describe("SpokePoolClient: Deposit Routes", async function () {
describe("SpokePoolClient: Deposit Routes", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();
// Deploy a minimal spokePool, without using the fixture as this does some route enabling within it.
Expand Down
2 changes: 1 addition & 1 deletion test/SpokePoolClient.RefundRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let _relayer: SignerWithAddress, relayer: string;
let deploymentBlock: number;
let spokePoolClient: MockSpokePoolClient;

describe("SpokePoolClient: Refund Requests", async function () {
describe("SpokePoolClient: Refund Requests", function () {
beforeEach(async function () {
[_relayer] = await ethers.getSigners();
relayer = _relayer.address;
Expand Down
2 changes: 1 addition & 1 deletion test/SpokePoolClient.SpeedUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const destinationChainId2 = destinationChainId + 1;

let spokePoolClient: SpokePoolClient;

describe("SpokePoolClient: SpeedUp", async function () {
describe("SpokePoolClient: SpeedUp", function () {
const ignoredFields = [
"blockNumber",
"blockTimestamp",
Expand Down
2 changes: 1 addition & 1 deletion test/SpokePoolClient.deposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const originChainId2 = originChainId + 1;

let spokePoolClient: SpokePoolClient;

describe("SpokePoolClient: Deposits", async function () {
describe("SpokePoolClient: Deposits", function () {
beforeEach(async function () {
[, depositor, relayer1, relayer2] = await ethers.getSigners();
({ spokePool, erc20, destErc20, weth, deploymentBlock } = await deploySpokePoolWithToken(
Expand Down
2 changes: 1 addition & 1 deletion test/SpokePoolClient.fills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const originChainId2 = originChainId + 1;

let spokePoolClient: SpokePoolClient;

describe("SpokePoolClient: Fills", async function () {
describe("SpokePoolClient: Fills", function () {
beforeEach(async function () {
[, depositor, relayer1, relayer2] = await ethers.getSigners();
({ spokePool, erc20, destErc20, weth, deploymentBlock } = await deploySpokePoolWithToken(
Expand Down
17 changes: 12 additions & 5 deletions test/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ dotenv.config();

describe("Utils test", () => {
it("retry", async () => {
const failN = (numFails: number) => async () => {
if (numFails-- > 0) throw new Error("Failed!");
return true;
const failN = (numFails: number) => {
return () =>
new Promise((resolve, reject) => {
if (numFails-- > 0) {
reject();
}
resolve(true);
});
};

await Promise.all([
assert.doesNotReject(() => retry(failN(0), 0, 1)),
assert.rejects(() => retry(failN(1), 0, 1)),
Expand Down Expand Up @@ -60,7 +64,10 @@ describe("Utils test", () => {
gasPrice
);
const gasMultiplier = toBNWei(1.0 + gasMarkup);
expect(toBN(gasEstimate).eq(toBN(refGasEstimate).mul(gasMultiplier).div(toBNWei(1))));

const expectedValue = toBN(refGasEstimate).mul(gasMultiplier).div(toBNWei(1));

expect(String(gasEstimate)).to.be.equal(String(expectedValue));
}
});
});
2 changes: 1 addition & 1 deletion test/lpFeeCalculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { toBNWei } from "../src/utils";
const rateModel = { UBar: toBNWei("0.65"), R0: toBNWei("0.00"), R1: toBNWei("0.08"), R2: toBNWei("1.00") };

describe("Realized liquidity provision calculation", function () {
it("Realized liquidity provision calculation", async function () {
it("Realized liquidity provision calculation", function () {
// Define a set of intervals to test over. Each interval contains the utilization at pointA (before deposit), the
// utilization at pointB (after the deposit), expected APY rate and the expected weekly rate. The numbers are
// generated from the juypter notebook defined in the comments above.
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/MockUBAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MockUBAClient extends UBAClient {
return this.flows[chainId]?.[tokenSymbol] ?? [];
}

async validateFlow(flow: interfaces.UbaFlow): Promise<clients.ModifiedUBAFlow | undefined> {
validateFlow(flow: interfaces.UbaFlow): Promise<clients.ModifiedUBAFlow | undefined> {
return super.validateFlow(flow);
}
}
8 changes: 4 additions & 4 deletions test/relayFeeCalculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const testCapitalCostsConfig: { [token: string]: any } = {
// Example of how to write this query class
class ExampleQueries implements QueryInterface {
constructor(private defaultGas = "305572") {}
async getGasCosts(): Promise<BigNumberish> {
return gasCost(this.defaultGas, 1e9); // 1 gwei
getGasCosts(): Promise<BigNumberish> {
return Promise.resolve(gasCost(this.defaultGas, 1e9)); // 1 gwei
}
async getTokenPrice(): Promise<number> {
getTokenPrice(): Promise<number> {
// Return token price denominated in ETH, assuming ETH is native token.
return 1 / 1000; // 1 USDC = 1 / $1000 ETH/USD
return Promise.resolve(1 / 1000); // 1 USDC = 1 / $1000 ETH/USD
}
getTokenDecimals(): number {
return 6;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/SpyTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class SpyTransport extends Transport {
this.spy = spyOptions.spy; // local instance of the spy to capture passed messages.
}

async log(info: unknown, callback: () => void): Promise<void> {
log(info: unknown, callback: () => void): void {
// Add info sent to the winston transport to the spy. This enables unit tests to validate what is passed to winston.
this.spy(info);
callback();
Expand Down
9 changes: 9 additions & 0 deletions test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export async function assertPromiseError<T>(promise: Promise<T>, errMessage?: st
}
}
}
export async function assertPromisePasses<T>(promise: Promise<T>): Promise<void> {
try {
await promise;
} catch (e: unknown) {
const err: Error = e as Error;
throw new Error("Promise failed: " + err.message);
}
}

export async function setupTokensForWallet(
contractToApprove: utils.Contract,
wallet: utils.SignerWithAddress,
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.json",
"include": ["./src/**/*.ts", "./test/**/*.ts"],
"include": ["./src/**/*.ts", "./test/**/*.ts", ".eslintrc.js", "./e2e/**/*.ts"],
"compilerOptions": {
// Expand the rootDir to include the test directory
"rootDir": "."
"rootDirs": ["./src", "./test", "./", "./e2e"]
}
}

0 comments on commit ae9873c

Please sign in to comment.