From 6b2638163f56a6fef1d6b2e62f086105d24bc84c Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 16 Feb 2024 17:36:15 +0200 Subject: [PATCH 1/7] add action --- .github/workflows/node.js.yml | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..53012eb --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,85 @@ +name: Build and Test + +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] + +jobs: + Setup: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.9.0" + + - name: Cache node modules + uses: actions/cache@v4 + id: npm-cache + with: + path: | + node_modules + ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.npm-cache.outputs.cache-hit != 'true' + run: npm i + + Test: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' # This line ensures that this job only runs on pull requests + needs: Setup + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.9.0" + + - name: Cache node modules + uses: actions/cache/restore@v4 + with: + path: | + node_modules + ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + + - name: Run tests + run: npx hardhat test + + Coverage-Test: + runs-on: ubuntu-latest + needs: Setup + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.9.0" + + - name: Cache node modules + uses: actions/cache/restore@v4 + with: + path: | + node_modules + ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + + - name: Run tests and generate coverage + run: npx hardhat coverage + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} # required \ No newline at end of file From 3e954b4d3be0eed75f5e0fe43e35166bd31ca6dd Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 16 Feb 2024 17:39:20 +0200 Subject: [PATCH 2/7] fix build --- package-lock.json | 148 ------------------------------------- test/CollateralProvider.ts | 2 +- 2 files changed, 1 insertion(+), 149 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4dd7f30..720dbdc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1683,141 +1683,6 @@ "@nomicfoundation/solidity-analyzer-win32-x64-msvc": "0.1.1" } }, - "node_modules/@nomicfoundation/solidity-analyzer-darwin-arm64": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz", - "integrity": "sha512-KcTodaQw8ivDZyF+D76FokN/HdpgGpfjc/gFCImdLUyqB6eSWVaZPazMbeAjmfhx3R0zm/NYVzxwAokFKgrc0w==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-darwin-x64": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-darwin-x64/-/solidity-analyzer-darwin-x64-0.1.1.tgz", - "integrity": "sha512-XhQG4BaJE6cIbjAVtzGOGbK3sn1BO9W29uhk9J8y8fZF1DYz0Doj8QDMfpMu+A6TjPDs61lbsmeYodIDnfveSA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-freebsd-x64": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-freebsd-x64/-/solidity-analyzer-freebsd-x64-0.1.1.tgz", - "integrity": "sha512-GHF1VKRdHW3G8CndkwdaeLkVBi5A9u2jwtlS7SLhBc8b5U/GcoL39Q+1CSO3hYqePNP+eV5YI7Zgm0ea6kMHoA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-linux-arm64-gnu": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-arm64-gnu/-/solidity-analyzer-linux-arm64-gnu-0.1.1.tgz", - "integrity": "sha512-g4Cv2fO37ZsUENQ2vwPnZc2zRenHyAxHcyBjKcjaSmmkKrFr64yvzeNO8S3GBFCo90rfochLs99wFVGT/0owpg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-linux-arm64-musl": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-arm64-musl/-/solidity-analyzer-linux-arm64-musl-0.1.1.tgz", - "integrity": "sha512-WJ3CE5Oek25OGE3WwzK7oaopY8xMw9Lhb0mlYuJl/maZVo+WtP36XoQTb7bW/i8aAdHW5Z+BqrHMux23pvxG3w==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-linux-x64-gnu": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-x64-gnu/-/solidity-analyzer-linux-x64-gnu-0.1.1.tgz", - "integrity": "sha512-5WN7leSr5fkUBBjE4f3wKENUy9HQStu7HmWqbtknfXkkil+eNWiBV275IOlpXku7v3uLsXTOKpnnGHJYI2qsdA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-linux-x64-musl": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-x64-musl/-/solidity-analyzer-linux-x64-musl-0.1.1.tgz", - "integrity": "sha512-KdYMkJOq0SYPQMmErv/63CwGwMm5XHenEna9X9aB8mQmhDBrYrlAOSsIPgFCUSL0hjxE3xHP65/EPXR/InD2+w==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-win32-arm64-msvc": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-win32-arm64-msvc/-/solidity-analyzer-win32-arm64-msvc-0.1.1.tgz", - "integrity": "sha512-VFZASBfl4qiBYwW5xeY20exWhmv6ww9sWu/krWSesv3q5hA0o1JuzmPHR4LPN6SUZj5vcqci0O6JOL8BPw+APg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@nomicfoundation/solidity-analyzer-win32-ia32-msvc": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-win32-ia32-msvc/-/solidity-analyzer-win32-ia32-msvc-0.1.1.tgz", - "integrity": "sha512-JnFkYuyCSA70j6Si6cS1A9Gh1aHTEb8kOTBApp/c7NRTFGNMH8eaInKlyuuiIbvYFhlXW4LicqyYuWNNq9hkpQ==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, "node_modules/@nomicfoundation/solidity-analyzer-win32-x64-msvc": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-win32-x64-msvc/-/solidity-analyzer-win32-x64-msvc-0.1.1.tgz", @@ -8495,19 +8360,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", diff --git a/test/CollateralProvider.ts b/test/CollateralProvider.ts index 6290a2a..12dfffe 100644 --- a/test/CollateralProvider.ts +++ b/test/CollateralProvider.ts @@ -3,7 +3,7 @@ import { CollateralProvider } from "../typechain-types" import { DealProvider } from "../typechain-types" import { LockDealNFT } from "../typechain-types" import { MockProvider } from "../typechain-types" -import { deployed, token, MAX_RATIO, BUSD } from "/LockDealNFT/test/helper" +import { deployed, token, MAX_RATIO, BUSD } from "lockdeal-nft/test/helper" import { time, mine } from "@nomicfoundation/hardhat-network-helpers" import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers" import { expect } from "chai" From d870909be25b4e26e98749ab8aefca6b46dee3a3 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 16 Feb 2024 17:46:01 +0200 Subject: [PATCH 3/7] reinstall packages --- package-lock.json | 148 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/package-lock.json b/package-lock.json index 720dbdc..4dd7f30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1683,6 +1683,141 @@ "@nomicfoundation/solidity-analyzer-win32-x64-msvc": "0.1.1" } }, + "node_modules/@nomicfoundation/solidity-analyzer-darwin-arm64": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz", + "integrity": "sha512-KcTodaQw8ivDZyF+D76FokN/HdpgGpfjc/gFCImdLUyqB6eSWVaZPazMbeAjmfhx3R0zm/NYVzxwAokFKgrc0w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-darwin-x64": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-darwin-x64/-/solidity-analyzer-darwin-x64-0.1.1.tgz", + "integrity": "sha512-XhQG4BaJE6cIbjAVtzGOGbK3sn1BO9W29uhk9J8y8fZF1DYz0Doj8QDMfpMu+A6TjPDs61lbsmeYodIDnfveSA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-freebsd-x64": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-freebsd-x64/-/solidity-analyzer-freebsd-x64-0.1.1.tgz", + "integrity": "sha512-GHF1VKRdHW3G8CndkwdaeLkVBi5A9u2jwtlS7SLhBc8b5U/GcoL39Q+1CSO3hYqePNP+eV5YI7Zgm0ea6kMHoA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-linux-arm64-gnu": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-arm64-gnu/-/solidity-analyzer-linux-arm64-gnu-0.1.1.tgz", + "integrity": "sha512-g4Cv2fO37ZsUENQ2vwPnZc2zRenHyAxHcyBjKcjaSmmkKrFr64yvzeNO8S3GBFCo90rfochLs99wFVGT/0owpg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-linux-arm64-musl": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-arm64-musl/-/solidity-analyzer-linux-arm64-musl-0.1.1.tgz", + "integrity": "sha512-WJ3CE5Oek25OGE3WwzK7oaopY8xMw9Lhb0mlYuJl/maZVo+WtP36XoQTb7bW/i8aAdHW5Z+BqrHMux23pvxG3w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-linux-x64-gnu": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-x64-gnu/-/solidity-analyzer-linux-x64-gnu-0.1.1.tgz", + "integrity": "sha512-5WN7leSr5fkUBBjE4f3wKENUy9HQStu7HmWqbtknfXkkil+eNWiBV275IOlpXku7v3uLsXTOKpnnGHJYI2qsdA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-linux-x64-musl": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-linux-x64-musl/-/solidity-analyzer-linux-x64-musl-0.1.1.tgz", + "integrity": "sha512-KdYMkJOq0SYPQMmErv/63CwGwMm5XHenEna9X9aB8mQmhDBrYrlAOSsIPgFCUSL0hjxE3xHP65/EPXR/InD2+w==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-win32-arm64-msvc": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-win32-arm64-msvc/-/solidity-analyzer-win32-arm64-msvc-0.1.1.tgz", + "integrity": "sha512-VFZASBfl4qiBYwW5xeY20exWhmv6ww9sWu/krWSesv3q5hA0o1JuzmPHR4LPN6SUZj5vcqci0O6JOL8BPw+APg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/solidity-analyzer-win32-ia32-msvc": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-win32-ia32-msvc/-/solidity-analyzer-win32-ia32-msvc-0.1.1.tgz", + "integrity": "sha512-JnFkYuyCSA70j6Si6cS1A9Gh1aHTEb8kOTBApp/c7NRTFGNMH8eaInKlyuuiIbvYFhlXW4LicqyYuWNNq9hkpQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@nomicfoundation/solidity-analyzer-win32-x64-msvc": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@nomicfoundation/solidity-analyzer-win32-x64-msvc/-/solidity-analyzer-win32-x64-msvc-0.1.1.tgz", @@ -8360,6 +8495,19 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", From 41027e1de0aaee8641e802e58f10f63c6e18a873 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Mon, 19 Feb 2024 14:21:33 +0200 Subject: [PATCH 4/7] fix tests --- test/CollateralProvider.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/CollateralProvider.ts b/test/CollateralProvider.ts index 12dfffe..0ff11ed 100644 --- a/test/CollateralProvider.ts +++ b/test/CollateralProvider.ts @@ -3,7 +3,7 @@ import { CollateralProvider } from "../typechain-types" import { DealProvider } from "../typechain-types" import { LockDealNFT } from "../typechain-types" import { MockProvider } from "../typechain-types" -import { deployed, token, MAX_RATIO, BUSD } from "lockdeal-nft/test/helper" +import { deployed } from "@poolzfinance/poolz-helper-v2" import { time, mine } from "@nomicfoundation/hardhat-network-helpers" import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers" import { expect } from "chai" @@ -24,8 +24,11 @@ describe("Collateral Provider", function () { let vaultId: BigNumber const signature: Bytes = ethers.utils.toUtf8Bytes("signature") const name: string = "CollateralProvider" - const halfRatio = MAX_RATIO.div(2) + const MAX_RATIO = ethers.utils.parseUnits("1", 21) // 100% + const halfRatio = ethers.utils.parseUnits("5", 20) const amount = 100000 + const token = "0xCcf41440a137299CB6af95114cb043Ce4e28679A" + const BUSD = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56" before(async () => { ;[receiver, projectOwner] = await ethers.getSigners() From a419f5e7aaac468a061c1c545a479a86b8bb1171 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Mon, 19 Feb 2024 14:29:46 +0200 Subject: [PATCH 5/7] add icons --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 01bb04a..59d85f3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # CollateralProvider +[![Build and Test](https://github.com/The-Poolz/LockDealNFT.CollateralProvider/actions/workflows/node.js.yml/badge.svg)](https://github.com/The-Poolz/LockDealNFT.CollateralProvider/actions/workflows/node.js.yml) +[![codecov](https://codecov.io/gh/The-Poolz/LockDealNFT.CollateralProvider/branch/master/graph/badge.svg)](https://codecov.io/gh/The-Poolz/LockDealNFT.CollateralProvider) +[![CodeFactor](https://www.codefactor.io/repository/github/the-poolz/LockDealNFT.CollateralProvider/badge)](https://www.codefactor.io/repository/github/the-poolz/LockDealNFT.CollateralProvider) + **CollateralProvider** is a contract that enables the management of `tokens` and `main coins` for the **Project Owner**. ## Pools From 083f87115337d79d64d7418055ee5723bc10d99f Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Mon, 19 Feb 2024 14:36:27 +0200 Subject: [PATCH 6/7] codefactor fix --- test/CollateralProvider.ts | 357 +++++++++++++++++-------------------- 1 file changed, 163 insertions(+), 194 deletions(-) diff --git a/test/CollateralProvider.ts b/test/CollateralProvider.ts index 0ff11ed..8a562da 100644 --- a/test/CollateralProvider.ts +++ b/test/CollateralProvider.ts @@ -31,7 +31,7 @@ describe("Collateral Provider", function () { const BUSD = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56" before(async () => { - ;[receiver, projectOwner] = await ethers.getSigners() + [receiver, projectOwner] = await ethers.getSigners() mockVaultManager = await deployed("MockVaultManager") lockDealNFT = await deployed("LockDealNFT", mockVaultManager.address, "") dealProvider = await deployed("DealProvider", lockDealNFT.address) @@ -49,67 +49,59 @@ describe("Collateral Provider", function () { params = [amount * 2, amount, finishTime] await mockProvider.createNewPool([projectOwner.address, token], params, signature) vaultId = await mockVaultManager.Id() - }) - - it("should return provider name", async () => { - expect(await collateralProvider.name()).to.equal("CollateralProvider") - }) - - it("should revert invalid zero address before creation", async () => { - await expect(deployed("CollateralProvider", lockDealNFT.address, constants.AddressZero)).to.be.revertedWith( - "CollateralProvider: invalid address" + }) + + it('should return provider name', async () => { + expect(await collateralProvider.name()).to.equal('CollateralProvider') + }) + + it('should revert invalid zero address before creation', async () => { + await expect(deployed('CollateralProvider', lockDealNFT.address, constants.AddressZero)).to.be.revertedWith( + 'CollateralProvider: invalid address', ) - }) - - it("should register new collateral pool", async () => { - const poolData = await lockDealNFT.getData(poolId) - const params = [amount, finishTime, halfRatio] - expect(poolData).to.deep.equal([ - collateralProvider.address, - name, - poolId, - vaultId, - projectOwner.address, - token, - params, - ]) - }) - - it("should create main coin deal provider pool", async () => { + }) + + it('should register new collateral pool', async () => { + const poolData = await lockDealNFT.getData(poolId); + const params = [amount, finishTime, halfRatio]; + expect(poolData).to.deep.equal([collateralProvider.address, name, poolId, vaultId, projectOwner.address, token, params]) + }) + + it('should create main coin deal provider pool', async () => { const poolData = await lockDealNFT.getData(poolId + 1) const params = [0] expect(poolData).to.deep.equal([ - dealProvider.address, - "DealProvider", - poolId + 1, - vaultId, - collateralProvider.address, - token, - params, + dealProvider.address, + 'DealProvider', + poolId + 1, + vaultId, + collateralProvider.address, + token, + params, ]) - }) - - it("should create token provider pool", async () => { + }) + + it('should create token provider pool', async () => { const poolData = await lockDealNFT.getData(poolId + 2) const params = [0] expect(poolData).to.deep.equal([ - dealProvider.address, - "DealProvider", - poolId + 2, - 0, - collateralProvider.address, - constants.AddressZero, - params, + dealProvider.address, + 'DealProvider', + poolId + 2, + 0, + collateralProvider.address, + constants.AddressZero, + params, ]) - }) - - it("should revert invalid finish time", async () => { + }) + + it('should revert invalid finish time', async () => { await expect( - mockProvider.createNewPool([receiver.address, token], [amount, (await time.latest()) - 1, 0, 0], signature) - ).to.be.revertedWith("CollateralProvider: start time must be in the future") - }) - - it("should deposit tokens", async () => { + mockProvider.createNewPool([receiver.address, token], [amount, (await time.latest()) - 1, 0, 0], signature), + ).to.be.revertedWith('CollateralProvider: start time must be in the future') + }) + + it('should deposit tokens', async () => { await mockProvider.handleRefund(poolId, projectOwner.address, amount) const tokenCollectorId = poolId + 2 const mainCoinHolderId = poolId + 3 @@ -117,9 +109,9 @@ describe("Collateral Provider", function () { expect(poolData.params[0]).to.equal(amount) poolData = await lockDealNFT.getData(mainCoinHolderId) expect(poolData.params[0]).to.equal(amount / 2) - }) - - it("should deposit main coin", async () => { + }) + + it('should deposit main coin', async () => { await mockProvider.handleWithdraw(poolId, amount) const mainCoinCollectorId = poolId + 1 const mainCoinHolderId = poolId + 3 @@ -127,146 +119,132 @@ describe("Collateral Provider", function () { expect(poolData.params[0]).to.equal(amount / 2) poolData = await lockDealNFT.getData(mainCoinCollectorId) expect(poolData.params[0]).to.equal(amount / 2) - }) - - it("only NFT can manage withdraw", async () => { - await expect(collateralProvider.withdraw(poolId)).to.be.revertedWith("only NFT contract can call this function") - }) - - it("should increase holder pool's amount", async () => { + }) + + it('only NFT can manage withdraw', async () => { + await expect(collateralProvider.withdraw(poolId)).to.be.revertedWith('only NFT contract can call this function') + }) + + it("should increase holder pool's amount", async () => { await mockProvider.handleWithdraw(poolId, amount) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(amount / 2) - }) - - it("should increase token pool's amount", async () => { + }) + + it("should increase token pool's amount", async () => { await mockProvider.handleRefund(poolId, projectOwner.address, amount) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(amount) - }) - - it("should increase holder and token pool's amount", async () => { + }) + + it("should increase holder and token pool's amount", async () => { await mockProvider.handleWithdraw(poolId, amount) await mockProvider.handleRefund(poolId, projectOwner.address, amount) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(amount / 2) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(amount) - }) - - it("should withdraw half main coins before time", async () => { + }) + + it('should withdraw half main coins before time', async () => { // user withdraw half token amount await mockProvider.handleWithdraw(poolId, amount) // Project owner withdraw half main coin amount before time await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256)"](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(amount / 2) - }) - - it("should withdraw tokens before time", async () => { + }) + + it('should withdraw tokens before time', async () => { await mockProvider.handleRefund(poolId, projectOwner.address, amount) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256)"](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(amount / 2) - }) - - it("should withdraw main coins and tokens before time", async () => { + }) + + it('should withdraw main coins and tokens before time', async () => { await mockProvider.handleWithdraw(poolId, amount) await mockProvider.handleRefund(poolId, projectOwner.address, amount) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256)"](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(0) - }) - - it("should transfer all pools to NFT after finish time", async () => { + }) + + it('should transfer all pools to NFT after finish time', async () => { await time.setNextBlockTimestamp(finishTime + 1) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256)"](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(0) - }) - - it("should get zero amount before time", async () => { + }) + + it('should get zero amount before time', async () => { const withdrawAmount = await lockDealNFT.getWithdrawableAmount(poolId) expect(withdrawAmount).to.equal(0) - }) - - it("should get full amount after time", async () => { + }) + + it('should get full amount after time', async () => { await time.setNextBlockTimestamp(finishTime) await mine(1) const withdrawAmount = await lockDealNFT.getWithdrawableAmount(poolId) expect(withdrawAmount).to.equal(amount) - }) - - it("should return full collateral data", async () => { + }) + + it('should return full collateral data', async () => { params = [amount * 2, amount, finishTime] await mockProvider.createNewPool([projectOwner.address, token], params, signature) const collateralParams = [amount.toString(), finishTime.toString(), halfRatio] const fullData = await lockDealNFT.getFullData(poolId) expect(fullData).to.deep.equal([ - [collateralProvider.address, name, poolId, vaultId, projectOwner.address, token, collateralParams], - [dealProvider.address, "DealProvider", poolId + 1, vaultId, collateralProvider.address, token, [0]], - [ - dealProvider.address, - "DealProvider", - poolId + 2, - 0, - collateralProvider.address, - constants.AddressZero, - [0], - ], - [dealProvider.address, "DealProvider", poolId + 3, vaultId, collateralProvider.address, token, [amount]], + [collateralProvider.address, name, poolId, vaultId, projectOwner.address, token, collateralParams], + [dealProvider.address, 'DealProvider', poolId + 1, vaultId, collateralProvider.address, token, [0]], + [dealProvider.address, 'DealProvider', poolId + 2, 0, collateralProvider.address, constants.AddressZero, [0]], + [dealProvider.address, 'DealProvider', poolId + 3, vaultId, collateralProvider.address, token, [amount]], ]) - }) - - it("should get half main coin amount", async () => { + }) + + it('should get half main coin amount', async () => { params = [amount * 2, amount, finishTime] await mockProvider.createNewPool([projectOwner.address, token], params, signature) await mockProvider.handleWithdraw(poolId, amount) const withdrawAmount = await lockDealNFT.getWithdrawableAmount(poolId) expect(withdrawAmount).to.equal(amount / 2) - }) - - it("should create 4 new pools after split", async () => { + }) + + it('should create 4 new pools after split', async () => { await time.setNextBlockTimestamp(finishTime + 1) const totalSupply = await lockDealNFT.totalSupply() - const packedData = ethers.utils.defaultAbiCoder.encode( - ["uint256", "address"], - [halfRatio, projectOwner.address] - ) + const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256,bytes)"]( - projectOwner.address, - lockDealNFT.address, - poolId, - packedData - ) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256,bytes)']( + projectOwner.address, + lockDealNFT.address, + poolId, + packedData, + ) // check that all pools was created expect(await lockDealNFT.totalSupply()).to.equal(totalSupply.add(4)) - }) - - it("should return a PoolSplit event after splitting", async () => { + }) + + it('should return a PoolSplit event after splitting', async () => { await time.setNextBlockTimestamp(finishTime + 1) - const packedData = ethers.utils.defaultAbiCoder.encode( - ["uint256", "address"], - [halfRatio, projectOwner.address] - ) + const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) const tx = await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256,bytes)"]( - projectOwner.address, - lockDealNFT.address, - poolId, - packedData - ) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256,bytes)']( + projectOwner.address, + lockDealNFT.address, + poolId, + packedData, + ) await tx.wait() const events = await lockDealNFT.queryFilter(lockDealNFT.filters.PoolSplit()) expect(events[events.length - 1].args.poolId).to.equal(poolId) @@ -276,91 +254,82 @@ describe("Collateral Provider", function () { expect(events[events.length - 1].args.newOwner).to.equal(projectOwner.address) expect(events[events.length - 1].args.splitLeftAmount).to.equal(amount / 2) expect(events[events.length - 1].args.newSplitLeftAmount).to.equal(amount / 2) - }) - - it("should split Main Coin Collector pool", async () => { + }) + + it('should split Main Coin Collector pool', async () => { await mockProvider.handleWithdraw(poolId, amount) - const packedData = ethers.utils.defaultAbiCoder.encode( - ["uint256", "address"], - [halfRatio, projectOwner.address] - ) + const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256,bytes)"]( - projectOwner.address, - lockDealNFT.address, - poolId, - packedData - ) - const mainCoinCollectorId = poolId + 1 + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256,bytes)']( + projectOwner.address, + lockDealNFT.address, + poolId, + packedData, + ) + const mainCoinCollectorId = poolId + 1; const newMainCoinCoolectorId = mainCoinCollectorId + 4 const poolData = await lockDealNFT.getData(mainCoinCollectorId) const newPoolData = await lockDealNFT.getData(newMainCoinCoolectorId) expect(poolData.params[0]).to.equal(amount / 4) expect(newPoolData.params[0]).to.equal(amount / 4) - }) - - it("should split Token Collector pool", async () => { + }) + + it('should split Token Collector pool', async () => { await mockProvider.handleRefund(poolId, projectOwner.address, amount) - const packedData = ethers.utils.defaultAbiCoder.encode( - ["uint256", "address"], - [halfRatio, projectOwner.address] - ) + const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256,bytes)"]( - projectOwner.address, - lockDealNFT.address, - poolId, - packedData - ) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256,bytes)']( + projectOwner.address, + lockDealNFT.address, + poolId, + packedData, + ) const tokenCollectorId = poolId + 2 const newTokenCoolectorId = tokenCollectorId + 5 const poolData = await lockDealNFT.getData(tokenCollectorId) const newPoolData = await lockDealNFT.getData(newTokenCoolectorId) expect(poolData.params[0]).to.equal(amount / 2) expect(newPoolData.params[0]).to.equal(amount / 2) - }) - - it("should split main coin holder pool", async () => { + }) + + it('should split main coin holder pool', async () => { await time.setNextBlockTimestamp(finishTime + 1) - const packedData = ethers.utils.defaultAbiCoder.encode( - ["uint256", "address"], - [halfRatio, projectOwner.address] - ) + const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ["safeTransferFrom(address,address,uint256,bytes)"]( - projectOwner.address, - lockDealNFT.address, - poolId, - packedData - ) + .connect(projectOwner) + ['safeTransferFrom(address,address,uint256,bytes)']( + projectOwner.address, + lockDealNFT.address, + poolId, + packedData, + ) const coinHolderId = poolId + 3 const newCoinHolderId = poolId + 4 const poolData = await lockDealNFT.getData(coinHolderId) const newPoolData = await lockDealNFT.getData(newCoinHolderId) expect(poolData.params[0]).to.equal(amount / 2) expect(newPoolData.params[0]).to.equal(amount / 2) - }) - - it("should create new pool with 1 usdt to 50 tokens", async () => { - const tokenAmount = ethers.utils.parseUnits("50", 18) - const usdtAmount = ethers.utils.parseUnits("1", 18) + }) + + it('should create new pool with 1 usdt to 50 tokens', async () => { + const tokenAmount = ethers.utils.parseUnits('50', 18) + const usdtAmount = ethers.utils.parseUnits('1', 18) const params = [tokenAmount, usdtAmount, finishTime] poolId = (await lockDealNFT.totalSupply()).toNumber() await mockProvider.createNewPool([projectOwner.address, BUSD], params, signature) expect((await collateralProvider.getParams(poolId))[0]).to.equal(usdtAmount) expect(await collateralProvider.poolIdToRateToWei(poolId)).to.equal(MAX_RATIO.div(50)) - }) - - it("should create new pool with 1 token to 50 usdt", async () => { - const tokenAmount = ethers.utils.parseUnits("1", 18) - const usdtAmount = ethers.utils.parseUnits("50", 18) + }) + + it('should create new pool with 1 token to 50 usdt', async () => { + const tokenAmount = ethers.utils.parseUnits('1', 18) + const usdtAmount = ethers.utils.parseUnits('50', 18) const params = [tokenAmount, usdtAmount, finishTime] poolId = (await lockDealNFT.totalSupply()).toNumber() await mockProvider.createNewPool([projectOwner.address, BUSD], params, signature) expect((await collateralProvider.getParams(poolId))[0]).to.equal(usdtAmount) expect(await collateralProvider.poolIdToRateToWei(poolId)).to.equal(MAX_RATIO.mul(50)) - }) + }) }) From 4ea671ed38f645af0c947525f996189a1b1c4531 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Mon, 19 Feb 2024 14:38:30 +0200 Subject: [PATCH 7/7] codefactor --- test/CollateralProvider.ts | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/CollateralProvider.ts b/test/CollateralProvider.ts index 8a562da..1430929 100644 --- a/test/CollateralProvider.ts +++ b/test/CollateralProvider.ts @@ -147,8 +147,7 @@ describe("Collateral Provider", function () { await mockProvider.handleWithdraw(poolId, amount) // Project owner withdraw half main coin amount before time await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner)['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(amount / 2) @@ -157,8 +156,7 @@ describe("Collateral Provider", function () { it('should withdraw tokens before time', async () => { await mockProvider.handleRefund(poolId, projectOwner.address, amount) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner)['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(amount / 2) @@ -168,8 +166,7 @@ describe("Collateral Provider", function () { await mockProvider.handleWithdraw(poolId, amount) await mockProvider.handleRefund(poolId, projectOwner.address, amount) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner)['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(0) @@ -178,8 +175,7 @@ describe("Collateral Provider", function () { it('should transfer all pools to NFT after finish time', async () => { await time.setNextBlockTimestamp(finishTime + 1) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) + .connect(projectOwner)['safeTransferFrom(address,address,uint256)'](projectOwner.address, lockDealNFT.address, poolId) expect((await lockDealNFT.getData(poolId + 1)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 2)).params[0]).to.deep.equal(0) expect((await lockDealNFT.getData(poolId + 3)).params[0]).to.deep.equal(0) @@ -223,8 +219,7 @@ describe("Collateral Provider", function () { const totalSupply = await lockDealNFT.totalSupply() const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256,bytes)']( + .connect(projectOwner)['safeTransferFrom(address,address,uint256,bytes)']( projectOwner.address, lockDealNFT.address, poolId, @@ -238,8 +233,7 @@ describe("Collateral Provider", function () { await time.setNextBlockTimestamp(finishTime + 1) const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) const tx = await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256,bytes)']( + .connect(projectOwner)['safeTransferFrom(address,address,uint256,bytes)']( projectOwner.address, lockDealNFT.address, poolId, @@ -260,8 +254,7 @@ describe("Collateral Provider", function () { await mockProvider.handleWithdraw(poolId, amount) const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256,bytes)']( + .connect(projectOwner)['safeTransferFrom(address,address,uint256,bytes)']( projectOwner.address, lockDealNFT.address, poolId, @@ -279,8 +272,7 @@ describe("Collateral Provider", function () { await mockProvider.handleRefund(poolId, projectOwner.address, amount) const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256,bytes)']( + .connect(projectOwner)['safeTransferFrom(address,address,uint256,bytes)']( projectOwner.address, lockDealNFT.address, poolId, @@ -298,8 +290,7 @@ describe("Collateral Provider", function () { await time.setNextBlockTimestamp(finishTime + 1) const packedData = ethers.utils.defaultAbiCoder.encode(['uint256', 'address'], [halfRatio, projectOwner.address]) await lockDealNFT - .connect(projectOwner) - ['safeTransferFrom(address,address,uint256,bytes)']( + .connect(projectOwner)['safeTransferFrom(address,address,uint256,bytes)']( projectOwner.address, lockDealNFT.address, poolId,