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;