Skip to content

Commit

Permalink
Revert when deregistration fails
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Sep 13, 2022
1 parent ddba08c commit f7fcc6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions contracts/modules/RegistryController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,16 @@ contract RegistryController is
internal
onlyInstanceOperator
{
bool removed = EnumerableSet.remove(_contractNames[_release], _contractName);

if (removed) {
_contractsInRelease[_release] -= 1;
delete _contracts[_release][_contractName];
require(
_contractsInRelease[_release] == EnumerableSet.length(_contractNames[_release]),
"ERROR:REC-010:CONTRACT_NUMBER_MISMATCH");
emit LogContractDeregistered(_release, _contractName);
}
require(EnumerableSet.contains(_contractNames[_release], _contractName), "ERROR:REC-009:CONTRACT_UNKNOWN");

EnumerableSet.remove(_contractNames[_release], _contractName);

_contractsInRelease[_release] -= 1;
delete _contracts[_release][_contractName];

require(
_contractsInRelease[_release] == EnumerableSet.length(_contractNames[_release]),
"ERROR:REC-010:CONTRACT_NUMBER_MISMATCH");
emit LogContractDeregistered(_release, _contractName);
}
}
3 changes: 2 additions & 1 deletion tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def test_registry_deregister(registry, owner):
assert tx1 == registry.getContract(name1)
assert tx2 == registry.getContract(name2)

tx = registry.deregister(name3, {'from': owner})
with brownie.reverts("ERROR:REC-009:CONTRACT_UNKNOWN"):
tx = registry.deregister(name3, {'from': owner})

assert tx1 == registry.getContract(name1)
assert tx2 == registry.getContract(name2)
Expand Down

0 comments on commit f7fcc6c

Please sign in to comment.