From d5146f8c0e2d9ee04aec13378e7f24477eeb1346 Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 9 May 2023 12:10:32 +0200 Subject: [PATCH] Fix the bug in update seller --- .../protocol/facets/SellerHandlerFacet.sol | 6 +++- test/protocol/SellerHandlerTest.js | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/contracts/protocol/facets/SellerHandlerFacet.sol b/contracts/protocol/facets/SellerHandlerFacet.sol index f968202a4..67bfd8d38 100644 --- a/contracts/protocol/facets/SellerHandlerFacet.sol +++ b/contracts/protocol/facets/SellerHandlerFacet.sol @@ -253,8 +253,12 @@ contract SellerHandlerFacet is SellerBase { // Delete pending update admin delete sellerPendingUpdate.admin; + // Delete auth token for seller id if it exists - delete protocolEntities().authTokens[_sellerId]; + if (authToken.tokenType != AuthTokenType.None) { + delete lookups.sellerIdByAuthToken[authToken.tokenType][authToken.tokenId]; + delete protocolEntities().authTokens[_sellerId]; + } updateApplied = true; } else if (role == SellerUpdateFields.Assistant && sellerPendingUpdate.assistant != address(0)) { diff --git a/test/protocol/SellerHandlerTest.js b/test/protocol/SellerHandlerTest.js index 79ccb343e..5fd649f34 100644 --- a/test/protocol/SellerHandlerTest.js +++ b/test/protocol/SellerHandlerTest.js @@ -2485,6 +2485,35 @@ describe("SellerHandler", function () { ); }); + it("Auth token can be used again if it was previously removed", async function () { + // Update a seller to use auth token + seller.admin = ethers.constants.AddressZero; + await accountHandler.connect(admin).updateSeller(seller, authToken); + await accountHandler.connect(authTokenOwner).optInToSellerUpdate(seller.id, [SellerUpdateFields.AuthToken]); + + // Update seller to not use auth token anymore + seller.admin = other1.address; + await accountHandler.connect(admin).updateSeller(seller, emptyAuthToken); + await accountHandler.connect(other1).optInToSellerUpdate(seller.id, [SellerUpdateFields.Admin]); + + // Update back to auth token + seller.admin = ethers.constants.AddressZero; + sellerStruct = seller.toStruct(); + await accountHandler.connect(other1).updateSeller(seller, authToken); + await expect( + accountHandler.connect(authTokenOwner).optInToSellerUpdate(seller.id, [SellerUpdateFields.AuthToken]) + ) + .to.emit(accountHandler, "SellerUpdateApplied") + .withArgs( + seller.id, + sellerStruct, + pendingSellerUpdateStruct, + authTokenStruct, + emptyAuthTokenStruct, + authTokenOwner.address + ); + }); + it("If updateSeller is called twice with no optIn in between, pendingSellerUpdate is populated with the data from second call", async function () { seller.assistant = other1.address;