Skip to content

Commit

Permalink
Fix the bug in update seller
Browse files Browse the repository at this point in the history
  • Loading branch information
zajck committed May 9, 2023
1 parent d65bed2 commit d5146f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion contracts/protocol/facets/SellerHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
29 changes: 29 additions & 0 deletions test/protocol/SellerHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d5146f8

Please sign in to comment.