From 4f41f62108bc0434725a422263fc717ddfb98ae6 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 22 Feb 2024 15:32:28 +0400 Subject: [PATCH 01/11] Add sepolia arbitrum --- hardhat.config.ts | 26 ++++++++++++++++--- .../offchainAssetReceiptVault_Goerli.ts | 4 +-- .../offchainAssetReceiptVault_Polygon.ts | 4 +-- .../offchainAssetReceiptVault_Sepolia.ts | 6 +++++ .../OffChainAssetReceiptVault.test.ts | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 scripts/constructorArguments/offchainAssetReceiptVault_Sepolia.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index e16b9059..1d070b4e 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -9,12 +9,15 @@ require("dotenv").config(); const { RINKEBY_URL, PRIVATE_KEY, + PRIVATE_KEY3, POLYGON_URL, ETHEREUM_URL, MUMBAI_URL, POLYGONSCAN_API_KEY, GOERLI_URL, + SEPOLIA_URL, ETHERSCAN_API_KEY, + ARBITRUM_API_KEY } = process.env; export const config = { @@ -32,7 +35,7 @@ export const config = { matic: { url: POLYGON_URL || "", accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - gasPrice: 141900000000, + gasPrice: 262000000000, }, mumbai: { url: MUMBAI_URL || "https://rpc-mumbai.maticvigil.com", @@ -41,14 +44,19 @@ export const config = { }, goerli: { url: GOERLI_URL || "", - accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - gasPrice: 16000000000, + accounts: PRIVATE_KEY3 ? [`0x${PRIVATE_KEY3}`] : [], + gasPrice: 22000000000, }, ethereum: { url: ETHEREUM_URL || "", accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], gasPrice: 22000000000, }, + sepolia: { + url: SEPOLIA_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 22000000000, + }, }, solidity: { compilers: [ @@ -66,7 +74,17 @@ export const config = { etherscan: { // Your API key for Etherscan // Obtain one at https://etherscan.io/ - apiKey: ETHERSCAN_API_KEY, + apiKey: ARBITRUM_API_KEY, + customChains: [ + { + network: "arbitrum sepolia", + chainId: 421614, + urls: { + apiURL: "https://api-sepolia.arbiscan.io/api", + browserURL: "https://sepolia.arbiscan.io/" + } + } + ] }, gasReporter: { currency: "USD", diff --git a/scripts/constructorArguments/offchainAssetReceiptVault_Goerli.ts b/scripts/constructorArguments/offchainAssetReceiptVault_Goerli.ts index c8210552..e4e7bbcc 100644 --- a/scripts/constructorArguments/offchainAssetReceiptVault_Goerli.ts +++ b/scripts/constructorArguments/offchainAssetReceiptVault_Goerli.ts @@ -1,6 +1,6 @@ module.exports = [ { - implementation: "0x576FBc9ab2693d6e748e85B301eD0FC6b14fC708", - receiptFactory: "0x431C85E807a1bc810538121db2E9934822e13643", + implementation: "0xeEbC089D9CbeC08BB10CdE85D2A17502EeA04544", + receiptFactory: "0xbECC502aF9E8476cb9A0616F7C1549D31670a806", }, ]; diff --git a/scripts/constructorArguments/offchainAssetReceiptVault_Polygon.ts b/scripts/constructorArguments/offchainAssetReceiptVault_Polygon.ts index b327b245..a1cfadfc 100644 --- a/scripts/constructorArguments/offchainAssetReceiptVault_Polygon.ts +++ b/scripts/constructorArguments/offchainAssetReceiptVault_Polygon.ts @@ -1,6 +1,6 @@ module.exports = [ { - implementation: "0x52324308A8dC7240Bcce870A10733A1DA4633CFC", - receiptFactory: "0x5C5663c76147CFa47d5bb19570B8F1e1AB292492", + implementation: "0x1331b50cBDE17d2ff04ca87797178721430A698e", + receiptFactory: "0xdEE8d59c6C2925b83C678A7f8c26D9C228a52621", }, ]; diff --git a/scripts/constructorArguments/offchainAssetReceiptVault_Sepolia.ts b/scripts/constructorArguments/offchainAssetReceiptVault_Sepolia.ts new file mode 100644 index 00000000..c8210552 --- /dev/null +++ b/scripts/constructorArguments/offchainAssetReceiptVault_Sepolia.ts @@ -0,0 +1,6 @@ +module.exports = [ + { + implementation: "0x576FBc9ab2693d6e748e85B301eD0FC6b14fC708", + receiptFactory: "0x431C85E807a1bc810538121db2E9934822e13643", + }, +]; diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 80eea4c4..6f003388 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -672,7 +672,7 @@ describe("OffChainAssetReceiptVault", async function () { .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assetToDeposit = aliceAssets.div(2); - const assetToReDeposit = ethers.BigNumber.from(10); + const assetToReDeposit = ethers.BigNumber.from(0); await vault .connect(alice) ["deposit(uint256,address,uint256,bytes)"]( From 8d2a59fbf04a1cf269773158046c47b689ddeb20 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 22 Feb 2024 18:13:26 +0400 Subject: [PATCH 02/11] Add arbitrum mainnet --- hardhat.config.ts | 8 +++++++- .../offchainAssetReceiptVault_Arbitrum.ts | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 scripts/constructorArguments/offchainAssetReceiptVault_Arbitrum.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 1d070b4e..6e449e97 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -17,7 +17,8 @@ const { GOERLI_URL, SEPOLIA_URL, ETHERSCAN_API_KEY, - ARBITRUM_API_KEY + ARBITRUM_API_KEY, + ARBITRUM_URL } = process.env; export const config = { @@ -57,6 +58,11 @@ export const config = { accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], gasPrice: 22000000000, }, + arbitrum: { + url: ARBITRUM_URL || "", + accounts: PRIVATE_KEY3 ? [`0x${PRIVATE_KEY3}`] : [], + gasPrice: 300000000, + }, }, solidity: { compilers: [ diff --git a/scripts/constructorArguments/offchainAssetReceiptVault_Arbitrum.ts b/scripts/constructorArguments/offchainAssetReceiptVault_Arbitrum.ts new file mode 100644 index 00000000..653d11ed --- /dev/null +++ b/scripts/constructorArguments/offchainAssetReceiptVault_Arbitrum.ts @@ -0,0 +1,6 @@ +module.exports = [ + { + implementation: "0x6DB9F75C0B79E0351B09311c4856F556b09F67a5", + receiptFactory: "0x5e08F361001480717cf35c6230C942e9d47fbE86", + }, +]; From 8a7c3fcb4ca419a746ab0f2e5dff5ea25aeba918 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Sun, 28 Apr 2024 12:06:47 +0400 Subject: [PATCH 03/11] Add sepolia etherium network --- hardhat.config.ts | 16 +++++++++++----- .../offchainAssetReceiptVault_Sepolia_Eth.ts | 6 ++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 scripts/constructorArguments/offchainAssetReceiptVault_Sepolia_Eth.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 6e449e97..7dfb0cb7 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -15,10 +15,11 @@ const { MUMBAI_URL, POLYGONSCAN_API_KEY, GOERLI_URL, - SEPOLIA_URL, + SEPOLIA_ARBITRUM_URL, ETHERSCAN_API_KEY, ARBITRUM_API_KEY, - ARBITRUM_URL + ARBITRUM_URL, + ETHEREUM_SEPOLIA_URL } = process.env; export const config = { @@ -53,8 +54,8 @@ export const config = { accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], gasPrice: 22000000000, }, - sepolia: { - url: SEPOLIA_URL || "", + sepolia_arbitrum: { + url: SEPOLIA_ARBITRUM_URL || "", accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], gasPrice: 22000000000, }, @@ -63,6 +64,11 @@ export const config = { accounts: PRIVATE_KEY3 ? [`0x${PRIVATE_KEY3}`] : [], gasPrice: 300000000, }, + sepolia: { + url: ETHEREUM_SEPOLIA_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 10000000000, + }, }, solidity: { compilers: [ @@ -80,7 +86,7 @@ export const config = { etherscan: { // Your API key for Etherscan // Obtain one at https://etherscan.io/ - apiKey: ARBITRUM_API_KEY, + apiKey: ETHERSCAN_API_KEY, customChains: [ { network: "arbitrum sepolia", diff --git a/scripts/constructorArguments/offchainAssetReceiptVault_Sepolia_Eth.ts b/scripts/constructorArguments/offchainAssetReceiptVault_Sepolia_Eth.ts new file mode 100644 index 00000000..94ed6393 --- /dev/null +++ b/scripts/constructorArguments/offchainAssetReceiptVault_Sepolia_Eth.ts @@ -0,0 +1,6 @@ +module.exports = [ + { + implementation: "0xebaF408b5cE8bf417e627d66b948acDa3Ca9de15", + receiptFactory: "0x7e6Ee6a291847Aa28788467092B318A7D2229F7c", + }, +]; From 770f28fcbbb42f298c05883c389b1a89cf3349a1 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Fri, 3 May 2024 14:48:50 +0400 Subject: [PATCH 04/11] Prettier --- hardhat.config.ts | 122 +++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index f0cecf1f..e482766d 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -7,73 +7,73 @@ import "@nomiclabs/hardhat-etherscan"; require("dotenv").config(); const { - PRIVATE_KEY, - POLYGON_URL, - ETHEREUM_URL, - POLYGONSCAN_API_KEY, - ETHERSCAN_API_KEY, - SEPOLIA_URL, - POLYGON_AMOY_URL, + PRIVATE_KEY, + POLYGON_URL, + ETHEREUM_URL, + POLYGONSCAN_API_KEY, + ETHERSCAN_API_KEY, + SEPOLIA_URL, + POLYGON_AMOY_URL, } = process.env; export const config = { - networks: { - // Running 'hardhat test' will use this network, which forks mainnet using the "london" hardfork - hardhat: { - blockGasLimit: 100000000, - allowUnlimitedContractSize: true, - hardfork: "london", - }, - matic: { - url: POLYGON_URL || "", - accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - gasPrice: 141900000000, - }, - ethereum: { - url: ETHEREUM_URL || "", - accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - gasPrice: 22000000000, - }, - sepolia: { - chainId: 11155111, - url: SEPOLIA_URL || "", - accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - gasPrice: 22000000000, - }, - amoy: { - chainId: 80002, - url: POLYGON_AMOY_URL || "", - accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - gasPrice: 22000000000, - }, - - // arbitrumSepolia: { - // url: ARBITRUM_SEPOLIA_URL || "", - // accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], - // gasPrice: 22000000000, - // }, + networks: { + // Running 'hardhat test' will use this network, which forks mainnet using the "london" hardfork + hardhat: { + blockGasLimit: 100000000, + allowUnlimitedContractSize: true, + hardfork: "london", + }, + matic: { + url: POLYGON_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 141900000000, }, - solidity: { - compilers: [ - { - version: "0.8.17", - settings: { - optimizer: { - enabled: true, - runs: 100000, - }, - }, - }, - ], + ethereum: { + url: ETHEREUM_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 22000000000, }, - etherscan: { - // Your API key for Etherscan - // Obtain one at https://etherscan.io/ - apiKey: ETHERSCAN_API_KEY, + sepolia: { + chainId: 11155111, + url: SEPOLIA_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 22000000000, }, - gasReporter: { - currency: "USD", - gasPrice: 10, + amoy: { + chainId: 80002, + url: POLYGON_AMOY_URL || "", + accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + gasPrice: 22000000000, }, + + // arbitrumSepolia: { + // url: ARBITRUM_SEPOLIA_URL || "", + // accounts: PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : [], + // gasPrice: 22000000000, + // }, + }, + solidity: { + compilers: [ + { + version: "0.8.17", + settings: { + optimizer: { + enabled: true, + runs: 100000, + }, + }, + }, + ], + }, + etherscan: { + // Your API key for Etherscan + // Obtain one at https://etherscan.io/ + apiKey: ETHERSCAN_API_KEY, + }, + gasReporter: { + currency: "USD", + gasPrice: 10, + }, }; export default config; From e93b0f921cd028042a3a7066caa944cb3e1dd66e Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Mon, 6 May 2024 16:28:09 +0400 Subject: [PATCH 05/11] Create one contract and use it to all tests --- .../OffChainAssetReceiptVault.test.ts | 101 ++---------------- 1 file changed, 9 insertions(+), 92 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 6f003388..77da3df2 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -34,15 +34,15 @@ let expectedName = "OffchainAssetVaul"; let expectedSymbol = "OAV"; describe("OffChainAssetReceiptVault", async function () { - beforeEach(async () => { - const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); - TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; - await TierV2TestContract.deployed(); - }); - it("Check admin is not address zero", async function () { - const offchainAssetReceiptVaultFactory = - await deployOffchainAssetReceiptVaultFactory(); + const [vault, receipt, config] = await deployOffChainAssetReceiptVault(); + const offchainAssetReceiptVaultFactory = + await deployOffchainAssetReceiptVaultFactory(); + const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); + TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; + await TierV2TestContract.deployed(); + + it("Check admin is not address zero", async function () { const constructionConfig = { admin: ADDRESS_ZERO, vaultConfig: { @@ -65,9 +65,6 @@ describe("OffChainAssetReceiptVault", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const offchainAssetReceiptVaultFactory = - await deployOffchainAssetReceiptVaultFactory(); - const constructionConfig = { admin: alice.address, vaultConfig: { @@ -87,8 +84,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Constructs well", async function () { - const [, , config] = await deployOffChainAssetReceiptVault(); - assert( config.receiptVaultConfig.vaultConfig.name === expectedName, `wrong name expected ${expectedName} got ${config.receiptVaultConfig.vaultConfig.name}` @@ -104,7 +99,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Check vault is the owner of its receipt", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; @@ -115,8 +109,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Checks SetERC20Tier event is emitted", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -148,8 +140,6 @@ describe("OffChainAssetReceiptVault", async function () { assert(data === "0x01", `wrong data expected 0x01 got ${data}`); }); it("Checks setERC1155Tier event is emitted", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -182,7 +172,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Checks totalAssets", async function () { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -231,7 +220,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewDeposit returns correct shares", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const assets = ethers.BigNumber.from(100); const signers = await ethers.getSigners(); @@ -260,7 +248,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewMint returns correct assets", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(10); const signers = await ethers.getSigners(); @@ -279,7 +266,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewWithdraw returns 0 shares if no withdrawer role", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const assets = ethers.BigNumber.from(100); const signers = await ethers.getSigners(); @@ -299,7 +285,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewWithdraw returns correct shares", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const assets = ethers.BigNumber.from(10); const signers = await ethers.getSigners(); @@ -325,7 +310,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Mints with data", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; @@ -358,7 +342,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Cannot Mint to someone else if recipient is not DEPOSITOR or system not certified for them", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -389,7 +372,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Mints to someone else if recipient is not DEPOSITOR but system certified for them", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -433,7 +415,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Mints to someone else if recipient is DEPOSITOR", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -470,7 +451,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Cannot Deposit to someone else if recipient is not DEPOSITOR or system not certified for them", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -499,7 +479,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Deposits to someone else if recipient is not DEPOSITOR but system certified for them", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -540,7 +519,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Deposits to someone else if recipient is DEPOSITOR", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -574,7 +552,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewRedeem returns correct assets", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(100); const signers = await ethers.getSigners(); @@ -608,8 +585,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewRedeem returns 0 shares if no withdrawer role", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -652,8 +627,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Redeposits", async function () { const signers = await ethers.getSigners(); - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -672,7 +645,7 @@ describe("OffChainAssetReceiptVault", async function () { .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assetToDeposit = aliceAssets.div(2); - const assetToReDeposit = ethers.BigNumber.from(0); + const assetToReDeposit = ethers.BigNumber.from(10); await vault .connect(alice) ["deposit(uint256,address,uint256,bytes)"]( @@ -705,7 +678,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Prevents redeposit to someone else while not certified or recipient is not depositor", async function () { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -747,7 +719,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Redeposits to someone else while certified", async function () { const signers = await ethers.getSigners(); - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -810,8 +781,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Prevents Redeposit on receipt with id 0", async function () { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); - const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -837,8 +806,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Prevents Redeposit on non-existing receipt", async function () { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); - const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -865,7 +832,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Snapshot event is emitted", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) @@ -882,7 +848,6 @@ describe("OffChainAssetReceiptVault", async function () { it("SnapshotWithData event is emitted", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) @@ -903,8 +868,6 @@ describe("OffChainAssetReceiptVault", async function () { assert(data === "0x01", `Wrong information. Expected 0x01, got ${data}`); }); it("Sets correct erc20Tier and mintier", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -935,8 +898,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Sets correct erc11Tier and mintier", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -967,8 +928,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Checks Certify event is emitted", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -1004,8 +963,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Certifies with data", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -1043,8 +1000,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Certify in the past relative to the existing certification time with forceUntil true", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; @@ -1083,8 +1038,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Checks certifiedUntil is not zero", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); - const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); const _certifiedUntil = ethers.BigNumber.from(0); @@ -1106,7 +1059,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Checks referenceBlockNumber is less than block number", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -1129,7 +1081,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Certifies", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -1156,7 +1107,6 @@ describe("OffChainAssetReceiptVault", async function () { it("AuthorizeReceiptTransfer reverts if certification expired", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); await assertError( async () => @@ -1170,7 +1120,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Confiscate - Checks role CONFISCATOR", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); await assertError( async () => @@ -1184,7 +1133,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Confiscate - Checks ConfiscateShares is NOT emitted on Zero balance", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) @@ -1208,7 +1156,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Confiscate - Checks ConfiscateShares is emitted", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1259,7 +1206,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Confiscate receipts - Checks ConfiscateReceipt is emitted", async function () { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1325,7 +1271,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Confiscate receipts - Checks ConfiscateReceipt is NOT emitted on zero balance", async function () { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); const alice = signers[0]; @@ -1353,7 +1298,6 @@ describe("OffChainAssetReceiptVault", async function () { it("Checks confiscated is same as balance", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1402,7 +1346,6 @@ describe("OffChainAssetReceiptVault", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; - const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -1458,7 +1401,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Checks confiscated is same as receipt balance", async function () { const signers = await ethers.getSigners(); - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1530,7 +1472,6 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Checks confiscated amount is transferred", async function () { const signers = await ethers.getSigners(); - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const alice = signers[0]; const bob = signers[1]; @@ -1601,7 +1542,6 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; - const [vault, receipt] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const testErc20Contract = (await testErc20.deploy()) as TestErc20; await testErc20Contract.deployed(); @@ -1669,8 +1609,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Should not withdraw on more than balance", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const id = ethers.BigNumber.from(1); @@ -1717,8 +1655,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("User not being able to withdraw someone else's share", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1766,8 +1702,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Prevent authorizeReceiptTransfer if system not certified", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1782,8 +1716,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Prevent authorizeReceiptTransfer if unauthorizedSenderTier", async function () { - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1824,8 +1756,6 @@ describe("OffChainAssetReceiptVault", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; - - const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); @@ -1846,7 +1776,6 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; - const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); @@ -1867,8 +1796,6 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -1918,8 +1845,6 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -1968,8 +1893,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Withdraw on someone else", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -2031,8 +1954,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Check withdraw for alice", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const id = 1; @@ -2096,8 +2017,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Redeems on someone else", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -2159,8 +2078,6 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Check redeem for alice", async function () { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); const alice = signers[0]; const id = 1; From 7fa93925f20bed763ec13cca97987d6f159a9dda Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Mon, 6 May 2024 17:15:29 +0400 Subject: [PATCH 06/11] Create one contract and use it to all tests - Factory and roles tests --- test/offchainAsset/Factory.test.ts | 20 ++--- test/offchainAsset/Roles.test.ts | 125 ++++++++++++++--------------- 2 files changed, 67 insertions(+), 78 deletions(-) diff --git a/test/offchainAsset/Factory.test.ts b/test/offchainAsset/Factory.test.ts index d6266d5d..45884b9a 100644 --- a/test/offchainAsset/Factory.test.ts +++ b/test/offchainAsset/Factory.test.ts @@ -1,21 +1,17 @@ import { ethers } from "hardhat"; import { - OffchainAssetReceiptVaultFactory, - ReceiptFactory, + OffchainAssetReceiptVaultFactory } from "../../typechain-types"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { expectedUri, getEventArgs } from "../util"; +import { getEventArgs } from "../util"; import { deployOffchainAssetReceiptVaultFactory } from "./deployOffchainAssetReceiptVault"; const assert = require("assert"); let offchainAssetReceiptVaultFactory: OffchainAssetReceiptVaultFactory; -describe("OffchainAssetReceiptVaultFactory Test", () => { - before(async () => { - offchainAssetReceiptVaultFactory = - await deployOffchainAssetReceiptVaultFactory(); - }); +describe("OffchainAssetReceiptVaultFactory Test", async () => { + offchainAssetReceiptVaultFactory = + await deployOffchainAssetReceiptVaultFactory(); it("Should deploy Factory correctly", async () => { assert( @@ -25,15 +21,15 @@ describe("OffchainAssetReceiptVaultFactory Test", () => { it("Should createChild", async () => { const signers = await ethers.getSigners(); - const alice = signers[0]; + const alice = signers[ 0 ]; const constructionConfig = { admin: alice.address, vaultConfig: { asset: ethers.constants.AddressZero, name: "OffchainAssetReceiptVault", - symbol: "OAV", - }, + symbol: "OAV" + } }; let tx = await offchainAssetReceiptVaultFactory.createChildTyped( diff --git a/test/offchainAsset/Roles.test.ts b/test/offchainAsset/Roles.test.ts index 2569f79a..c8321760 100644 --- a/test/offchainAsset/Roles.test.ts +++ b/test/offchainAsset/Roles.test.ts @@ -8,10 +8,12 @@ import assert from "assert"; let TierV2TestContract: ReadWriteTier; -describe("OffChainAssetReceiptVault Roles", async function () { - it("Checks Admin roles granted", async function () { +describe("OffChainAssetReceiptVault Roles", async function() { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + + it("Checks Admin roles granted", async function() { const signers = await ethers.getSigners(); - const alice = signers[0]; + const alice = signers[ 0 ]; const [vault] = await deployOffChainAssetReceiptVault(); const DEPOSITOR_ADMIN = await vault.connect(alice).DEPOSITOR_ADMIN(); @@ -54,47 +56,46 @@ describe("OffChainAssetReceiptVault Roles", async function () { assert( DEPOSITOR_ADMIN_Granted === true, - `No ${DEPOSITOR_ADMIN_Granted} role granted` + `No ${ DEPOSITOR_ADMIN_Granted } role granted` ); assert( WITHDRAWER_ADMIN_Granted === true, - `No ${WITHDRAWER_ADMIN_Granted} role granted` + `No ${ WITHDRAWER_ADMIN_Granted } role granted` ); assert( CERTIFIER_ADMIN_Granted === true, - `No ${CERTIFIER_ADMIN_Granted} role granted` + `No ${ CERTIFIER_ADMIN_Granted } role granted` ); assert( HANDLER_ADMIN_Granted === true, - `No ${HANDLER_ADMIN_Granted} role granted` + `No ${ HANDLER_ADMIN_Granted } role granted` ); assert( ERC20TIERER_ADMIN_Granted === true, - `No ${ERC20TIERER_ADMIN_Granted} role granted` + `No ${ ERC20TIERER_ADMIN_Granted } role granted` ); assert( ERC1155TIERER_ADMIN_Granted === true, - `No ${ERC1155TIERER_ADMIN_Granted} role granted` + `No ${ ERC1155TIERER_ADMIN_Granted } role granted` ); assert( ERC20SNAPSHOTTER_ADMIN_Granted === true, - `No ${ERC20SNAPSHOTTER_ADMIN_Granted} role granted` + `No ${ ERC20SNAPSHOTTER_ADMIN_Granted } role granted` ); assert( CONFISCATOR_ADMIN_Granted === true, - `No ${CONFISCATOR_ADMIN_Granted} role granted` + `No ${ CONFISCATOR_ADMIN_Granted } role granted` ); }); - it("Gets 0 shares for deposit without depositor role", async function () { + it("Gets 0 shares for deposit without depositor role", async function() { const signers = await ethers.getSigners(); - const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); - const asset = (await testErc20.deploy()) as TestErc20; + const asset = ( await testErc20.deploy() ) as TestErc20; await asset.deployed(); - const alice = signers[0]; - const bob = signers[1]; + const alice = signers[ 0 ]; + const bob = signers[ 1 ]; const shareRatio = ONE; const aliceAssets = ethers.BigNumber.from(1000); @@ -107,26 +108,24 @@ describe("OffChainAssetReceiptVault Roles", async function () { async () => await vault .connect(alice) - ["deposit(uint256,address,uint256,bytes)"]( - aliceAssets, - bob.address, - shareRatio, - [] - ), + [ "deposit(uint256,address,uint256,bytes)" ]( + aliceAssets, + bob.address, + shareRatio, + [] + ), `MinShareRatio`, "Failed to deposit" ); }); - it("Checks withdraw without depositor role", async function () { + it("Checks withdraw without depositor role", async function() { const signers = await ethers.getSigners(); - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - const testErc20 = await ethers.getContractFactory("TestErc20"); - const asset = (await testErc20.deploy()) as TestErc20; + const asset = ( await testErc20.deploy() ) as TestErc20; await asset.deployed(); - const alice = signers[0]; - const bob = signers[1]; + const alice = signers[ 0 ]; + const bob = signers[ 1 ]; const shareRatio = ethers.BigNumber.from(1); const aliceAssets = ethers.BigNumber.from(10); @@ -152,12 +151,12 @@ describe("OffChainAssetReceiptVault Roles", async function () { await vault .connect(alice) - ["deposit(uint256,address,uint256,bytes)"]( - aliceAssets, - bob.address, - shareRatio, - [] - ); + [ "deposit(uint256,address,uint256,bytes)" ]( + aliceAssets, + bob.address, + shareRatio, + [] + ); const balance = await receipt .connect(alice) @@ -168,13 +167,13 @@ describe("OffChainAssetReceiptVault Roles", async function () { .grantRole(await vault.connect(alice).WITHDRAWER(), bob.address); await vault .connect(bob) - ["redeem(uint256,address,address,uint256,bytes)"]( - balance, - bob.address, - bob.address, - shareRatio, - [] - ); + [ "redeem(uint256,address,address,uint256,bytes)" ]( + balance, + bob.address, + bob.address, + shareRatio, + [] + ); const balanceAfter = await receipt .connect(alice) @@ -182,18 +181,16 @@ describe("OffChainAssetReceiptVault Roles", async function () { assert( balanceAfter.isZero(), - `wrong assets. expected ${ethers.BigNumber.from(0)} got ${balanceAfter}` + `wrong assets. expected ${ ethers.BigNumber.from(0) } got ${ balanceAfter }` ); }); - it("Checks SetERC20Tier role", async function () { + it("Checks SetERC20Tier role", async function() { const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); - TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; + TierV2TestContract = ( await TierV2Test.deploy() ) as ReadWriteTier; await TierV2TestContract.deployed(); - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); - const alice = signers[0]; + const alice = signers[ 0 ]; const minTier = ethers.BigNumber.from(10); @@ -202,20 +199,18 @@ describe("OffChainAssetReceiptVault Roles", async function () { await vault .connect(alice) .setERC20Tier(TierV2TestContract.address, minTier, [], []), - `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault + `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault .connect(alice) - .ERC20TIERER()}`, + .ERC20TIERER() }`, "Failed to set erc20tier" ); }); - it("Checks setERC1155Tier role", async function () { + it("Checks setERC1155Tier role", async function() { const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); - TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; + TierV2TestContract = ( await TierV2Test.deploy() ) as ReadWriteTier; await TierV2TestContract.deployed(); - const [vault] = await deployOffChainAssetReceiptVault(); - const signers = await ethers.getSigners(); - const alice = signers[0]; + const alice = signers[ 0 ]; const minTier = ethers.BigNumber.from(10); @@ -224,29 +219,27 @@ describe("OffChainAssetReceiptVault Roles", async function () { await vault .connect(alice) .setERC1155Tier(TierV2TestContract.address, minTier, [], []), - `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault + `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault .connect(alice) - .ERC1155TIERER()}`, + .ERC1155TIERER() }`, "Failed to set erc1155tier" ); }); - it("Checks role for snapshotter", async function () { + it("Checks role for snapshotter", async function() { const signers = await ethers.getSigners(); - const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); + const alice = signers[ 0 ]; await assertError( async () => await vault.connect(alice).snapshot([]), - `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault + `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault .connect(alice) - .ERC20SNAPSHOTTER()}`, + .ERC20SNAPSHOTTER() }`, "failed to snapshot" ); }); - it("Checks role for certifier", async function () { + it("Checks role for certifier", async function() { const signers = await ethers.getSigners(); - const alice = signers[0]; - const [vault] = await deployOffChainAssetReceiptVault(); + const alice = signers[ 0 ]; const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -258,9 +251,9 @@ describe("OffChainAssetReceiptVault Roles", async function () { await vault .connect(alice) .certify(_until, _referenceBlockNumber, false, []), - `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault + `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault .connect(alice) - .CERTIFIER()}`, + .CERTIFIER() }`, "failed to certify" ); }); From b04ac47e23bbfb6cbe6e3562bdbf8b3d984757e4 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Mon, 6 May 2024 17:31:15 +0400 Subject: [PATCH 07/11] Create one contract and use it to all tests - Price Oracle --- test/priceOracle/Deposit.test.ts | 12 +---- test/priceOracle/Erc1155.test.ts | 57 ++++++++++----------- test/priceOracle/Erc20.test.ts | 8 ++- test/priceOracle/Mint.test.ts | 18 +------ test/priceOracle/Redeem.test.ts | 5 +- test/priceOracle/RedeemOverloaded.test.ts | 5 +- test/priceOracle/Withdraw.test.ts | 6 +-- test/priceOracle/WithdrawOverloaded.test.ts | 6 +-- 8 files changed, 45 insertions(+), 72 deletions(-) diff --git a/test/priceOracle/Deposit.test.ts b/test/priceOracle/Deposit.test.ts index c8a7c3ed..f23c2317 100644 --- a/test/priceOracle/Deposit.test.ts +++ b/test/priceOracle/Deposit.test.ts @@ -10,12 +10,12 @@ import { const assert = require("assert"); describe("deposit", async function () { + const [vault, asset, priceOracle, receipt] = await deployERC20PriceOracleVault(); + it("should not zero deposit", async function () { const signers = await ethers.getSigners(); const alice = signers[1]; - const [vault, asset] = await deployERC20PriceOracleVault(); - const totalTokenSupply = await asset.totalSupply(); const aliceDepositAmount = totalTokenSupply.div(2); @@ -39,8 +39,6 @@ describe("deposit", async function () { it("should deposit a sensible reference price", async function () { const signers = await ethers.getSigners(); - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - const alice = signers[1]; const totalTokenSupply = await asset.totalSupply(); @@ -92,9 +90,6 @@ describe("deposit", async function () { it("should deposit and withdraw", async function () { const signers = await ethers.getSigners(); - const [vault, asset, priceOracle, receipt] = - await deployERC20PriceOracleVault(); - const alice = signers[0]; const bob = signers[1]; @@ -239,9 +234,6 @@ describe("deposit", async function () { it("should trade erc1155", async function () { const signers = await ethers.getSigners(); - const [vault, asset, priceOracle, receipt] = - await deployERC20PriceOracleVault(); - const alice = signers[0]; const bob = signers[1]; diff --git a/test/priceOracle/Erc1155.test.ts b/test/priceOracle/Erc1155.test.ts index a119861d..aa3324b4 100644 --- a/test/priceOracle/Erc1155.test.ts +++ b/test/priceOracle/Erc1155.test.ts @@ -2,35 +2,34 @@ import { ethers } from "hardhat"; import { deployERC20PriceOracleVault, expectedUri, - fixedPointMul, + fixedPointMul } from "../util"; const assert = require("assert"); -describe("erc1155 usage", async function () { - it("should initialize well", async function () { - const [vault, asset, price, receipt] = await deployERC20PriceOracleVault(); +describe("erc1155 usage", async function() { + const [vault, erc20Token, priceOracle, receipt] = + await deployERC20PriceOracleVault(); + it("should initialize well", async function() { const signers = await ethers.getSigners(); - const alice = signers[0]; + const alice = signers[ 0 ]; const id = 12345; const erc1155Uri = await receipt.connect(alice).uri(id); assert( erc1155Uri === expectedUri, - `erc1155 did not construct with correct uri expected - ${expectedUri}, got - ${erc1155Uri} ` + `erc1155 did not construct with correct uri expected - ${ expectedUri }, got - ${ erc1155Uri } ` ); }); - it("should only send itself", async function () { + it("should only send itself", async function() { const signers = await ethers.getSigners(); - const [vault, erc20Token, priceOracle, receipt] = - await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); - const alice = signers[0]; - const bob = signers[1]; + const alice = signers[ 0 ]; + const bob = signers[ 1 ]; const depositAmount = ethers.BigNumber.from(1000); await erc20Token @@ -38,12 +37,12 @@ describe("erc1155 usage", async function () { .increaseAllowance(vault.address, depositAmount); await vault .connect(alice) - ["deposit(uint256,address,uint256,bytes)"]( - depositAmount, - alice.address, - shareRatio, - [] - ); + [ "deposit(uint256,address,uint256,bytes)" ]( + depositAmount, + alice.address, + shareRatio, + [] + ); const expectedErc20Balance = fixedPointMul(depositAmount, shareRatio); const expectedErc20BalanceAfter = expectedErc20Balance; @@ -53,18 +52,18 @@ describe("erc1155 usage", async function () { const erc20Balance = await vault .connect(alice) - ["balanceOf(address)"](signers[0].address); + [ "balanceOf(address)" ](signers[ 0 ].address); assert( erc20Balance.eq(expectedErc20Balance), - `wrong erc20 balance ${expectedErc20Balance} ${erc20Balance}` + `wrong erc20 balance ${ expectedErc20Balance } ${ erc20Balance }` ); const erc1155Balance = await receipt .connect(alice) - ["balanceOf(address,uint256)"](alice.address, expected1155ID); + [ "balanceOf(address,uint256)" ](alice.address, expected1155ID); assert( erc1155Balance.eq(expectedErc1155Balance), - `wrong erc1155 balance ${expectedErc20Balance} ${erc1155Balance}` + `wrong erc1155 balance ${ expectedErc20Balance } ${ erc1155Balance }` ); await receipt @@ -79,34 +78,34 @@ describe("erc1155 usage", async function () { const erc20BalanceAfter = await vault .connect(alice) - ["balanceOf(address)"](alice.address); + [ "balanceOf(address)" ](alice.address); assert( erc20BalanceAfter.eq(expectedErc20BalanceAfter), - `wrong erc20 balance after ${expectedErc20BalanceAfter} ${erc20BalanceAfter}` + `wrong erc20 balance after ${ expectedErc20BalanceAfter } ${ erc20BalanceAfter }` ); const erc20BalanceAfter2 = await vault .connect(bob) - ["balanceOf(address)"](bob.address); + [ "balanceOf(address)" ](bob.address); assert( erc20BalanceAfter2.eq(0), - `wrong erc20 balance after 2 0 ${erc20BalanceAfter2}` + `wrong erc20 balance after 2 0 ${ erc20BalanceAfter2 }` ); const erc1155BalanceAfter = await receipt .connect(alice) - ["balanceOf(address,uint256)"](alice.address, expected1155ID); + [ "balanceOf(address,uint256)" ](alice.address, expected1155ID); assert( erc1155BalanceAfter.eq(expectedErc1155BalanceAfter), - `wrong erc1155 balance after ${expectedErc1155BalanceAfter} ${erc1155BalanceAfter}` + `wrong erc1155 balance after ${ expectedErc1155BalanceAfter } ${ erc1155BalanceAfter }` ); const erc1155BalanceAfter2 = await receipt .connect(bob) - ["balanceOf(address,uint256)"](bob.address, expected1155ID); + [ "balanceOf(address,uint256)" ](bob.address, expected1155ID); assert( erc1155BalanceAfter2.eq(expectedErc1155BalanceAfter), - `wrong erc1155 balance 2 after ${expectedErc1155BalanceAfter} ${erc1155BalanceAfter2}` + `wrong erc1155 balance 2 after ${ expectedErc1155BalanceAfter } ${ erc1155BalanceAfter2 }` ); }); }); diff --git a/test/priceOracle/Erc20.test.ts b/test/priceOracle/Erc20.test.ts index 917b5dd4..cb28b94b 100644 --- a/test/priceOracle/Erc20.test.ts +++ b/test/priceOracle/Erc20.test.ts @@ -8,12 +8,13 @@ import { const assert = require("assert"); describe("erc20 usage", async function () { + const [vault, asset, priceOracle, receipt] = + await deployERC20PriceOracleVault(); + it("should construct well", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployERC20PriceOracleVault(); - const erc20Name = await vault.connect(alice).name(); const erc20Symbol = await vault.connect(alice).symbol(); @@ -30,9 +31,6 @@ describe("erc20 usage", async function () { it("should only send itself", async function () { const signers = await ethers.getSigners(); - const [vault, asset, priceOracle, receipt] = - await deployERC20PriceOracleVault(); - const alice = signers[0]; const bob = signers[1]; let shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/Mint.test.ts b/test/priceOracle/Mint.test.ts index a3487cc8..e2ee26c6 100644 --- a/test/priceOracle/Mint.test.ts +++ b/test/priceOracle/Mint.test.ts @@ -11,12 +11,12 @@ import { const assert = require("assert"); describe("Mint", async function () { + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + it("Sets maxShares correctly", async function () { const signers = await ethers.getSigners(); const owner = signers[0]; - const [vault] = await deployERC20PriceOracleVault(); - const expectedMaxShares = ethers.BigNumber.from(2) .pow(256) //up to 2**256 so should substruct 1 @@ -29,7 +29,6 @@ describe("Mint", async function () { ); }); it("Checks min share ratio is less than share ratio", async function () { - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); const signers = await ethers.getSigners(); @@ -49,7 +48,6 @@ describe("Mint", async function () { ); }); it("PreviewMint - Calculates assets correctly with round up", async function () { - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); const signers = await ethers.getSigners(); const alice = signers[0]; @@ -71,8 +69,6 @@ describe("Mint", async function () { it("Mint - Calculates assets correctly while minShareRation is set", async function () { const signers = await ethers.getSigners(); - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - const alice = signers[0]; const assets = ethers.BigNumber.from(5000); @@ -102,8 +98,6 @@ describe("Mint", async function () { it("Mint - Calculates assets correctly", async function () { const signers = await ethers.getSigners(); - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - const alice = signers[0]; const assets = ethers.BigNumber.from(5000); @@ -132,7 +126,6 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault] = await deployERC20PriceOracleVault(); const shares = ethers.BigNumber.from(0); await assertError( @@ -171,8 +164,6 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - const assets = ethers.BigNumber.from(5000); await asset.transfer(alice.address, assets); await asset.connect(alice).increaseAllowance(vault.address, assets); @@ -203,7 +194,6 @@ describe("Mint", async function () { ); }); it("Mint Overloaded - Checks min share ratio is less than share ratio", async function () { - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); const signers = await ethers.getSigners(); @@ -233,8 +223,6 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - const assets = ethers.BigNumber.from(5000); await asset.transfer(alice.address, assets); await asset.connect(alice).increaseAllowance(vault.address, assets); @@ -261,8 +249,6 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - const shareRatio = await priceOracle.price(); await assertError( diff --git a/test/priceOracle/Redeem.test.ts b/test/priceOracle/Redeem.test.ts index 54b0b356..90be4876 100644 --- a/test/priceOracle/Redeem.test.ts +++ b/test/priceOracle/Redeem.test.ts @@ -25,13 +25,12 @@ let vault: ERC20PriceOracleReceiptVault, describe("Redeem", async function () { let alice; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptVault] = + await deployERC20PriceOracleVault(); beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptVault] = - await deployERC20PriceOracleVault(); - vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/RedeemOverloaded.test.ts b/test/priceOracle/RedeemOverloaded.test.ts index 6482508b..7f04dd9b 100644 --- a/test/priceOracle/RedeemOverloaded.test.ts +++ b/test/priceOracle/RedeemOverloaded.test.ts @@ -25,13 +25,12 @@ let vault: ERC20PriceOracleReceiptVault, describe("Overloaded Redeem", async function () { let alice; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = + await deployERC20PriceOracleVault(); beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = - await deployERC20PriceOracleVault(); - vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/Withdraw.test.ts b/test/priceOracle/Withdraw.test.ts index 24e24ff0..c27f7222 100644 --- a/test/priceOracle/Withdraw.test.ts +++ b/test/priceOracle/Withdraw.test.ts @@ -26,13 +26,13 @@ let vault: ERC20PriceOracleReceiptVault, describe("Withdraw", async function () { let alice; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = + await deployERC20PriceOracleVault(); + beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = - await deployERC20PriceOracleVault(); - vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/WithdrawOverloaded.test.ts b/test/priceOracle/WithdrawOverloaded.test.ts index 8d4725f7..7acd92c7 100644 --- a/test/priceOracle/WithdrawOverloaded.test.ts +++ b/test/priceOracle/WithdrawOverloaded.test.ts @@ -26,13 +26,13 @@ let vault: ERC20PriceOracleReceiptVault, describe("Overloaded Withdraw", async function () { let alice; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = + await deployERC20PriceOracleVault(); + beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = - await deployERC20PriceOracleVault(); - vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); From 175ece7c26fbfd89f904f0380c070f95beabc3c0 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Wed, 15 May 2024 14:48:02 +0400 Subject: [PATCH 08/11] Revert "Create one contract and use it to all tests - Price Oracle" This reverts commit b04ac47e23bbfb6cbe6e3562bdbf8b3d984757e4. --- test/priceOracle/Deposit.test.ts | 12 ++++- test/priceOracle/Erc1155.test.ts | 57 +++++++++++---------- test/priceOracle/Erc20.test.ts | 8 +-- test/priceOracle/Mint.test.ts | 18 ++++++- test/priceOracle/Redeem.test.ts | 5 +- test/priceOracle/RedeemOverloaded.test.ts | 5 +- test/priceOracle/Withdraw.test.ts | 6 +-- test/priceOracle/WithdrawOverloaded.test.ts | 6 +-- 8 files changed, 72 insertions(+), 45 deletions(-) diff --git a/test/priceOracle/Deposit.test.ts b/test/priceOracle/Deposit.test.ts index f23c2317..c8a7c3ed 100644 --- a/test/priceOracle/Deposit.test.ts +++ b/test/priceOracle/Deposit.test.ts @@ -10,12 +10,12 @@ import { const assert = require("assert"); describe("deposit", async function () { - const [vault, asset, priceOracle, receipt] = await deployERC20PriceOracleVault(); - it("should not zero deposit", async function () { const signers = await ethers.getSigners(); const alice = signers[1]; + const [vault, asset] = await deployERC20PriceOracleVault(); + const totalTokenSupply = await asset.totalSupply(); const aliceDepositAmount = totalTokenSupply.div(2); @@ -39,6 +39,8 @@ describe("deposit", async function () { it("should deposit a sensible reference price", async function () { const signers = await ethers.getSigners(); + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + const alice = signers[1]; const totalTokenSupply = await asset.totalSupply(); @@ -90,6 +92,9 @@ describe("deposit", async function () { it("should deposit and withdraw", async function () { const signers = await ethers.getSigners(); + const [vault, asset, priceOracle, receipt] = + await deployERC20PriceOracleVault(); + const alice = signers[0]; const bob = signers[1]; @@ -234,6 +239,9 @@ describe("deposit", async function () { it("should trade erc1155", async function () { const signers = await ethers.getSigners(); + const [vault, asset, priceOracle, receipt] = + await deployERC20PriceOracleVault(); + const alice = signers[0]; const bob = signers[1]; diff --git a/test/priceOracle/Erc1155.test.ts b/test/priceOracle/Erc1155.test.ts index aa3324b4..a119861d 100644 --- a/test/priceOracle/Erc1155.test.ts +++ b/test/priceOracle/Erc1155.test.ts @@ -2,34 +2,35 @@ import { ethers } from "hardhat"; import { deployERC20PriceOracleVault, expectedUri, - fixedPointMul + fixedPointMul, } from "../util"; const assert = require("assert"); -describe("erc1155 usage", async function() { - const [vault, erc20Token, priceOracle, receipt] = - await deployERC20PriceOracleVault(); - it("should initialize well", async function() { +describe("erc1155 usage", async function () { + it("should initialize well", async function () { + const [vault, asset, price, receipt] = await deployERC20PriceOracleVault(); const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; const id = 12345; const erc1155Uri = await receipt.connect(alice).uri(id); assert( erc1155Uri === expectedUri, - `erc1155 did not construct with correct uri expected - ${ expectedUri }, got - ${ erc1155Uri } ` + `erc1155 did not construct with correct uri expected - ${expectedUri}, got - ${erc1155Uri} ` ); }); - it("should only send itself", async function() { + it("should only send itself", async function () { const signers = await ethers.getSigners(); + const [vault, erc20Token, priceOracle, receipt] = + await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); - const alice = signers[ 0 ]; - const bob = signers[ 1 ]; + const alice = signers[0]; + const bob = signers[1]; const depositAmount = ethers.BigNumber.from(1000); await erc20Token @@ -37,12 +38,12 @@ describe("erc1155 usage", async function() { .increaseAllowance(vault.address, depositAmount); await vault .connect(alice) - [ "deposit(uint256,address,uint256,bytes)" ]( - depositAmount, - alice.address, - shareRatio, - [] - ); + ["deposit(uint256,address,uint256,bytes)"]( + depositAmount, + alice.address, + shareRatio, + [] + ); const expectedErc20Balance = fixedPointMul(depositAmount, shareRatio); const expectedErc20BalanceAfter = expectedErc20Balance; @@ -52,18 +53,18 @@ describe("erc1155 usage", async function() { const erc20Balance = await vault .connect(alice) - [ "balanceOf(address)" ](signers[ 0 ].address); + ["balanceOf(address)"](signers[0].address); assert( erc20Balance.eq(expectedErc20Balance), - `wrong erc20 balance ${ expectedErc20Balance } ${ erc20Balance }` + `wrong erc20 balance ${expectedErc20Balance} ${erc20Balance}` ); const erc1155Balance = await receipt .connect(alice) - [ "balanceOf(address,uint256)" ](alice.address, expected1155ID); + ["balanceOf(address,uint256)"](alice.address, expected1155ID); assert( erc1155Balance.eq(expectedErc1155Balance), - `wrong erc1155 balance ${ expectedErc20Balance } ${ erc1155Balance }` + `wrong erc1155 balance ${expectedErc20Balance} ${erc1155Balance}` ); await receipt @@ -78,34 +79,34 @@ describe("erc1155 usage", async function() { const erc20BalanceAfter = await vault .connect(alice) - [ "balanceOf(address)" ](alice.address); + ["balanceOf(address)"](alice.address); assert( erc20BalanceAfter.eq(expectedErc20BalanceAfter), - `wrong erc20 balance after ${ expectedErc20BalanceAfter } ${ erc20BalanceAfter }` + `wrong erc20 balance after ${expectedErc20BalanceAfter} ${erc20BalanceAfter}` ); const erc20BalanceAfter2 = await vault .connect(bob) - [ "balanceOf(address)" ](bob.address); + ["balanceOf(address)"](bob.address); assert( erc20BalanceAfter2.eq(0), - `wrong erc20 balance after 2 0 ${ erc20BalanceAfter2 }` + `wrong erc20 balance after 2 0 ${erc20BalanceAfter2}` ); const erc1155BalanceAfter = await receipt .connect(alice) - [ "balanceOf(address,uint256)" ](alice.address, expected1155ID); + ["balanceOf(address,uint256)"](alice.address, expected1155ID); assert( erc1155BalanceAfter.eq(expectedErc1155BalanceAfter), - `wrong erc1155 balance after ${ expectedErc1155BalanceAfter } ${ erc1155BalanceAfter }` + `wrong erc1155 balance after ${expectedErc1155BalanceAfter} ${erc1155BalanceAfter}` ); const erc1155BalanceAfter2 = await receipt .connect(bob) - [ "balanceOf(address,uint256)" ](bob.address, expected1155ID); + ["balanceOf(address,uint256)"](bob.address, expected1155ID); assert( erc1155BalanceAfter2.eq(expectedErc1155BalanceAfter), - `wrong erc1155 balance 2 after ${ expectedErc1155BalanceAfter } ${ erc1155BalanceAfter2 }` + `wrong erc1155 balance 2 after ${expectedErc1155BalanceAfter} ${erc1155BalanceAfter2}` ); }); }); diff --git a/test/priceOracle/Erc20.test.ts b/test/priceOracle/Erc20.test.ts index cb28b94b..917b5dd4 100644 --- a/test/priceOracle/Erc20.test.ts +++ b/test/priceOracle/Erc20.test.ts @@ -8,13 +8,12 @@ import { const assert = require("assert"); describe("erc20 usage", async function () { - const [vault, asset, priceOracle, receipt] = - await deployERC20PriceOracleVault(); - it("should construct well", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployERC20PriceOracleVault(); + const erc20Name = await vault.connect(alice).name(); const erc20Symbol = await vault.connect(alice).symbol(); @@ -31,6 +30,9 @@ describe("erc20 usage", async function () { it("should only send itself", async function () { const signers = await ethers.getSigners(); + const [vault, asset, priceOracle, receipt] = + await deployERC20PriceOracleVault(); + const alice = signers[0]; const bob = signers[1]; let shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/Mint.test.ts b/test/priceOracle/Mint.test.ts index e2ee26c6..a3487cc8 100644 --- a/test/priceOracle/Mint.test.ts +++ b/test/priceOracle/Mint.test.ts @@ -11,12 +11,12 @@ import { const assert = require("assert"); describe("Mint", async function () { - const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); - it("Sets maxShares correctly", async function () { const signers = await ethers.getSigners(); const owner = signers[0]; + const [vault] = await deployERC20PriceOracleVault(); + const expectedMaxShares = ethers.BigNumber.from(2) .pow(256) //up to 2**256 so should substruct 1 @@ -29,6 +29,7 @@ describe("Mint", async function () { ); }); it("Checks min share ratio is less than share ratio", async function () { + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); const signers = await ethers.getSigners(); @@ -48,6 +49,7 @@ describe("Mint", async function () { ); }); it("PreviewMint - Calculates assets correctly with round up", async function () { + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); const signers = await ethers.getSigners(); const alice = signers[0]; @@ -69,6 +71,8 @@ describe("Mint", async function () { it("Mint - Calculates assets correctly while minShareRation is set", async function () { const signers = await ethers.getSigners(); + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + const alice = signers[0]; const assets = ethers.BigNumber.from(5000); @@ -98,6 +102,8 @@ describe("Mint", async function () { it("Mint - Calculates assets correctly", async function () { const signers = await ethers.getSigners(); + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + const alice = signers[0]; const assets = ethers.BigNumber.from(5000); @@ -126,6 +132,7 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployERC20PriceOracleVault(); const shares = ethers.BigNumber.from(0); await assertError( @@ -164,6 +171,8 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + const assets = ethers.BigNumber.from(5000); await asset.transfer(alice.address, assets); await asset.connect(alice).increaseAllowance(vault.address, assets); @@ -194,6 +203,7 @@ describe("Mint", async function () { ); }); it("Mint Overloaded - Checks min share ratio is less than share ratio", async function () { + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); const shareRatio = await priceOracle.price(); const signers = await ethers.getSigners(); @@ -223,6 +233,8 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + const assets = ethers.BigNumber.from(5000); await asset.transfer(alice.address, assets); await asset.connect(alice).increaseAllowance(vault.address, assets); @@ -249,6 +261,8 @@ describe("Mint", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault, asset, priceOracle] = await deployERC20PriceOracleVault(); + const shareRatio = await priceOracle.price(); await assertError( diff --git a/test/priceOracle/Redeem.test.ts b/test/priceOracle/Redeem.test.ts index 90be4876..54b0b356 100644 --- a/test/priceOracle/Redeem.test.ts +++ b/test/priceOracle/Redeem.test.ts @@ -25,12 +25,13 @@ let vault: ERC20PriceOracleReceiptVault, describe("Redeem", async function () { let alice; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptVault] = - await deployERC20PriceOracleVault(); beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptVault] = + await deployERC20PriceOracleVault(); + vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/RedeemOverloaded.test.ts b/test/priceOracle/RedeemOverloaded.test.ts index 7f04dd9b..6482508b 100644 --- a/test/priceOracle/RedeemOverloaded.test.ts +++ b/test/priceOracle/RedeemOverloaded.test.ts @@ -25,12 +25,13 @@ let vault: ERC20PriceOracleReceiptVault, describe("Overloaded Redeem", async function () { let alice; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = - await deployERC20PriceOracleVault(); beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = + await deployERC20PriceOracleVault(); + vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/Withdraw.test.ts b/test/priceOracle/Withdraw.test.ts index c27f7222..24e24ff0 100644 --- a/test/priceOracle/Withdraw.test.ts +++ b/test/priceOracle/Withdraw.test.ts @@ -26,13 +26,13 @@ let vault: ERC20PriceOracleReceiptVault, describe("Withdraw", async function () { let alice; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = - await deployERC20PriceOracleVault(); - beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = + await deployERC20PriceOracleVault(); + vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); diff --git a/test/priceOracle/WithdrawOverloaded.test.ts b/test/priceOracle/WithdrawOverloaded.test.ts index 7acd92c7..8d4725f7 100644 --- a/test/priceOracle/WithdrawOverloaded.test.ts +++ b/test/priceOracle/WithdrawOverloaded.test.ts @@ -26,13 +26,13 @@ let vault: ERC20PriceOracleReceiptVault, describe("Overloaded Withdraw", async function () { let alice; - const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = - await deployERC20PriceOracleVault(); - beforeEach(async () => { const signers = await ethers.getSigners(); alice = signers[0]; + const [ERC20PriceOracleVault, Erc20Asset, priceOracle, receiptContract] = + await deployERC20PriceOracleVault(); + vault = await ERC20PriceOracleVault; asset = await Erc20Asset; shareRatio = await priceOracle.price(); From d14899bf2465bd051bcb79eb78f49ff931614ac4 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Wed, 15 May 2024 14:48:35 +0400 Subject: [PATCH 09/11] Revert "Create one contract and use it to all tests - Factory and roles tests" This reverts commit 7fa93925f20bed763ec13cca97987d6f159a9dda. --- test/offchainAsset/Factory.test.ts | 20 +++-- test/offchainAsset/Roles.test.ts | 125 +++++++++++++++-------------- 2 files changed, 78 insertions(+), 67 deletions(-) diff --git a/test/offchainAsset/Factory.test.ts b/test/offchainAsset/Factory.test.ts index 45884b9a..d6266d5d 100644 --- a/test/offchainAsset/Factory.test.ts +++ b/test/offchainAsset/Factory.test.ts @@ -1,17 +1,21 @@ import { ethers } from "hardhat"; import { - OffchainAssetReceiptVaultFactory + OffchainAssetReceiptVaultFactory, + ReceiptFactory, } from "../../typechain-types"; -import { getEventArgs } from "../util"; +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { expectedUri, getEventArgs } from "../util"; import { deployOffchainAssetReceiptVaultFactory } from "./deployOffchainAssetReceiptVault"; const assert = require("assert"); let offchainAssetReceiptVaultFactory: OffchainAssetReceiptVaultFactory; -describe("OffchainAssetReceiptVaultFactory Test", async () => { - offchainAssetReceiptVaultFactory = - await deployOffchainAssetReceiptVaultFactory(); +describe("OffchainAssetReceiptVaultFactory Test", () => { + before(async () => { + offchainAssetReceiptVaultFactory = + await deployOffchainAssetReceiptVaultFactory(); + }); it("Should deploy Factory correctly", async () => { assert( @@ -21,15 +25,15 @@ describe("OffchainAssetReceiptVaultFactory Test", async () => { it("Should createChild", async () => { const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; const constructionConfig = { admin: alice.address, vaultConfig: { asset: ethers.constants.AddressZero, name: "OffchainAssetReceiptVault", - symbol: "OAV" - } + symbol: "OAV", + }, }; let tx = await offchainAssetReceiptVaultFactory.createChildTyped( diff --git a/test/offchainAsset/Roles.test.ts b/test/offchainAsset/Roles.test.ts index c8321760..2569f79a 100644 --- a/test/offchainAsset/Roles.test.ts +++ b/test/offchainAsset/Roles.test.ts @@ -8,12 +8,10 @@ import assert from "assert"; let TierV2TestContract: ReadWriteTier; -describe("OffChainAssetReceiptVault Roles", async function() { - const [vault, receipt] = await deployOffChainAssetReceiptVault(); - - it("Checks Admin roles granted", async function() { +describe("OffChainAssetReceiptVault Roles", async function () { + it("Checks Admin roles granted", async function () { const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; const [vault] = await deployOffChainAssetReceiptVault(); const DEPOSITOR_ADMIN = await vault.connect(alice).DEPOSITOR_ADMIN(); @@ -56,46 +54,47 @@ describe("OffChainAssetReceiptVault Roles", async function() { assert( DEPOSITOR_ADMIN_Granted === true, - `No ${ DEPOSITOR_ADMIN_Granted } role granted` + `No ${DEPOSITOR_ADMIN_Granted} role granted` ); assert( WITHDRAWER_ADMIN_Granted === true, - `No ${ WITHDRAWER_ADMIN_Granted } role granted` + `No ${WITHDRAWER_ADMIN_Granted} role granted` ); assert( CERTIFIER_ADMIN_Granted === true, - `No ${ CERTIFIER_ADMIN_Granted } role granted` + `No ${CERTIFIER_ADMIN_Granted} role granted` ); assert( HANDLER_ADMIN_Granted === true, - `No ${ HANDLER_ADMIN_Granted } role granted` + `No ${HANDLER_ADMIN_Granted} role granted` ); assert( ERC20TIERER_ADMIN_Granted === true, - `No ${ ERC20TIERER_ADMIN_Granted } role granted` + `No ${ERC20TIERER_ADMIN_Granted} role granted` ); assert( ERC1155TIERER_ADMIN_Granted === true, - `No ${ ERC1155TIERER_ADMIN_Granted } role granted` + `No ${ERC1155TIERER_ADMIN_Granted} role granted` ); assert( ERC20SNAPSHOTTER_ADMIN_Granted === true, - `No ${ ERC20SNAPSHOTTER_ADMIN_Granted } role granted` + `No ${ERC20SNAPSHOTTER_ADMIN_Granted} role granted` ); assert( CONFISCATOR_ADMIN_Granted === true, - `No ${ CONFISCATOR_ADMIN_Granted } role granted` + `No ${CONFISCATOR_ADMIN_Granted} role granted` ); }); - it("Gets 0 shares for deposit without depositor role", async function() { + it("Gets 0 shares for deposit without depositor role", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); - const asset = ( await testErc20.deploy() ) as TestErc20; + const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); - const alice = signers[ 0 ]; - const bob = signers[ 1 ]; + const alice = signers[0]; + const bob = signers[1]; const shareRatio = ONE; const aliceAssets = ethers.BigNumber.from(1000); @@ -108,24 +107,26 @@ describe("OffChainAssetReceiptVault Roles", async function() { async () => await vault .connect(alice) - [ "deposit(uint256,address,uint256,bytes)" ]( - aliceAssets, - bob.address, - shareRatio, - [] - ), + ["deposit(uint256,address,uint256,bytes)"]( + aliceAssets, + bob.address, + shareRatio, + [] + ), `MinShareRatio`, "Failed to deposit" ); }); - it("Checks withdraw without depositor role", async function() { + it("Checks withdraw without depositor role", async function () { const signers = await ethers.getSigners(); + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const testErc20 = await ethers.getContractFactory("TestErc20"); - const asset = ( await testErc20.deploy() ) as TestErc20; + const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); - const alice = signers[ 0 ]; - const bob = signers[ 1 ]; + const alice = signers[0]; + const bob = signers[1]; const shareRatio = ethers.BigNumber.from(1); const aliceAssets = ethers.BigNumber.from(10); @@ -151,12 +152,12 @@ describe("OffChainAssetReceiptVault Roles", async function() { await vault .connect(alice) - [ "deposit(uint256,address,uint256,bytes)" ]( - aliceAssets, - bob.address, - shareRatio, - [] - ); + ["deposit(uint256,address,uint256,bytes)"]( + aliceAssets, + bob.address, + shareRatio, + [] + ); const balance = await receipt .connect(alice) @@ -167,13 +168,13 @@ describe("OffChainAssetReceiptVault Roles", async function() { .grantRole(await vault.connect(alice).WITHDRAWER(), bob.address); await vault .connect(bob) - [ "redeem(uint256,address,address,uint256,bytes)" ]( - balance, - bob.address, - bob.address, - shareRatio, - [] - ); + ["redeem(uint256,address,address,uint256,bytes)"]( + balance, + bob.address, + bob.address, + shareRatio, + [] + ); const balanceAfter = await receipt .connect(alice) @@ -181,16 +182,18 @@ describe("OffChainAssetReceiptVault Roles", async function() { assert( balanceAfter.isZero(), - `wrong assets. expected ${ ethers.BigNumber.from(0) } got ${ balanceAfter }` + `wrong assets. expected ${ethers.BigNumber.from(0)} got ${balanceAfter}` ); }); - it("Checks SetERC20Tier role", async function() { + it("Checks SetERC20Tier role", async function () { const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); - TierV2TestContract = ( await TierV2Test.deploy() ) as ReadWriteTier; + TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; await TierV2TestContract.deployed(); + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; const minTier = ethers.BigNumber.from(10); @@ -199,18 +202,20 @@ describe("OffChainAssetReceiptVault Roles", async function() { await vault .connect(alice) .setERC20Tier(TierV2TestContract.address, minTier, [], []), - `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault + `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault .connect(alice) - .ERC20TIERER() }`, + .ERC20TIERER()}`, "Failed to set erc20tier" ); }); - it("Checks setERC1155Tier role", async function() { + it("Checks setERC1155Tier role", async function () { const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); - TierV2TestContract = ( await TierV2Test.deploy() ) as ReadWriteTier; + TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; await TierV2TestContract.deployed(); + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; const minTier = ethers.BigNumber.from(10); @@ -219,27 +224,29 @@ describe("OffChainAssetReceiptVault Roles", async function() { await vault .connect(alice) .setERC1155Tier(TierV2TestContract.address, minTier, [], []), - `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault + `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault .connect(alice) - .ERC1155TIERER() }`, + .ERC1155TIERER()}`, "Failed to set erc1155tier" ); }); - it("Checks role for snapshotter", async function() { + it("Checks role for snapshotter", async function () { const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); await assertError( async () => await vault.connect(alice).snapshot([]), - `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault + `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault .connect(alice) - .ERC20SNAPSHOTTER() }`, + .ERC20SNAPSHOTTER()}`, "failed to snapshot" ); }); - it("Checks role for certifier", async function() { + it("Checks role for certifier", async function () { const signers = await ethers.getSigners(); - const alice = signers[ 0 ]; + const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -251,9 +258,9 @@ describe("OffChainAssetReceiptVault Roles", async function() { await vault .connect(alice) .certify(_until, _referenceBlockNumber, false, []), - `AccessControl: account ${ alice.address.toLowerCase() } is missing role ${ await vault + `AccessControl: account ${alice.address.toLowerCase()} is missing role ${await vault .connect(alice) - .CERTIFIER() }`, + .CERTIFIER()}`, "failed to certify" ); }); From 5a350c44b49a676ab36fc5b3768e0c438425ec8f Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Wed, 15 May 2024 14:48:39 +0400 Subject: [PATCH 10/11] Revert "Create one contract and use it to all tests" This reverts commit e93b0f921cd028042a3a7066caa944cb3e1dd66e. --- .../OffChainAssetReceiptVault.test.ts | 101 ++++++++++++++++-- 1 file changed, 92 insertions(+), 9 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 77da3df2..6f003388 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -34,15 +34,15 @@ let expectedName = "OffchainAssetVaul"; let expectedSymbol = "OAV"; describe("OffChainAssetReceiptVault", async function () { - const [vault, receipt, config] = await deployOffChainAssetReceiptVault(); - const offchainAssetReceiptVaultFactory = - await deployOffchainAssetReceiptVaultFactory(); - - const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); - TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; - await TierV2TestContract.deployed(); - + beforeEach(async () => { + const TierV2Test = await ethers.getContractFactory("ReadWriteTier"); + TierV2TestContract = (await TierV2Test.deploy()) as ReadWriteTier; + await TierV2TestContract.deployed(); + }); it("Check admin is not address zero", async function () { + const offchainAssetReceiptVaultFactory = + await deployOffchainAssetReceiptVaultFactory(); + const constructionConfig = { admin: ADDRESS_ZERO, vaultConfig: { @@ -65,6 +65,9 @@ describe("OffChainAssetReceiptVault", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const offchainAssetReceiptVaultFactory = + await deployOffchainAssetReceiptVaultFactory(); + const constructionConfig = { admin: alice.address, vaultConfig: { @@ -84,6 +87,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Constructs well", async function () { + const [, , config] = await deployOffChainAssetReceiptVault(); + assert( config.receiptVaultConfig.vaultConfig.name === expectedName, `wrong name expected ${expectedName} got ${config.receiptVaultConfig.vaultConfig.name}` @@ -99,6 +104,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Check vault is the owner of its receipt", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; @@ -109,6 +115,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Checks SetERC20Tier event is emitted", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -140,6 +148,8 @@ describe("OffChainAssetReceiptVault", async function () { assert(data === "0x01", `wrong data expected 0x01 got ${data}`); }); it("Checks setERC1155Tier event is emitted", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -172,6 +182,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Checks totalAssets", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -220,6 +231,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewDeposit returns correct shares", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const assets = ethers.BigNumber.from(100); const signers = await ethers.getSigners(); @@ -248,6 +260,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewMint returns correct assets", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(10); const signers = await ethers.getSigners(); @@ -266,6 +279,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewWithdraw returns 0 shares if no withdrawer role", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const assets = ethers.BigNumber.from(100); const signers = await ethers.getSigners(); @@ -285,6 +299,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewWithdraw returns correct shares", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const assets = ethers.BigNumber.from(10); const signers = await ethers.getSigners(); @@ -310,6 +325,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Mints with data", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; @@ -342,6 +358,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Cannot Mint to someone else if recipient is not DEPOSITOR or system not certified for them", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -372,6 +389,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Mints to someone else if recipient is not DEPOSITOR but system certified for them", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -415,6 +433,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Mints to someone else if recipient is DEPOSITOR", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -451,6 +470,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Cannot Deposit to someone else if recipient is not DEPOSITOR or system not certified for them", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -479,6 +499,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Deposits to someone else if recipient is not DEPOSITOR but system certified for them", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -519,6 +540,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Deposits to someone else if recipient is DEPOSITOR", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -552,6 +574,7 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewRedeem returns correct assets", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(100); const signers = await ethers.getSigners(); @@ -585,6 +608,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("PreviewRedeem returns 0 shares if no withdrawer role", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -627,6 +652,8 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Redeposits", async function () { const signers = await ethers.getSigners(); + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -645,7 +672,7 @@ describe("OffChainAssetReceiptVault", async function () { .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assetToDeposit = aliceAssets.div(2); - const assetToReDeposit = ethers.BigNumber.from(10); + const assetToReDeposit = ethers.BigNumber.from(0); await vault .connect(alice) ["deposit(uint256,address,uint256,bytes)"]( @@ -678,6 +705,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Prevents redeposit to someone else while not certified or recipient is not depositor", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -719,6 +747,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Redeposits to someone else while certified", async function () { const signers = await ethers.getSigners(); + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -781,6 +810,8 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Prevents Redeposit on receipt with id 0", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); + const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -806,6 +837,8 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Prevents Redeposit on non-existing receipt", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); + const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -832,6 +865,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Snapshot event is emitted", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) @@ -848,6 +882,7 @@ describe("OffChainAssetReceiptVault", async function () { it("SnapshotWithData event is emitted", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) @@ -868,6 +903,8 @@ describe("OffChainAssetReceiptVault", async function () { assert(data === "0x01", `Wrong information. Expected 0x01, got ${data}`); }); it("Sets correct erc20Tier and mintier", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -898,6 +935,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Sets correct erc11Tier and mintier", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -928,6 +967,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Checks Certify event is emitted", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -963,6 +1004,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Certifies with data", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -1000,6 +1043,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Certify in the past relative to the existing certification time with forceUntil true", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; @@ -1038,6 +1083,8 @@ describe("OffChainAssetReceiptVault", async function () { it("Checks certifiedUntil is not zero", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); + const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); const _certifiedUntil = ethers.BigNumber.from(0); @@ -1059,6 +1106,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Checks referenceBlockNumber is less than block number", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -1081,6 +1129,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Certifies", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -1107,6 +1156,7 @@ describe("OffChainAssetReceiptVault", async function () { it("AuthorizeReceiptTransfer reverts if certification expired", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); await assertError( async () => @@ -1120,6 +1170,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Confiscate - Checks role CONFISCATOR", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); await assertError( async () => @@ -1133,6 +1184,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Confiscate - Checks ConfiscateShares is NOT emitted on Zero balance", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) @@ -1156,6 +1208,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Confiscate - Checks ConfiscateShares is emitted", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1206,6 +1259,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Confiscate receipts - Checks ConfiscateReceipt is emitted", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1271,6 +1325,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Confiscate receipts - Checks ConfiscateReceipt is NOT emitted on zero balance", async function () { const signers = await ethers.getSigners(); + const [vault] = await deployOffChainAssetReceiptVault(); const alice = signers[0]; @@ -1298,6 +1353,7 @@ describe("OffChainAssetReceiptVault", async function () { it("Checks confiscated is same as balance", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; + const [vault] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1346,6 +1402,7 @@ describe("OffChainAssetReceiptVault", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; + const [vault] = await deployOffChainAssetReceiptVault(); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); @@ -1401,6 +1458,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Checks confiscated is same as receipt balance", async function () { const signers = await ethers.getSigners(); + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; @@ -1472,6 +1530,7 @@ describe("OffChainAssetReceiptVault", async function () { }); it("Checks confiscated amount is transferred", async function () { const signers = await ethers.getSigners(); + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const alice = signers[0]; const bob = signers[1]; @@ -1542,6 +1601,7 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; + const [vault, receipt] = await deployOffChainAssetReceiptVault(); const testErc20 = await ethers.getContractFactory("TestErc20"); const testErc20Contract = (await testErc20.deploy()) as TestErc20; await testErc20Contract.deployed(); @@ -1609,6 +1669,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Should not withdraw on more than balance", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const id = ethers.BigNumber.from(1); @@ -1655,6 +1717,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("User not being able to withdraw someone else's share", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1702,6 +1766,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Prevent authorizeReceiptTransfer if system not certified", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1716,6 +1782,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Prevent authorizeReceiptTransfer if unauthorizedSenderTier", async function () { + const [vault] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1756,6 +1824,8 @@ describe("OffChainAssetReceiptVault", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; + + const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); @@ -1776,6 +1846,7 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; + const [vault] = await deployOffChainAssetReceiptVault(); await vault .connect(alice) .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); @@ -1796,6 +1867,8 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -1845,6 +1918,8 @@ describe("OffChainAssetReceiptVault", async function () { const alice = signers[0]; const bob = signers[1]; + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const testErc20 = await ethers.getContractFactory("TestErc20"); const asset = (await testErc20.deploy()) as TestErc20; await asset.deployed(); @@ -1893,6 +1968,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Withdraw on someone else", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -1954,6 +2031,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Check withdraw for alice", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const id = 1; @@ -2017,6 +2096,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Redeems on someone else", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const bob = signers[1]; @@ -2078,6 +2159,8 @@ describe("OffChainAssetReceiptVault", async function () { ); }); it("Check redeem for alice", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + const signers = await ethers.getSigners(); const alice = signers[0]; const id = 1; From 5e6aa100bdf7b36390f5dd373911c65271200878 Mon Sep 17 00:00:00 2001 From: ninokeldishvili Date: Wed, 15 May 2024 15:02:26 +0400 Subject: [PATCH 11/11] Fix redeposit test --- test/offchainAsset/OffChainAssetReceiptVault.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 6f003388..80eea4c4 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -672,7 +672,7 @@ describe("OffChainAssetReceiptVault", async function () { .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assetToDeposit = aliceAssets.div(2); - const assetToReDeposit = ethers.BigNumber.from(0); + const assetToReDeposit = ethers.BigNumber.from(10); await vault .connect(alice) ["deposit(uint256,address,uint256,bytes)"](