Skip to content
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
1 change: 1 addition & 0 deletions contracts/protocol/domain/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface EntityErrors {
uint256 sellerId,
uint256 associatedEntityId
);
error NoEntitiesModified(FermionTypes.AssociatedRole associatedRole, uint256 sellerId);
error AccountAlreadyExists(address account);
error NewAccountSameAsOld();
}
Expand Down
15 changes: 13 additions & 2 deletions contracts/protocol/facets/Entity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ contract EntityFacet is Context, EntityErrors, Access, IEntityEvents {
) = getAssociatedLookups(_sellerId, _associatedRole, pl);

mapping(uint256 => FermionTypes.EntityData) storage entityData = FermionStorage.protocolEntities().entityData;
bool found;
for (uint256 i; i < _associatedEntitiesIds.length; ++i) {
uint256 associatedEntityId = _associatedEntitiesIds[i];
if (_add) {
Expand All @@ -740,15 +741,25 @@ contract EntityFacet is Context, EntityErrors, Access, IEntityEvents {
if (j != facilitatorsLength - 1)
associatedEntities[j] = associatedEntities[facilitatorsLength - 1];
associatedEntities.pop();

emit AssociatedEntityRemoved(_associatedRole, _sellerId, associatedEntityId);
found = true;
// stack too deep workaround
_emitAssociatedEntityRemoved(_associatedRole, _sellerId, associatedEntityId);
break;
}
}
}

isAssociatedRole[associatedEntityId] = _add;
}
if (!_add && !found) revert NoEntitiesModified(_associatedRole, _sellerId);
}

function _emitAssociatedEntityRemoved(
FermionTypes.AssociatedRole _associatedRole,
uint256 _sellerId,
uint256 _associatedEntityId
) private {
emit AssociatedEntityRemoved(_associatedRole, _sellerId, _associatedEntityId);
}

/** Returns the storage pointers to associated entities and the mapping of the associated role.
Expand Down
14 changes: 6 additions & 8 deletions test/protocol/entityFacet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,9 @@ describe("Entity", function () {
});

it("Removing a facilitator that was not added", async function () {
await expect(entityFacet.removeFacilitators(sellerId, [6])).to.not.emit(
entityFacet,
"AssociatedEntityRemoved",
);
await expect(entityFacet.removeFacilitators(sellerId, [6]))
.to.be.revertedWithCustomError(fermionErrors, "NoEntitiesModified")
.withArgs(AssociatedRole.Facilitator, sellerId);

// verify state
expect(await entityFacet.getSellersFacilitators(sellerId)).to.eql([
Expand Down Expand Up @@ -1384,10 +1383,9 @@ describe("Entity", function () {
});

it("Removing a royaltyRecipient that was not added", async function () {
await expect(entityFacet.removeRoyaltyRecipients(sellerId, [6])).to.not.emit(
entityFacet,
"AssociatedEntityRemoved",
);
await expect(entityFacet.removeRoyaltyRecipients(sellerId, [6]))
.to.be.revertedWithCustomError(fermionErrors, "NoEntitiesModified")
.withArgs(AssociatedRole.RoyaltyRecipient, sellerId);

// verify state
expect(await entityFacet.getSellersRoyaltyRecipients(sellerId)).to.eql([
Expand Down