-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
13 changed files
with
170 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Submodule solady
added at
ec85d4
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Script, console2} from "forge-std/Script.sol"; | ||
import {UsernameRegistry} from "../src/contracts/UsernameRegistry.sol"; | ||
|
||
contract UsernameRegistryScript is Script { | ||
function setUp() public {} | ||
|
||
function run() public { | ||
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
UsernameRegistry unreg = new UsernameRegistry(msg.sender); | ||
console2.log("UsernameRegistry deployed at address", address(unreg)); | ||
vm.stopBroadcast(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.20; | ||
|
||
import "solady/auth/Ownable.sol"; | ||
import "../interfaces/IUsernameRegistry.sol"; | ||
|
||
contract UsernameRegistry is Ownable, IUsernameRegistry { | ||
mapping(address => string) public addressToUsername; | ||
mapping(string => address) public usernameToAddress; | ||
|
||
constructor(address _owner) { | ||
_setOwner(_owner); | ||
} | ||
|
||
// External functions | ||
|
||
function registerUserData( | ||
address _scw, | ||
string memory _un | ||
) external onlyOwner { | ||
_setSCW(_scw, _un); | ||
_setUsername(_scw, _un); | ||
emit UserRegistered(_scw, _un); | ||
} | ||
|
||
function getUsernameForWallet( | ||
address _scw | ||
) external view returns (string memory un) { | ||
return addressToUsername[_scw]; | ||
} | ||
|
||
function getWalletForUsername( | ||
string memory _un | ||
) external view returns (address scw) { | ||
return usernameToAddress[_un]; | ||
} | ||
|
||
// Internal functions | ||
|
||
function _setSCW(address _scw, string memory _un) internal { | ||
usernameToAddress[_un] = _scw; | ||
} | ||
function _setUsername(address _scw, string memory _un) internal { | ||
addressToUsername[_scw] = _un; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.20; | ||
|
||
interface IUsernameRegistry { | ||
event UserRegistered(address indexed scw, string un); | ||
|
||
function registerUserData(address _scw, string memory _un) external; | ||
|
||
function getUsernameForWallet( | ||
address _scw | ||
) external view returns (string memory un); | ||
|
||
function getWalletForUsername( | ||
string memory _un | ||
) external view returns (address scw); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.20; | ||
|
||
import "forge-std/Test.sol"; | ||
import {UsernameRegistry} from "../src/contracts/UsernameRegistry.sol"; | ||
|
||
contract UsernameRegistryTest is Test { | ||
UsernameRegistry registry; | ||
Account internal owner; | ||
Account internal user; | ||
|
||
event UserRegistered(address indexed scw, string un); | ||
|
||
function setUp() public { | ||
owner = makeAccount("owner"); | ||
user = makeAccount("user"); | ||
registry = new UsernameRegistry(owner.addr); | ||
} | ||
|
||
function test_registerUserData() public { | ||
string memory username = "john"; | ||
vm.prank(owner.addr); | ||
|
||
registry.registerUserData(user.addr, username); | ||
|
||
assertEq(registry.getUsernameForWallet(user.addr), username); | ||
assertEq(registry.getWalletForUsername(username), user.addr); | ||
} | ||
|
||
function test_revertOnlyOwnerCanRegister() public { | ||
string memory username = "john"; | ||
vm.prank(user.addr); | ||
vm.expectRevert(); | ||
registry.registerUserData(user.addr, username); | ||
} | ||
|
||
// Test getUsernameForWallet | ||
function test_getUsernameForWallet() public { | ||
string memory username = "john"; | ||
vm.prank(owner.addr); | ||
|
||
registry.registerUserData(user.addr, username); | ||
|
||
string memory result = registry.getUsernameForWallet(user.addr); | ||
assertEq(result, username); | ||
} | ||
|
||
// Test getWalletForUsername | ||
function test_getWalletForUsername() public { | ||
string memory username = "john"; | ||
vm.prank(owner.addr); | ||
|
||
registry.registerUserData(user.addr, username); | ||
|
||
address result = registry.getWalletForUsername(username); | ||
assertEq(result, user.addr); | ||
} | ||
|
||
// Test UserRegistered event | ||
function test_emitUserRegisteredEvent() public { | ||
string memory username = "john"; | ||
vm.expectEmit(true, true, false, true); | ||
emit UserRegistered(user.addr, username); | ||
vm.prank(owner.addr); | ||
|
||
registry.registerUserData(user.addr, username); | ||
} | ||
} |