From 725841274cced9c1dfd8b3e554a8b0aef3895c76 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 18:16:59 +0400 Subject: [PATCH 01/17] Cannot Mint to someone else if recipient is not DEPOSITOR or system not certified for them --- .../OffChainAssetReceiptVault.test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 12d64493..8be9c021 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -357,6 +357,35 @@ describe("OffChainAssetReceiptVault", async function () { `wrong assets. expected ${expectedAssets} got ${aliceBalanceAfter}` ); }); + 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]; + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const asset = (await testErc20.deploy()) as TestErc20; + await asset.deployed(); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assets = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, assets); + await asset.connect(alice).increaseAllowance(vault.address, assets); + + const shares = fixedPointMul(assets, ONE).add(1); + + await assertError( + async () => + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [1]), + `CertificationExpired`, + "Failed to mint" + ); + }); it("PreviewRedeem returns correct assets", async function () { const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(100); From 811599c9384a99ff50c085de9a5d557ed7e341e2 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 18:17:30 +0400 Subject: [PATCH 02/17] Add offchainAssetReceiptVault_Ethereum.ts construction arguments for ethereum --- .../offchainAssetReceiptVault_Ethereum.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 scripts/constructorArguments/offchainAssetReceiptVault_Ethereum.ts diff --git a/scripts/constructorArguments/offchainAssetReceiptVault_Ethereum.ts b/scripts/constructorArguments/offchainAssetReceiptVault_Ethereum.ts new file mode 100644 index 00000000..72761a54 --- /dev/null +++ b/scripts/constructorArguments/offchainAssetReceiptVault_Ethereum.ts @@ -0,0 +1,6 @@ +module.exports = [ + { + implementation: "0x486303714EB5185742acBC63F119fda3b7E637AE", + receiptFactory: "0xd5753d6B68712bda48d4867186d7BED9db3656A5", + }, +]; From 32e888059da71b6ed079448efd01dd2b6482f33b Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 18:27:19 +0400 Subject: [PATCH 03/17] Mints to someone else if recipient is not DEPOSITOR but system certified for them --- .../OffChainAssetReceiptVault.test.ts | 58 +++++++++++++++++-- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 8be9c021..fbc88829 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -378,12 +378,58 @@ describe("OffChainAssetReceiptVault", async function () { const shares = fixedPointMul(assets, ONE).add(1); await assertError( - async () => - await vault - .connect(alice) - ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [1]), - `CertificationExpired`, - "Failed to mint" + async () => + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [ + 1, + ]), + `CertificationExpired`, + "Failed to mint" + ); + }); + 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]; + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const asset = (await testErc20.deploy()) as TestErc20; + await asset.deployed(); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assets = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, assets); + await asset.connect(alice).increaseAllowance(vault.address, assets); + + const shares = fixedPointMul(assets, ONE).add(1); + + const blockNum = await ethers.provider.getBlockNumber(); + const block = await ethers.provider.getBlock(blockNum); + const _until = block.timestamp + 100; + const _referenceBlockNumber = block.number; + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).CERTIFIER(), bob.address); + + await vault.connect(bob).certify(_until, _referenceBlockNumber, false, []); + + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [1]); + const expectedAssets = fixedPointDiv(shares, ONE); + const bobBalanceAfter = await receipt + .connect(alice) + ["balanceOf(address,uint256)"](bob.address, 1); + + assert( + bobBalanceAfter.eq(expectedAssets), + `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` ); }); it("PreviewRedeem returns correct assets", async function () { From 0674e0677b7f2afde46023c4db5c2bf736b0a65f Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 18:32:04 +0400 Subject: [PATCH 04/17] Mints to someone else if recipient is DEPOSITOR --- .../OffChainAssetReceiptVault.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index fbc88829..6a484e65 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -432,6 +432,44 @@ describe("OffChainAssetReceiptVault", async function () { `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` ); }); + 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]; + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const asset = (await testErc20.deploy()) as TestErc20; + await asset.deployed(); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assets = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, assets); + await asset.connect(alice).increaseAllowance(vault.address, assets); + + const shares = fixedPointMul(assets, ONE).add(1); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); + + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [1]); + const expectedAssets = fixedPointDiv(shares, ONE); + const bobBalanceAfter = await receipt + .connect(alice) + ["balanceOf(address,uint256)"](bob.address, 1); + + assert( + bobBalanceAfter.eq(expectedAssets), + `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` + ); + }); + it("PreviewRedeem returns correct assets", async function () { const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(100); From b45a8a3863a697263111ac2cc25b7b038b5700ac Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 19:23:44 +0400 Subject: [PATCH 05/17] Redeposits to someone else while certified --- .../OffChainAssetReceiptVault.test.ts | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 6a484e65..1cfa06fc 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -469,7 +469,6 @@ describe("OffChainAssetReceiptVault", async function () { `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` ); }); - it("PreviewRedeem returns correct assets", async function () { const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(100); @@ -611,6 +610,71 @@ describe("OffChainAssetReceiptVault", async function () { )} got ${aliceReceiptBalanceAfterRedeposit}` ); }); + 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; + await asset.deployed(); + + const alice = signers[0]; + const bob = signers[1]; + + const receiptId = ethers.BigNumber.from(1); + const aliceAssets = ethers.BigNumber.from(20); + + await asset.connect(alice).transfer(alice.address, aliceAssets); + + await asset.connect(alice).increaseAllowance(vault.address, aliceAssets); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assetToDeposit = aliceAssets.div(2); + const assetToReDeposit = ethers.BigNumber.from(10); + await vault + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"]( + assetToDeposit, + alice.address, + receiptId, + [] + ); + + const bobReceiptBalance = await receipt + .connect(alice) + .balanceOf(bob.address, receiptId); + + const blockNum = await ethers.provider.getBlockNumber(); + const block = await ethers.provider.getBlock(blockNum); + const _certifiedUntil = block.timestamp + 100; + const _referenceBlockNumber = block.number; + await vault + .connect(alice) + .grantRole(await vault.connect(alice).CERTIFIER(), alice.address); + await vault + .connect(alice) + .certify(_certifiedUntil, _referenceBlockNumber, false, []); + + await vault + .connect(alice) + .redeposit(assetToReDeposit, bob.address, 1, [1]); + + const bobReceiptBalanceAfterRedeposit = await receipt + .connect(alice) + .balanceOf(bob.address, receiptId); + + assert( + bobReceiptBalanceAfterRedeposit.eq( + bobReceiptBalance.add(assetToReDeposit) + ), + `Incorrect balance ${bobReceiptBalance.add( + assetToReDeposit + )} got ${bobReceiptBalanceAfterRedeposit}` + ); + }); it("Prevents Redeposit on receipt with id 0", async function () { const signers = await ethers.getSigners(); const [vault] = await deployOffChainAssetReceiptVault(); From 8f85862e34742a1391f66b5e7a455e66c27cd26d Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 19:29:23 +0400 Subject: [PATCH 06/17] Prevents redeposit to someone else while not certified or recipient is not depositor --- .../OffChainAssetReceiptVault.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 1cfa06fc..c0f677c0 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -610,6 +610,48 @@ describe("OffChainAssetReceiptVault", async function () { )} got ${aliceReceiptBalanceAfterRedeposit}` ); }); + 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; + await asset.deployed(); + + const alice = signers[0]; + const bob = signers[1]; + + const receiptId = ethers.BigNumber.from(1); + const aliceAssets = ethers.BigNumber.from(20); + + await asset.connect(alice).transfer(alice.address, aliceAssets); + + await asset.connect(alice).increaseAllowance(vault.address, aliceAssets); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assetToDeposit = aliceAssets.div(2); + const assetToReDeposit = ethers.BigNumber.from(10); + await vault + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"]( + assetToDeposit, + alice.address, + receiptId, + [] + ); + + await assertError( + async () => + await vault + .connect(alice) + .redeposit(assetToReDeposit, bob.address, 1, [1]), + `CertificationExpired`, + "Failed to redeposit" + ); + }); it("Redeposits to someone else while certified", async function () { const signers = await ethers.getSigners(); const [vault, receipt] = await deployOffChainAssetReceiptVault(); From 30f72cd03d7dbc42cbdb05d58ce354b246e61f2e Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 19:29:47 +0400 Subject: [PATCH 07/17] Prettier --- .../OffChainAssetReceiptVault.test.ts | 84 +++++++++---------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index c0f677c0..296315db 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -443,8 +443,8 @@ describe("OffChainAssetReceiptVault", async function () { await asset.deployed(); await vault - .connect(alice) - .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assets = ethers.BigNumber.from(5000); await asset.transfer(alice.address, assets); @@ -453,20 +453,20 @@ describe("OffChainAssetReceiptVault", async function () { const shares = fixedPointMul(assets, ONE).add(1); await vault - .connect(alice) - .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); await vault - .connect(alice) - ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [1]); + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, bob.address, ONE, [1]); const expectedAssets = fixedPointDiv(shares, ONE); const bobBalanceAfter = await receipt - .connect(alice) - ["balanceOf(address,uint256)"](bob.address, 1); + .connect(alice) + ["balanceOf(address,uint256)"](bob.address, 1); assert( - bobBalanceAfter.eq(expectedAssets), - `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` + bobBalanceAfter.eq(expectedAssets), + `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` ); }); it("PreviewRedeem returns correct assets", async function () { @@ -629,27 +629,27 @@ describe("OffChainAssetReceiptVault", async function () { await asset.connect(alice).increaseAllowance(vault.address, aliceAssets); await vault - .connect(alice) - .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assetToDeposit = aliceAssets.div(2); const assetToReDeposit = ethers.BigNumber.from(10); await vault - .connect(alice) - ["deposit(uint256,address,uint256,bytes)"]( + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"]( assetToDeposit, alice.address, receiptId, [] - ); + ); await assertError( - async () => - await vault - .connect(alice) - .redeposit(assetToReDeposit, bob.address, 1, [1]), - `CertificationExpired`, - "Failed to redeposit" + async () => + await vault + .connect(alice) + .redeposit(assetToReDeposit, bob.address, 1, [1]), + `CertificationExpired`, + "Failed to redeposit" ); }); it("Redeposits to someone else while certified", async function () { @@ -671,50 +671,48 @@ describe("OffChainAssetReceiptVault", async function () { await asset.connect(alice).increaseAllowance(vault.address, aliceAssets); await vault - .connect(alice) - .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const assetToDeposit = aliceAssets.div(2); const assetToReDeposit = ethers.BigNumber.from(10); await vault - .connect(alice) - ["deposit(uint256,address,uint256,bytes)"]( + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"]( assetToDeposit, alice.address, receiptId, [] - ); + ); const bobReceiptBalance = await receipt - .connect(alice) - .balanceOf(bob.address, receiptId); + .connect(alice) + .balanceOf(bob.address, receiptId); const blockNum = await ethers.provider.getBlockNumber(); const block = await ethers.provider.getBlock(blockNum); const _certifiedUntil = block.timestamp + 100; const _referenceBlockNumber = block.number; await vault - .connect(alice) - .grantRole(await vault.connect(alice).CERTIFIER(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).CERTIFIER(), alice.address); await vault - .connect(alice) - .certify(_certifiedUntil, _referenceBlockNumber, false, []); + .connect(alice) + .certify(_certifiedUntil, _referenceBlockNumber, false, []); - await vault - .connect(alice) - .redeposit(assetToReDeposit, bob.address, 1, [1]); + await vault.connect(alice).redeposit(assetToReDeposit, bob.address, 1, [1]); const bobReceiptBalanceAfterRedeposit = await receipt - .connect(alice) - .balanceOf(bob.address, receiptId); + .connect(alice) + .balanceOf(bob.address, receiptId); assert( - bobReceiptBalanceAfterRedeposit.eq( - bobReceiptBalance.add(assetToReDeposit) - ), - `Incorrect balance ${bobReceiptBalance.add( - assetToReDeposit - )} got ${bobReceiptBalanceAfterRedeposit}` + bobReceiptBalanceAfterRedeposit.eq( + bobReceiptBalance.add(assetToReDeposit) + ), + `Incorrect balance ${bobReceiptBalance.add( + assetToReDeposit + )} got ${bobReceiptBalanceAfterRedeposit}` ); }); it("Prevents Redeposit on receipt with id 0", async function () { From ca7369a2568a263046f04cfdf46c27d694976f27 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Mon, 13 Feb 2023 20:02:55 +0400 Subject: [PATCH 08/17] Add tests for deposit to someone else --- .../OffChainAssetReceiptVault.test.ts | 106 +++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 296315db..95c90387 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -469,6 +469,110 @@ describe("OffChainAssetReceiptVault", async function () { `wrong assets. expected ${expectedAssets} got ${bobBalanceAfter}` ); }); + 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]; + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const asset = (await testErc20.deploy()) as TestErc20; + await asset.deployed(); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assets = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, assets); + await asset.connect(alice).increaseAllowance(vault.address, assets); + + await assertError( + async () => + await vault + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"](assets, bob.address, ONE, [ + 1, + ]), + `CertificationExpired`, + "Failed to mint" + ); + }); + 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]; + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const asset = (await testErc20.deploy()) as TestErc20; + await asset.deployed(); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assets = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, assets); + await asset.connect(alice).increaseAllowance(vault.address, assets); + + const blockNum = await ethers.provider.getBlockNumber(); + const block = await ethers.provider.getBlock(blockNum); + const _until = block.timestamp + 100; + const _referenceBlockNumber = block.number; + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).CERTIFIER(), bob.address); + + await vault.connect(bob).certify(_until, _referenceBlockNumber, false, []); + + await vault + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"](assets, bob.address, ONE, [1]); + const bobBalanceAfter = await receipt + .connect(alice) + ["balanceOf(address,uint256)"](bob.address, 1); + + assert( + bobBalanceAfter.eq(assets), + `wrong assets. expected ${assets} got ${bobBalanceAfter}` + ); + }); + 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]; + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const asset = (await testErc20.deploy()) as TestErc20; + await asset.deployed(); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const assets = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, assets); + await asset.connect(alice).increaseAllowance(vault.address, assets); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), bob.address); + + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](assets, bob.address, ONE, [1]); + const bobBalanceAfter = await receipt + .connect(alice) + ["balanceOf(address,uint256)"](bob.address, 1); + + assert( + bobBalanceAfter.eq(assets), + `wrong assets. expected ${assets} got ${bobBalanceAfter}` + ); + }); it("PreviewRedeem returns correct assets", async function () { const [vault] = await deployOffChainAssetReceiptVault(); const shares = ethers.BigNumber.from(100); @@ -1305,7 +1409,6 @@ describe("OffChainAssetReceiptVault", async function () { `wrong confiscated expected ${shares} got ${confiscated}` ); }); - it("Checks confiscated is transferred", async function () { const signers = await ethers.getSigners(); const alice = signers[0]; @@ -1364,7 +1467,6 @@ describe("OffChainAssetReceiptVault", async function () { `Shares has not been confiscated` ); }); - it("Checks confiscated is same as receipt balance", async function () { const signers = await ethers.getSigners(); const [vault, receipt] = await deployOffChainAssetReceiptVault(); From c47964fccf6df537d753d1bef8f24fd1a3f56e80 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Tue, 14 Feb 2023 13:06:15 +0400 Subject: [PATCH 09/17] Check the receipt info sender when withdrawer burns for a different receiver --- .../OffChainAssetReceiptVault.test.ts | 65 +++++++++++++++---- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 95c90387..b850524e 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -650,17 +650,6 @@ describe("OffChainAssetReceiptVault", async function () { `Wrong assets: expected ${expectedAssets} got ${assets} ` ); }); - it("Redeposit - should be receipt holder", async function () { - const signers = await ethers.getSigners(); - const alice = signers[0]; - const [, receipt] = await deployOffChainAssetReceiptVault(); - - const aliceReceiptBalance = await receipt - .connect(alice) - .balanceOf(alice.address, ONE); - - assert(aliceReceiptBalance.eq(0), `NOT_RECEIPT_HOLDER`); - }); it("Redeposits", async function () { const signers = await ethers.getSigners(); const [vault, receipt] = await deployOffChainAssetReceiptVault(); @@ -1919,6 +1908,60 @@ describe("OffChainAssetReceiptVault", async function () { receipt )) as ReceiptInformationEvent["args"]; + assert( + sender === alice.address, + `wrong receipt information sender ${alice.address} got ${sender}` + ); + }); + it("Check the receipt info sender when withdrawer burns for a different receiver", async () => { + const signers = await ethers.getSigners(); + 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(); + + const aliceAmount = ethers.BigNumber.from(5000); + await asset.transfer(alice.address, aliceAmount); + await asset.connect(alice).increaseAllowance(vault.address, aliceAmount); + + const expectedId = 1; + + const informationBytes = [125, 126]; + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + + await vault + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"]( + aliceAmount, + alice.address, + expectedId, + informationBytes + ) + + const { sender } = (await getEventArgs( + await vault + .connect(alice) + ["redeem(uint256,address,address,uint256,bytes)"]( + aliceAmount, + bob.address, + alice.address, + expectedId, + informationBytes + ), + "ReceiptInformation", + receipt + )) as ReceiptInformationEvent["args"]; + assert( sender === alice.address, `wrong receipt information sender ${alice.address} got ${sender}` From 9fda5a1976445e6e4093c04f3484263f8deb8988 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Tue, 14 Feb 2023 13:06:59 +0400 Subject: [PATCH 10/17] Prettier --- test/offchainAsset/OffChainAssetReceiptVault.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index b850524e..6b4bd02a 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -1940,13 +1940,13 @@ describe("OffChainAssetReceiptVault", async function () { .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); await vault - .connect(alice) - ["deposit(uint256,address,uint256,bytes)"]( + .connect(alice) + ["deposit(uint256,address,uint256,bytes)"]( aliceAmount, alice.address, expectedId, informationBytes - ) + ); const { sender } = (await getEventArgs( await vault From 0cd9f700f309985db1e6f08ec0fa681dd593b3f5 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Tue, 14 Feb 2023 16:33:21 +0400 Subject: [PATCH 11/17] Test the URL on a deployed receipt contract instead of hardcoded one --- test/IPFSPull.test.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/test/IPFSPull.test.ts b/test/IPFSPull.test.ts index ea73cdc6..5d3a248a 100644 --- a/test/IPFSPull.test.ts +++ b/test/IPFSPull.test.ts @@ -1,12 +1,41 @@ import erc1155Metadata from "../erc1155Metadata/ReceiptMetadata.json"; import assert from "assert"; +import { artifacts, ethers } from "hardhat"; +import { Receipt, ReceiptFactory } from "../typechain-types"; +import { expectedUri, getEventArgs } from "./util"; +import { Contract } from "ethers"; describe("IPFS pull", async function () { it("Pulls data from ipfs and checks it", async function () { this.timeout(0); - const resp = await fetch( - "https://ipfs.io/ipfs/bafkreih7cvpjocgrk7mgdel2hvjpquc26j4jo2jkez5y2qdaojfil7vley" + + const signers = await ethers.getSigners(); + const alice = signers[0]; + + const receiptFactoryFactory = await ethers.getContractFactory( + "ReceiptFactory" + ); + const receiptFactoryContract = + (await receiptFactoryFactory.deploy()) as ReceiptFactory; + await receiptFactoryContract.deployed(); + + let tx = await receiptFactoryContract.createChild([]); + + const { child } = await getEventArgs( + tx, + "NewChild", + receiptFactoryContract ); + + let childContract = new Contract( + child, + (await artifacts.readArtifact("Receipt")).abi + ) as Receipt; + + let uri = await childContract.connect(alice).uri(1); + + const resp = await fetch(`https://ipfs.io/ipfs/${uri.slice(7)}`); + const ipfsData = await resp.json().catch(console.error); assert( From deafc7395e183f2b23af7edcc33c5fc15daa78cd Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Wed, 15 Feb 2023 15:30:08 +0400 Subject: [PATCH 12/17] WIP - withdraw --- .../OffChainAssetReceiptVault.test.ts | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 6b4bd02a..4f9200a5 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -1967,4 +1967,63 @@ describe("OffChainAssetReceiptVault", async function () { `wrong receipt information sender ${alice.address} got ${sender}` ); }); + it.only("Withdraw on someone else", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + + const signers = await ethers.getSigners(); + const alice = signers[0]; + const bob = signers[1]; + const id = 1; + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const testErc20Contract = (await testErc20.deploy()) as TestErc20; + await testErc20Contract.deployed(); + + const assets = ethers.BigNumber.from(30); + await testErc20Contract.transfer(alice.address, assets); + await testErc20Contract + .connect(alice) + .increaseAllowance(vault.address, assets); + + const shares = ethers.BigNumber.from(10); + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); + + const balance = await receipt.connect(alice).balanceOf(alice.address, id); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + + await vault + .connect(alice) + ["withdraw(uint256,address,address,uint256,bytes)"]( + balance, + bob.address, + alice.address, + id, + [] + ) + + + // await assertError( + // async () => + // await vault + // .connect(alice) + // ["redeem(uint256,address,address,uint256,bytes)"]( + // balance.add(1), + // alice.address, + // alice.address, + // id, + // [] + // ), + // "ERC20: burn amount exceeds balance", + // "failed to prevent withdraw on more than balance" + // ); + }); }); From 213c13dacc5f7e857bdd96c354872d9861821dd9 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 16 Feb 2023 12:33:30 +0400 Subject: [PATCH 13/17] "Withdraw on someone else --- .../OffChainAssetReceiptVault.test.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 4f9200a5..df4bba2f 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -1967,7 +1967,7 @@ describe("OffChainAssetReceiptVault", async function () { `wrong receipt information sender ${alice.address} got ${sender}` ); }); - it.only("Withdraw on someone else", async function () { + it("Withdraw on someone else", async function () { const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); @@ -1975,6 +1975,7 @@ describe("OffChainAssetReceiptVault", async function () { const bob = signers[1]; const id = 1; + //grant depositor role to alice await vault .connect(alice) .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); @@ -2000,6 +2001,9 @@ describe("OffChainAssetReceiptVault", async function () { .connect(alice) .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + let bobBalanceVault = await vault.connect(alice).balanceOf(bob.address) + let aliceBalanceVault = await vault.connect(alice).balanceOf(alice.address) + await vault .connect(alice) ["withdraw(uint256,address,address,uint256,bytes)"]( @@ -2010,20 +2014,17 @@ describe("OffChainAssetReceiptVault", async function () { [] ) + let bobBalanceVaultAft = await vault.connect(alice).balanceOf(bob.address) + let aliceBalanceVaultAft = await vault.connect(alice).balanceOf(alice.address) - // await assertError( - // async () => - // await vault - // .connect(alice) - // ["redeem(uint256,address,address,uint256,bytes)"]( - // balance.add(1), - // alice.address, - // alice.address, - // id, - // [] - // ), - // "ERC20: burn amount exceeds balance", - // "failed to prevent withdraw on more than balance" - // ); + + assert( + bobBalanceVaultAft.eq(bobBalanceVault), + `Wrong shares for bob ${bobBalanceVaultAft} got ${bobBalanceVaultAft}` + ); + assert( + aliceBalanceVaultAft.eq(aliceBalanceVault.sub(balance)), + `Wrong shares for alice ${aliceBalanceVault.sub(balance)} got ${aliceBalanceVaultAft}` + ); }); }); From 3e55d95a4ec3718fc863ce916ccf1679c7989f25 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 16 Feb 2023 13:23:53 +0400 Subject: [PATCH 14/17] Check withdraw for alice --- .../OffChainAssetReceiptVault.test.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index df4bba2f..be0f2d83 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -2027,4 +2027,67 @@ describe("OffChainAssetReceiptVault", async function () { `Wrong shares for alice ${aliceBalanceVault.sub(balance)} got ${aliceBalanceVaultAft}` ); }); + it("Check withdraw for alice", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + + const signers = await ethers.getSigners(); + const alice = signers[0]; + const id = 1; + + //grant depositor role to alice + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const testErc20Contract = (await testErc20.deploy()) as TestErc20; + await testErc20Contract.deployed(); + + const assets = ethers.BigNumber.from(30); + await testErc20Contract.transfer(alice.address, assets); + await testErc20Contract + .connect(alice) + .increaseAllowance(vault.address, assets); + let bla = await vault.connect(alice).balanceOf(alice.address) + console.log(bla) + const shares = ethers.BigNumber.from(10); + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); + + const balance = await receipt.connect(alice).balanceOf(alice.address, id); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + + let aliceSharesBef = await receipt.connect(alice).balanceOf(alice.address, id) + + await vault + .connect(alice) + ["withdraw(uint256,address,address,uint256,bytes)"]( + balance, + alice.address, + alice.address, + id, + [] + ) + + let aliceSharesAft = await receipt.connect(alice).balanceOf(alice.address, id) + let aliceAssetsAft = await vault.connect(alice).balanceOf(alice.address) + + assert( + aliceSharesBef.eq(balance), + `Wrong shares ${balance} got ${aliceSharesBef}` + ); + assert( + aliceAssetsAft.eq(0), + `Wrong assets after withdraw ${0} got ${aliceAssetsAft}` + ); + assert( + aliceSharesAft.eq(0), + `Wrong shares after withdraw ${0} got ${aliceSharesAft}` + ); + }); + }); From f42b4727896f56b95cc83b85bab85725443667d3 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 16 Feb 2023 13:24:25 +0400 Subject: [PATCH 15/17] Refactor --- .../OffChainAssetReceiptVault.test.ts | 91 ++++++++++--------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index be0f2d83..35031877 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -1977,8 +1977,8 @@ describe("OffChainAssetReceiptVault", async function () { //grant depositor role to alice await vault - .connect(alice) - .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const testErc20 = await ethers.getContractFactory("TestErc20"); const testErc20Contract = (await testErc20.deploy()) as TestErc20; @@ -1987,44 +1987,47 @@ describe("OffChainAssetReceiptVault", async function () { const assets = ethers.BigNumber.from(30); await testErc20Contract.transfer(alice.address, assets); await testErc20Contract - .connect(alice) - .increaseAllowance(vault.address, assets); + .connect(alice) + .increaseAllowance(vault.address, assets); const shares = ethers.BigNumber.from(10); await vault - .connect(alice) - ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); const balance = await receipt.connect(alice).balanceOf(alice.address, id); await vault - .connect(alice) - .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); - let bobBalanceVault = await vault.connect(alice).balanceOf(bob.address) - let aliceBalanceVault = await vault.connect(alice).balanceOf(alice.address) + let bobBalanceVault = await vault.connect(alice).balanceOf(bob.address); + let aliceBalanceVault = await vault.connect(alice).balanceOf(alice.address); await vault - .connect(alice) - ["withdraw(uint256,address,address,uint256,bytes)"]( + .connect(alice) + ["withdraw(uint256,address,address,uint256,bytes)"]( balance, bob.address, alice.address, id, [] - ) - - let bobBalanceVaultAft = await vault.connect(alice).balanceOf(bob.address) - let aliceBalanceVaultAft = await vault.connect(alice).balanceOf(alice.address) + ); + let bobBalanceVaultAft = await vault.connect(alice).balanceOf(bob.address); + let aliceBalanceVaultAft = await vault + .connect(alice) + .balanceOf(alice.address); assert( - bobBalanceVaultAft.eq(bobBalanceVault), - `Wrong shares for bob ${bobBalanceVaultAft} got ${bobBalanceVaultAft}` + bobBalanceVaultAft.eq(bobBalanceVault), + `Wrong shares for bob ${bobBalanceVaultAft} got ${bobBalanceVaultAft}` ); assert( - aliceBalanceVaultAft.eq(aliceBalanceVault.sub(balance)), - `Wrong shares for alice ${aliceBalanceVault.sub(balance)} got ${aliceBalanceVaultAft}` + aliceBalanceVaultAft.eq(aliceBalanceVault.sub(balance)), + `Wrong shares for alice ${aliceBalanceVault.sub( + balance + )} got ${aliceBalanceVaultAft}` ); }); it("Check withdraw for alice", async function () { @@ -2036,8 +2039,8 @@ describe("OffChainAssetReceiptVault", async function () { //grant depositor role to alice await vault - .connect(alice) - .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); const testErc20 = await ethers.getContractFactory("TestErc20"); const testErc20Contract = (await testErc20.deploy()) as TestErc20; @@ -2046,48 +2049,50 @@ describe("OffChainAssetReceiptVault", async function () { const assets = ethers.BigNumber.from(30); await testErc20Contract.transfer(alice.address, assets); await testErc20Contract - .connect(alice) - .increaseAllowance(vault.address, assets); - let bla = await vault.connect(alice).balanceOf(alice.address) - console.log(bla) + .connect(alice) + .increaseAllowance(vault.address, assets); + const shares = ethers.BigNumber.from(10); await vault - .connect(alice) - ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); const balance = await receipt.connect(alice).balanceOf(alice.address, id); await vault - .connect(alice) - .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); - let aliceSharesBef = await receipt.connect(alice).balanceOf(alice.address, id) + let aliceSharesBef = await receipt + .connect(alice) + .balanceOf(alice.address, id); await vault - .connect(alice) - ["withdraw(uint256,address,address,uint256,bytes)"]( + .connect(alice) + ["withdraw(uint256,address,address,uint256,bytes)"]( balance, alice.address, alice.address, id, [] - ) + ); - let aliceSharesAft = await receipt.connect(alice).balanceOf(alice.address, id) - let aliceAssetsAft = await vault.connect(alice).balanceOf(alice.address) + let aliceSharesAft = await receipt + .connect(alice) + .balanceOf(alice.address, id); + let aliceAssetsAft = await vault.connect(alice).balanceOf(alice.address); assert( - aliceSharesBef.eq(balance), - `Wrong shares ${balance} got ${aliceSharesBef}` + aliceSharesBef.eq(balance), + `Wrong shares ${balance} got ${aliceSharesBef}` ); assert( - aliceAssetsAft.eq(0), - `Wrong assets after withdraw ${0} got ${aliceAssetsAft}` + aliceAssetsAft.eq(0), + `Wrong assets after withdraw ${0} got ${aliceAssetsAft}` ); assert( - aliceSharesAft.eq(0), - `Wrong shares after withdraw ${0} got ${aliceSharesAft}` + aliceSharesAft.eq(0), + `Wrong shares after withdraw ${0} got ${aliceSharesAft}` ); }); - }); From ed6da09c80250c9b4e25e1510de2681d65cce869 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 16 Feb 2023 16:08:34 +0400 Subject: [PATCH 16/17] Redeem for alice and to other receiver --- .../OffChainAssetReceiptVault.test.ts | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index 35031877..a278f5f0 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -2082,6 +2082,134 @@ describe("OffChainAssetReceiptVault", async function () { .balanceOf(alice.address, id); let aliceAssetsAft = await vault.connect(alice).balanceOf(alice.address); + assert( + aliceSharesBef.eq(balance), + `Wrong shares ${balance} got ${aliceSharesBef}` + ); + assert( + aliceAssetsAft.eq(0), + `Wrong assets after withdraw ${0} got ${aliceAssetsAft}` + ); + assert( + aliceSharesAft.eq(0), + `Wrong shares after withdraw ${0} got ${aliceSharesAft}` + ); + }); + it.only("Redeems on someone else", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + + const signers = await ethers.getSigners(); + const alice = signers[0]; + const bob = signers[1]; + const id = 1; + + //grant depositor role to alice + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const testErc20Contract = (await testErc20.deploy()) as TestErc20; + await testErc20Contract.deployed(); + + const assets = ethers.BigNumber.from(30); + await testErc20Contract.transfer(alice.address, assets); + await testErc20Contract + .connect(alice) + .increaseAllowance(vault.address, assets); + + const shares = ethers.BigNumber.from(10); + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); + + const balance = await receipt.connect(alice).balanceOf(alice.address, id); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + + let bobBalanceVault = await vault.connect(alice).balanceOf(bob.address); + let aliceBalanceVault = await vault.connect(alice).balanceOf(alice.address); + + await vault + .connect(alice) + ["redeem(uint256,address,address,uint256,bytes)"]( + balance, + bob.address, + alice.address, + id, + [] + ); + + let bobBalanceVaultAft = await vault.connect(alice).balanceOf(bob.address); + let aliceBalanceVaultAft = await vault + .connect(alice) + .balanceOf(alice.address); + + assert( + bobBalanceVaultAft.eq(bobBalanceVault), + `Wrong shares for bob ${bobBalanceVaultAft} got ${bobBalanceVaultAft}` + ); + assert( + aliceBalanceVaultAft.eq(aliceBalanceVault.sub(balance)), + `Wrong shares for alice ${aliceBalanceVault.sub( + balance + )} got ${aliceBalanceVaultAft}` + ); + }); + it.only("Check redeem for alice", async function () { + const [vault, receipt] = await deployOffChainAssetReceiptVault(); + + const signers = await ethers.getSigners(); + const alice = signers[0]; + const id = 1; + + //grant depositor role to alice + await vault + .connect(alice) + .grantRole(await vault.connect(alice).DEPOSITOR(), alice.address); + + const testErc20 = await ethers.getContractFactory("TestErc20"); + const testErc20Contract = (await testErc20.deploy()) as TestErc20; + await testErc20Contract.deployed(); + + const assets = ethers.BigNumber.from(30); + await testErc20Contract.transfer(alice.address, assets); + await testErc20Contract + .connect(alice) + .increaseAllowance(vault.address, assets); + + const shares = ethers.BigNumber.from(10); + await vault + .connect(alice) + ["mint(uint256,address,uint256,bytes)"](shares, alice.address, id, []); + + const balance = await receipt.connect(alice).balanceOf(alice.address, id); + + await vault + .connect(alice) + .grantRole(await vault.connect(alice).WITHDRAWER(), alice.address); + + let aliceSharesBef = await receipt + .connect(alice) + .balanceOf(alice.address, id); + + await vault + .connect(alice) + ["redeem(uint256,address,address,uint256,bytes)"]( + balance, + alice.address, + alice.address, + id, + [] + ); + + let aliceSharesAft = await receipt + .connect(alice) + .balanceOf(alice.address, id); + let aliceAssetsAft = await vault.connect(alice).balanceOf(alice.address); + assert( aliceSharesBef.eq(balance), `Wrong shares ${balance} got ${aliceSharesBef}` From 9f63c7bf1b3d29310d87bab3c02babfb58551e86 Mon Sep 17 00:00:00 2001 From: --global <--global> Date: Thu, 16 Feb 2023 16:09:34 +0400 Subject: [PATCH 17/17] Remove only-s, prettier --- test/offchainAsset/OffChainAssetReceiptVault.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/offchainAsset/OffChainAssetReceiptVault.test.ts b/test/offchainAsset/OffChainAssetReceiptVault.test.ts index a278f5f0..80eea4c4 100644 --- a/test/offchainAsset/OffChainAssetReceiptVault.test.ts +++ b/test/offchainAsset/OffChainAssetReceiptVault.test.ts @@ -2095,7 +2095,7 @@ describe("OffChainAssetReceiptVault", async function () { `Wrong shares after withdraw ${0} got ${aliceSharesAft}` ); }); - it.only("Redeems on someone else", async function () { + it("Redeems on someone else", async function () { const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners(); @@ -2158,7 +2158,7 @@ describe("OffChainAssetReceiptVault", async function () { )} got ${aliceBalanceVaultAft}` ); }); - it.only("Check redeem for alice", async function () { + it("Check redeem for alice", async function () { const [vault, receipt] = await deployOffChainAssetReceiptVault(); const signers = await ethers.getSigners();