Skip to content

Commit

Permalink
Add a solution for the New Exercise (#33)
Browse files Browse the repository at this point in the history
Closes #29
  • Loading branch information
vince-grondin authored Dec 9, 2023
1 parent fd13ef7 commit abf4db4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/AddressBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,18 @@ contract AddressBook is Ownable {
* @notice Factory to dynamically deploy instances of the `AddressBook` contract.
*/
contract AddressBookFactory {
event AddressBookDeployed(address newAddressBookAddress);

/**
* @notice Creates an instance of `AddressBook` and assigns the caller as the owner of that instance.
* @return The address of the newly deployed `AddressBook` contract.
*/
function deploy() external returns (address) {
return address(new AddressBook(msg.sender));
AddressBook addressBook = new AddressBook(msg.sender);
address addressBookAddress = address(addressBook);

emit AddressBookDeployed(addressBookAddress);

return addressBookAddress;
}
}
2 changes: 1 addition & 1 deletion test/AddressBook.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract AddressBookTest is Test {

function setUp() public {
vm.startPrank(userA);
addressBook = new AddressBook();
addressBook = new AddressBook(userA);
}

/**
Expand Down

0 comments on commit abf4db4

Please sign in to comment.