Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug in update seller #624

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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