From e0daa64ce3154dc026922412d0431ef11a362d71 Mon Sep 17 00:00:00 2001 From: ChouAndy Date: Wed, 6 Sep 2023 20:29:57 +0800 Subject: [PATCH] fix: set fee rate to 0 in e2e testing --- .github/workflows/e2e-test.yml | 2 +- PULL_REQUEST_TEMPLATE.md | 1 + README.md | 70 +++++++++++++++++++--------------- hardhat.config.ts | 2 + test/hooks.ts | 14 +++++++ 5 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 test/hooks.ts diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index fab2d041..5e311dc1 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -1,4 +1,4 @@ -name: E2E Test Mainnet +name: E2E Test on: push: diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index bd5e4e7e..d433dd80 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,7 @@ # Pull Request Template --- + ## Protocol Information - **Name:** diff --git a/README.md b/README.md index 321418ba..90aa2dcf 100644 --- a/README.md +++ b/README.md @@ -16,47 +16,55 @@ An SDK that build protocol logics for Protocolink ### Contribution Steps 1. **Create a New Logic:** - - Add a new folder under `src/logics` named after the protocol (protocolId), using Hyphenation format. - - Create a new logic file under `src/logics/{protocolId}`, named with the action name (logicId). Prefix it with `logic.` and use Hyphenation format. The file name should be `logic.{logicId}.ts`. + +- Add a new folder under `src/logics` named after the protocol (protocolId), using Hyphenation format. +- Create a new logic file under `src/logics/{protocolId}`, named with the action name (logicId). Prefix it with `logic.` and use Hyphenation format. The file name should be `logic.{logicId}.ts`. 2. **Implement the Logic:** - - Implement the Logic class in the logic file using PascalCase. Append `Logic` to the action name. - - Extend the `core.Logic` class. - - Implement the following interfaces based on the requirements: - - `core.LogicTokenListInterface`: The tokens list function. - - `core.LogicOracleInterface`: The quotation function. - - `core.LogicBuilderInterface`: The txdata encode function for interacting with contracts. - - **Example:** - ```typescript - class LogicExampleLogic extends core.Logic implements - core.LogicTokenListInterface, core.LogicOracleInterface, core.LogicBuilderInterface { - // Your implementation here - } - ``` + +- Implement the Logic class in the logic file using PascalCase. Append `Logic` to the action name. +- Extend the `core.Logic` class. +- Implement the following interfaces based on the requirements: + - `core.LogicTokenListInterface`: The tokens list function. + - `core.LogicOracleInterface`: The quotation function. + - `core.LogicBuilderInterface`: The txdata encode function for interacting with contracts. + +**Example:** + +```typescript +class LogicExampleLogic + extends core.Logic + implements core.LogicTokenListInterface, core.LogicOracleInterface, core.LogicBuilderInterface { + // Your implementation here +} +``` 3. **Reference Examples:** - - Explore reference examples for different categories: - - Lending: [Aave V3](src/logics/aave-v2/), [Compound V3](src/logics/comopound-v3/) - - Swap: [Uniswap V3](src/logics/uniswap-v3/), [ParaSwap V5](src/logics/paraswap-v5/) - - FlashLoan: [Aave V3](src/logics/aave-v3/), [Balancer V2](src/logics/balancer-v2/) - - More: [GO](src/logics/) + +- Explore reference examples for different categories: + - Lending: [Aave V3](src/logics/aave-v2/), [Compound V3](src/logics/comopound-v3/) + - Swap: [Uniswap V3](src/logics/uniswap-v3/), [ParaSwap V5](src/logics/paraswap-v5/) + - FlashLoan: [Aave V3](src/logics/aave-v3/), [Balancer V2](src/logics/balancer-v2/) +- More: [GO](src/logics/) 4. **Unit Testing:** - - Write tests that won't fail based on block number increments. - - Test files are in the same path as the logic files, named `logic.{logicId}.test.ts`. - - Write tests for functions like `getTokenList()` and `build()` as needed. + +- Write tests that won't fail based on block number increments. +- Test files are in the same path as the logic files, named `logic.{logicId}.test.ts`. +- Write tests for functions like `getTokenList()` and `build()` as needed. 5. **Integration Testing:** - - Write tests that interact with the Router contract in real time. - - Test files are in `test/logics/{protocolId}/`, named `{logicId}.test.ts`. - - Utilize Logic's quotation functions to generate Logic Data for contract interactions. - - Verify transaction success and expected changes in user asset balances. + +- Write tests that interact with the Router contract in real time. +- Test files are in `test/logics/{protocolId}/`, named `{logicId}.test.ts`. +- Utilize Logic's quotation functions to generate Logic Data for contract interactions. +- Verify transaction success and expected changes in user asset balances. 6. **Submit a Pull Request (PR)**: - - Use the [PR template](PULL_REQUEST_TEMPLATE.md) for PR content. Fill in the template and submit the PR. - - Enable "Allow edits by maintainers" when creating the PR. - - If your PR isn't merged promptly, feel free to ask for assistance on our Discord. + +- Use the [PR template](PULL_REQUEST_TEMPLATE.md) for PR content. Fill in the template and submit the PR. +- Enable "Allow edits by maintainers" when creating the PR. +- If your PR isn't merged promptly, feel free to ask for assistance on our Discord. ### Get Involved and Learn More diff --git a/hardhat.config.ts b/hardhat.config.ts index 557de3b6..26fe11fc 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -2,6 +2,7 @@ import '@nomicfoundation/hardhat-chai-matchers'; import '@protocolink/test-helpers'; import { HardhatUserConfig } from 'hardhat/config'; +import { setup } from 'test/hooks'; const config: HardhatUserConfig = { networks: { @@ -22,6 +23,7 @@ const config: HardhatUserConfig = { mocha: { timeout: 1200000, retries: 3, + rootHooks: { beforeAll: [setup] }, }, }; diff --git a/test/hooks.ts b/test/hooks.ts new file mode 100644 index 00000000..7aff9d5e --- /dev/null +++ b/test/hooks.ts @@ -0,0 +1,14 @@ +import * as core from '@protocolink/core'; +import { getChainId } from '@protocolink/test-helpers'; +import * as helpers from '@nomicfoundation/hardhat-network-helpers'; + +export async function setup() { + const hre = await import('hardhat'); + const chainId = await getChainId(); + + const router = core.Router__factory.connect(core.getContractAddress(chainId, 'Router'), hre.ethers.provider); + const ownerAddress = await router.owner(); + await helpers.impersonateAccount(ownerAddress); + const owner = hre.ethers.provider.getSigner(ownerAddress); + await router.connect(owner).setFeeRate(0); +}