Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Removed dependency names can no longer be reused. #217

Merged
merged 2 commits into from
Oct 10, 2018
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
8 changes: 7 additions & 1 deletion packages/vouching/contracts/Vouching.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract Vouching is Initializable {
}

mapping (string => Dependency) private _registry;
mapping (string => bool) private _takenDependencyNames;
uint256 private _minimumStake;
ERC20 private _token;

Expand Down Expand Up @@ -63,8 +64,9 @@ contract Vouching is Initializable {
require(initialStake >= _minimumStake, "Initial stake must be equal or greater than minimum stake");
require(owner != address(0), "Owner address cannot be zero");
require(dependencyAddress != address(0), "Dependency address cannot be zero");
require(_registry[name].dependencyAddress == address(0), "Given dependency name is already registered");
require(!_takenDependencyNames[name], "Given dependency name is already registered");

_takenDependencyNames[name] = true;
_registry[name] = Dependency(owner, dependencyAddress, initialStake);

_token.safeTransferFrom(owner, this, initialStake);
Expand Down Expand Up @@ -97,7 +99,11 @@ contract Vouching is Initializable {
function remove(string name) external onlyDependencyOwner(name) {
// Owner surrenders _minimumStake to the system
uint256 reimbursedAmount = _registry[name].stake.sub(_minimumStake);

// The entry is not removed from _takenDependencyNames, to prevent a new dependecy
// from reusing the same name
delete _registry[name];

_token.safeTransfer(msg.sender, reimbursedAmount);
emit DependencyRemoved(keccak256(abi.encodePacked(name)));
}
Expand Down
9 changes: 9 additions & 0 deletions packages/vouching/test/contracts/Vouching.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ contract('Vouching', function ([_, tokenOwner, vouchingOwner, developer, transfe
amount.should.be.bignumber.equal(0);
});

it('reverts when a removed dependency\'s name is reutilized', async function () {
await this.vouching.remove(dependencyName, { from: developer });
await assertRevert(
this.vouching.create(
dependencyName, developer, anotherDependencyAddress, stakeAmount, { from: developer }
)
);
});

it('emits a DependencyRemoved event', async function () {
const result = await this.vouching.remove(dependencyName, { from: developer });
assertEvent.inLogs(result.logs, 'DependencyRemoved', {
Expand Down