Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jul 11, 2024
1 parent 206a827 commit 6758687
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 70 deletions.
8 changes: 3 additions & 5 deletions src/DelegationWall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pragma solidity ^0.8.17;
contract DelegationWall {
struct Candidate {
bytes contentUrl;
bytes socialUrl;
}

/// @dev Stores the data registered by the delegate candidates
Expand All @@ -17,22 +16,21 @@ contract DelegationWall {
address[] public candidateAddresses;

/// @notice Emitted when a wallet registers as a candidate
event CandidateRegistered(address indexed candidate, bytes contentUrl, bytes socialUrl);
event CandidateRegistered(address indexed candidate, bytes contentUrl);

/// @notice Raised when a delegate registers with an empty contentUrl
error EmptyContent();

function register(bytes memory _contentUrl, bytes memory _socialUrl) public {
function register(bytes memory _contentUrl) public {
if (_contentUrl.length == 0) revert EmptyContent();

if (candidates[msg.sender].contentUrl.length == 0) {
candidateAddresses.push(msg.sender);
}

candidates[msg.sender].contentUrl = _contentUrl;
candidates[msg.sender].socialUrl = _socialUrl;

emit CandidateRegistered(msg.sender, _contentUrl, _socialUrl);
emit CandidateRegistered(msg.sender, _contentUrl);
}

function candidateCount() public view returns (uint256) {
Expand Down
118 changes: 53 additions & 65 deletions test/DelegationWall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract EmergencyMultisigTest is AragonTest {
DelegationWall wall;

/// @notice Emitted when a wallet registers as a candidate
event CandidateRegistered(address indexed candidate, bytes contentUrl, bytes socialUrl);
event CandidateRegistered(address indexed candidate, bytes contentUrl);

/// @notice Raised when a delegate registers with an empty contentUrl
error EmptyContent();
Expand All @@ -19,128 +19,116 @@ contract EmergencyMultisigTest is AragonTest {
}

function test_ShouldRegisterACandidate() public {
wall.register("ipfs://1234", "");
wall.register("ipfs://1234");

vm.startPrank(alice);
wall.register("ipfs://abcdef", "");
wall.register("ipfs://abcdef");

vm.startPrank(bob);
wall.register("ipfs://xyz", " ");
wall.register("ipfs://xyz");

vm.startPrank(carol);
wall.register("ipfs://____", "https://taiko.xyz/");
wall.register("ipfs://____");

vm.startPrank(david);
wall.register("ipfs://1234000", "https://aragon.org/");
wall.register("ipfs://1234000");
}

function test_ShouldRevertIfEmptyContent() public {
vm.startPrank(alice);

vm.expectRevert(abi.encodeWithSelector(EmptyContent.selector));
wall.register("", "");
vm.expectRevert(abi.encodeWithSelector(EmptyContent.selector));
wall.register("", "https://taiko.xyz/");
wall.register("");

// Not revert
wall.register(" ", "https://taiko.xyz/");
wall.register(" ");

vm.startPrank(bob);

vm.expectRevert(abi.encodeWithSelector(EmptyContent.selector));
wall.register("", "");
vm.expectRevert(abi.encodeWithSelector(EmptyContent.selector));
wall.register("", "https://taiko.xyz/");
wall.register("");

// Not revert
wall.register(" ", "https://taiko.xyz/");
wall.register(" ");
}

function test_ShouldStoreCandidateDetails() public {
// Alice
vm.startPrank(alice);
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");

(bytes memory contentUrl, bytes memory url) = wall.candidates(alice);
bytes memory contentUrl = wall.candidates(alice);
assertEq(contentUrl, "ipfs://alice", "Incorrect delegate contentUrl");
assertEq(url, "https://", "Incorrect social URL");

// Bob
vm.startPrank(bob);

wall.register("ipfs://bob", "https://taiko.xyz");
(contentUrl, url) = wall.candidates(bob);
wall.register("ipfs://bob");
(contentUrl) = wall.candidates(bob);
assertEq(contentUrl, "ipfs://bob", "Incorrect delegate contentUrl");
assertEq(url, "https://taiko.xyz", "Incorrect social URL");

// Carol
vm.startPrank(carol);

wall.register("ipfs://carol", "https://x.com/carol");
(contentUrl, url) = wall.candidates(carol);
wall.register("ipfs://carol");
(contentUrl) = wall.candidates(carol);
assertEq(contentUrl, "ipfs://carol", "Incorrect delegate contentUrl");
assertEq(url, "https://x.com/carol", "Incorrect social URL");

// David
vm.startPrank(david);

wall.register("ipfs://david", "https://defeat-goliath.org");
(contentUrl, url) = wall.candidates(david);
wall.register("ipfs://david");
(contentUrl) = wall.candidates(david);
assertEq(contentUrl, "ipfs://david", "Incorrect delegate contentUrl");
assertEq(url, "https://defeat-goliath.org", "Incorrect social URL");
}

function test_ShouldUpdateCandidateDetails() public {
// Alice
vm.startPrank(alice);
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");

(bytes memory contentUrl, bytes memory url) = wall.candidates(alice);
bytes memory contentUrl = wall.candidates(alice);
assertEq(contentUrl, "ipfs://alice", "Incorrect delegate contentUrl");
assertEq(url, "https://", "Incorrect social URL");

// update
wall.register("ipfs://alice-2", "https://alice-for-president.org");
(contentUrl, url) = wall.candidates(alice);
wall.register("ipfs://alice-2");
(contentUrl) = wall.candidates(alice);
assertEq(contentUrl, "ipfs://alice-2", "Incorrect delegate contentUrl");
assertEq(url, "https://alice-for-president.org", "Incorrect social URL");

// Bob
vm.startPrank(bob);

wall.register("ipfs://bob", "https://taiko.xyz");
(contentUrl, url) = wall.candidates(bob);
wall.register("ipfs://bob");
(contentUrl) = wall.candidates(bob);
assertEq(contentUrl, "ipfs://bob", "Incorrect delegate contentUrl");
assertEq(url, "https://taiko.xyz", "Incorrect social URL");

// update
wall.register("ipfs://bob-2", "https://bob-president.org");
(contentUrl, url) = wall.candidates(bob);
wall.register("ipfs://bob-2");
(contentUrl) = wall.candidates(bob);
assertEq(contentUrl, "ipfs://bob-2", "Incorrect delegate contentUrl");
assertEq(url, "https://bob-president.org", "Incorrect social URL");
}

function test_ShouldCountRegisteredCandidates() public {
assertEq(wall.candidateCount(), 0, "Incorrect candidate count");

// Alice
vm.startPrank(alice);
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");
assertEq(wall.candidateCount(), 1, "Incorrect candidate count");

// Bob
vm.startPrank(bob);
wall.register("ipfs://bob", "https://taiko.xyz");
wall.register("ipfs://bob");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");

// Carol
vm.startPrank(carol);
wall.register("ipfs://carol", "https://x.com/carol");
wall.register("ipfs://carol");
assertEq(wall.candidateCount(), 3, "Incorrect candidate count");

// David
vm.startPrank(david);
wall.register("ipfs://david", "https://defeat-goliath.org");
wall.register("ipfs://david");
assertEq(wall.candidateCount(), 4, "Incorrect candidate count");
}

Expand All @@ -149,29 +137,29 @@ contract EmergencyMultisigTest is AragonTest {

// Alice
vm.startPrank(alice);
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");
assertEq(wall.candidateCount(), 1, "Incorrect candidate count");
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");
assertEq(wall.candidateCount(), 1, "Incorrect candidate count");
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");
assertEq(wall.candidateCount(), 1, "Incorrect candidate count");
wall.register("Alice", "https://alice-for-president.org");
wall.register("Alice");
assertEq(wall.candidateCount(), 1, "Incorrect candidate count");
wall.register("Vote Alice", "https://alice.land");
wall.register("Vote Alice");

// Bob
vm.startPrank(bob);
wall.register("ipfs://bob", "https://taiko.xyz");
wall.register("ipfs://bob");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");
wall.register("ipfs://bob-1", "https://taiko.xyz");
wall.register("ipfs://bob-1");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");
wall.register("ipfs://bob-2", "https://taiko.xyz");
wall.register("ipfs://bob-2");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");
wall.register("ipfs://bob-3", "https://taiko.xyz");
wall.register("ipfs://bob-3");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");
wall.register("ipfs://bob-4", "https://bob.xyz");
wall.register("ipfs://bob-4");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");
wall.register("ipfs://bob-5", "https://bob.robot");
wall.register("ipfs://bob-5");
assertEq(wall.candidateCount(), 2, "Incorrect candidate count");
}

Expand All @@ -187,7 +175,7 @@ contract EmergencyMultisigTest is AragonTest {

// Alice
vm.startPrank(alice);
wall.register("ipfs://alice", "https://");
wall.register("ipfs://alice");

assertEq(wall.candidateAddresses(0), alice, "Incorrect candidate address");
vm.expectRevert();
Expand All @@ -199,7 +187,7 @@ contract EmergencyMultisigTest is AragonTest {

// Bob
vm.startPrank(bob);
wall.register("ipfs://bob", "https://taiko.xyz");
wall.register("ipfs://bob");

assertEq(wall.candidateAddresses(0), alice, "Incorrect candidate address");
assertEq(wall.candidateAddresses(1), bob, "Incorrect candidate address");
Expand All @@ -210,7 +198,7 @@ contract EmergencyMultisigTest is AragonTest {

// Carol
vm.startPrank(carol);
wall.register("ipfs://carol", "https://x.com/carol");
wall.register("ipfs://carol");

assertEq(wall.candidateAddresses(0), alice, "Incorrect candidate address");
assertEq(wall.candidateAddresses(1), bob, "Incorrect candidate address");
Expand All @@ -220,7 +208,7 @@ contract EmergencyMultisigTest is AragonTest {

// David
vm.startPrank(david);
wall.register("ipfs://david", "https://defeat-goliath.org");
wall.register("ipfs://david");

assertEq(wall.candidateAddresses(0), alice, "Incorrect candidate address");
assertEq(wall.candidateAddresses(1), bob, "Incorrect candidate address");
Expand All @@ -232,25 +220,25 @@ contract EmergencyMultisigTest is AragonTest {
// Alice
vm.startPrank(alice);
vm.expectEmit();
emit CandidateRegistered(alice, "ipfs://alice", "https://");
wall.register("ipfs://alice", "https://");
emit CandidateRegistered(alice, "ipfs://alice");
wall.register("ipfs://alice");

// Bob
vm.startPrank(bob);
vm.expectEmit();
emit CandidateRegistered(bob, "ipfs://bob", "https://taiko.xyz");
wall.register("ipfs://bob", "https://taiko.xyz");
emit CandidateRegistered(bob, "ipfs://bob");
wall.register("ipfs://bob");

// Carol
vm.startPrank(carol);
vm.expectEmit();
emit CandidateRegistered(carol, "ipfs://carol", "https://x.com/carol");
wall.register("ipfs://carol", "https://x.com/carol");
emit CandidateRegistered(carol, "ipfs://carol");
wall.register("ipfs://carol");

// David
vm.startPrank(david);
vm.expectEmit();
emit CandidateRegistered(david, "ipfs://david", "https://defeat-goliath.org");
wall.register("ipfs://david", "https://defeat-goliath.org");
emit CandidateRegistered(david, "ipfs://david");
wall.register("ipfs://david");
}
}

0 comments on commit 6758687

Please sign in to comment.