From 6fa4bec94ea3babebd13bb5af65d2c3e353dedac Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 9 Feb 2024 16:25:16 +0100 Subject: [PATCH] chore: add .only and .skip variations for compliance tests --- .../stakingRouter.versioned.test.ts | 2 +- test/common/erc20.test.ts | 17 ++++++++++++----- test/common/erc721.test.ts | 16 ++++++++++++---- test/common/versioned.test.ts | 19 +++++++++++++------ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/test/0.8.9/stakingRouter/stakingRouter.versioned.test.ts b/test/0.8.9/stakingRouter/stakingRouter.versioned.test.ts index 074bdb70a..2ab59ee8a 100644 --- a/test/0.8.9/stakingRouter/stakingRouter.versioned.test.ts +++ b/test/0.8.9/stakingRouter/stakingRouter.versioned.test.ts @@ -5,7 +5,7 @@ import { StakingRouter__factory } from "typechain-types"; import { randomAddress } from "lib"; -import testVersionedCompliance from "../../common/versioned.test"; +import { testVersionedCompliance } from "../../common/versioned.test"; testVersionedCompliance({ name: "StakingRouter", diff --git a/test/common/erc20.test.ts b/test/common/erc20.test.ts index e909e9971..6d1232031 100644 --- a/test/common/erc20.test.ts +++ b/test/common/erc20.test.ts @@ -47,11 +47,6 @@ interface ERC20Target { * @param {object} target.deploy async function that returns the instance of the contract and initial parameters * @param {object} target.suiteFunction function that runs the suite, a temporary workaround for running * the suite exclusively or skipping the suite; see the todo below - * - * @todo rewrite the function to support the same interface as `describe`, i.e. - * instead of passing `suiteFunction`, we should be able to call the function like: - * testERC20Compliance.only(target) - * testERC20Compliance.skip(target) */ export function testERC20Compliance({ tokenName, deploy, suiteFunction = describe }: ERC20Target) { suiteFunction(`${tokenName} ERC-20 Compliance`, () => { @@ -306,3 +301,15 @@ export function testERC20Compliance({ tokenName, deploy, suiteFunction = describ }); }); } + +testERC20Compliance.only = (target: ERC20Target) => + testERC20Compliance({ + ...target, + suiteFunction: describe.only, // eslint-disable-line no-only-tests/no-only-tests + }); + +testERC20Compliance.skip = (target: ERC20Target) => + testERC20Compliance({ + ...target, + suiteFunction: describe.skip, + }); diff --git a/test/common/erc721.test.ts b/test/common/erc721.test.ts index 0e56baa2b..69b2d7cc2 100644 --- a/test/common/erc721.test.ts +++ b/test/common/erc721.test.ts @@ -55,10 +55,6 @@ interface ERC721Target { * * @todo call safeTransferFrom directly instead of using signature * @todo use DRY when testing overloadable functions (calling without and with extra data) - * @todo rewrite the function to support the same interface as `describe`, i.e. - * instead of passing `suiteFunction`, we should be able to call the function like: - * testERC20Compliance.only(target) - * testERC20Compliance.skip(target) */ export function testERC721Compliance({ tokenName, deploy, suiteFunction = describe }: ERC721Target) { suiteFunction(`${tokenName} ERC-721 Compliance`, () => { @@ -400,3 +396,15 @@ export function testERC721Compliance({ tokenName, deploy, suiteFunction = descri }); }); } + +testERC721Compliance.only = (target: ERC721Target) => + testERC721Compliance({ + ...target, + suiteFunction: describe.only, // eslint-disable-line no-only-tests/no-only-tests + }); + +testERC721Compliance.skip = (target: ERC721Target) => + testERC721Compliance({ + ...target, + suiteFunction: describe.skip, + }); diff --git a/test/common/versioned.test.ts b/test/common/versioned.test.ts index cf67997e4..17456b028 100644 --- a/test/common/versioned.test.ts +++ b/test/common/versioned.test.ts @@ -33,13 +33,8 @@ interface VersionedTarget { * predict how the derived contracts are used. * @param {object} target.suiteFunction function that runs the suite, a temporary workaround for running * the suite exclusively or skipping the suite; see the todo below - * - * @todo rewrite the function to support the same interface as `describe`, i.e. - * instead of passing `suiteFunction`, we should be able to call the function like: - * testVersionedCompliance.only(target) - * testVersionedCompliance.skip(target) */ -export default function testVersionedCompliance({ name, deploy, updates, suiteFunction = describe }: VersionedTarget) { +export function testVersionedCompliance({ name, deploy, updates, suiteFunction = describe }: VersionedTarget) { suiteFunction(`${name} Versioned Compliance`, () => { let admin: HardhatEthersSigner; let user: HardhatEthersSigner; @@ -90,3 +85,15 @@ export default function testVersionedCompliance({ name, deploy, updates, suiteFu }); }); } + +testVersionedCompliance.only = (target: VersionedTarget) => + testVersionedCompliance({ + ...target, + suiteFunction: describe.only, // eslint-disable-line no-only-tests/no-only-tests + }); + +testVersionedCompliance.skip = (target: VersionedTarget) => + testVersionedCompliance({ + ...target, + suiteFunction: describe.skip, + });