From 0f49e28caa46142fd1a15649b6d39754ac16345f Mon Sep 17 00:00:00 2001 From: Alberto Granzotto Date: Wed, 1 Nov 2023 15:25:08 +0100 Subject: [PATCH 1/4] Add failing test --- test/InternalMarket.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/InternalMarket.ts b/test/InternalMarket.ts index 2e9f669..eba394d 100644 --- a/test/InternalMarket.ts +++ b/test/InternalMarket.ts @@ -202,6 +202,13 @@ describe("InternalMarket", async () => { ); }); + it("should revert when called by a non-contributor", async () => { + registry.isAtLeast.returns(false); + await expect(internalMarket.makeOffer(1000)).revertedWith( + "InternalMarket: only Contributors can make offers" + ); + }); + describe("redeem", async () => { describe("with some unlocked tokens", async () => { beforeEach(async () => { From a7e30e7aae0c462136f506c1760d925054110bd8 Mon Sep 17 00:00:00 2001 From: Alberto Granzotto Date: Wed, 1 Nov 2023 16:03:35 +0100 Subject: [PATCH 2/4] Add check for make offer --- contracts/InternalMarket/InternalMarket.sol | 7 +++++++ test/RedemptionController.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/contracts/InternalMarket/InternalMarket.sol b/contracts/InternalMarket/InternalMarket.sol index 9a5bb9e..eeb3b6e 100644 --- a/contracts/InternalMarket/InternalMarket.sol +++ b/contracts/InternalMarket/InternalMarket.sol @@ -50,6 +50,13 @@ contract InternalMarket is Initializable, HasRole, InternalMarketBase { * @param amount The amount of tokens to offer for sale. */ function makeOffer(uint256 amount) public virtual { + require( + _shareholderRegistry.isAtLeast( + _shareholderRegistry.CONTRIBUTOR_STATUS(), + msg.sender + ), + "InternalMarket: only Contributors can make offers" + ); _makeOffer(_msgSender(), amount); } diff --git a/test/RedemptionController.ts b/test/RedemptionController.ts index 6957209..0a1d47c 100644 --- a/test/RedemptionController.ts +++ b/test/RedemptionController.ts @@ -202,7 +202,7 @@ describe("RedemptionController", () => { ); }); - describe.only("when 10 tokens are redeemable", async () => { + describe("when 10 tokens are redeemable", async () => { beforeEach(async () => { await redemptionController.afterMint(account.address, 10); await redemptionController.afterOffer(account.address, 10); From 62378f01600280de6813f6c26574a5de096de87b Mon Sep 17 00:00:00 2001 From: Alberto Granzotto Date: Wed, 1 Nov 2023 16:24:16 +0100 Subject: [PATCH 3/4] Fix case --- contracts/InternalMarket/InternalMarket.sol | 2 +- test/InternalMarket.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/InternalMarket/InternalMarket.sol b/contracts/InternalMarket/InternalMarket.sol index eeb3b6e..8ecff95 100644 --- a/contracts/InternalMarket/InternalMarket.sol +++ b/contracts/InternalMarket/InternalMarket.sol @@ -55,7 +55,7 @@ contract InternalMarket is Initializable, HasRole, InternalMarketBase { _shareholderRegistry.CONTRIBUTOR_STATUS(), msg.sender ), - "InternalMarket: only Contributors can make offers" + "InternalMarket: only contributors can make offers" ); _makeOffer(_msgSender(), amount); } diff --git a/test/InternalMarket.ts b/test/InternalMarket.ts index eba394d..16e6b37 100644 --- a/test/InternalMarket.ts +++ b/test/InternalMarket.ts @@ -205,7 +205,7 @@ describe("InternalMarket", async () => { it("should revert when called by a non-contributor", async () => { registry.isAtLeast.returns(false); await expect(internalMarket.makeOffer(1000)).revertedWith( - "InternalMarket: only Contributors can make offers" + "InternalMarket: only contributors can make offers" ); }); From 2bc976d3725b0047b70d7627af41a02f8e76a227 Mon Sep 17 00:00:00 2001 From: Alberto Granzotto Date: Fri, 3 Nov 2023 15:36:02 +0100 Subject: [PATCH 4/4] Add integration test --- test/Integration.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Integration.ts b/test/Integration.ts index 2960394..e50b1f2 100644 --- a/test/Integration.ts +++ b/test/Integration.ts @@ -679,6 +679,11 @@ describe("Integration", async () => { "Resolution: account cannot vote" ); + // user3 cannot offer tokens + await expect(internalMarket.connect(user3).makeOffer(10)).revertedWith( + "InternalMarket: only contributors can make offers" + ); + // ... and finally the world is saved. expect(await resolutionManager.getResolutionResult(resolutionId)).to.be .true;