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: allow transfers to team 0 (individual) #30

Merged
merged 1 commit into from
Nov 17, 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
2 changes: 1 addition & 1 deletion src/TeamRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ contract TeamRegistry {
if (team.isLeader) revert IsTeamLeader(team.id);

// Revert if `msg.sender` is not approved to join the team.
if (!getApproved[_to][msg.sender]) revert Unauthorized();
if (_to > 0 && !getApproved[_to][msg.sender]) revert Unauthorized();

// Transfer team.
getTeam[msg.sender].id = uint248(_to);
Expand Down
31 changes: 29 additions & 2 deletions test/TeamRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,22 @@ contract TeamRegistyTest is Test {
tr.transferTeam(1);
}

/// @notice Test events emitted and state updates upon transferring teams.
/// @notice Test that transferring teams to 0 (individual) succeeds.
function test_transferFrom_ToZero_Succeeds() public {
_createTeam();

// Repeatedly transfer `makeAddr("sudolabel")` between team 1 and 0
// (individual).
vm.startPrank(makeAddr("sudolabel"));
tr.transferTeam(1);
tr.transferTeam(0);
tr.transferTeam(1);
tr.transferTeam(0);
vm.stopPrank();
}

/// @notice Test events emitted and state updates upon transferring teams,
/// then transferring to `0` (individual).
function test_transferTeam() public {
_createTeam();

Expand All @@ -432,7 +447,7 @@ contract TeamRegistyTest is Test {
assertEq(teamId, 0);
}

// Transfer team 1 to `makeAddr("sudolabel")`.
// Transfer `makeAddr("sudolabel")` to team 1.
vm.expectEmit(true, true, true, true);
emit TransferTeam(0, 1, makeAddr("sudolabel"));
vm.prank(makeAddr("sudolabel"));
Expand All @@ -443,6 +458,18 @@ contract TeamRegistyTest is Test {
(uint248 teamId,) = tr.getTeam(makeAddr("sudolabel"));
assertEq(teamId, 1);
}

// Transfer `makeAddr("sudolabel")` to individual.
vm.expectEmit(true, true, true, true);
emit TransferTeam(1, 0, makeAddr("sudolabel"));
vm.prank(makeAddr("sudolabel"));
tr.transferTeam(0);

// Test that `makeAddr("sudolabel")` is now marked as individual.
{
(uint248 teamId,) = tr.getTeam(makeAddr("sudolabel"));
assertEq(teamId, 0);
}
}

// -------------------------------------------------------------------------
Expand Down
Loading