diff --git a/lib/forge-std b/lib/forge-std index 9825609..d0d6fdf 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 98256095f37d83653ba1617d06ccd9604cbd7c6d +Subproject commit d0d6fdf911d332c691c49a7ce5485b8ace61020c diff --git a/src/Repository.huff b/src/Repository.huff index c8284ae..90ee87d 100644 --- a/src/Repository.huff +++ b/src/Repository.huff @@ -7,14 +7,31 @@ #define function owner(uint256) view returns (address) #define function updater(uint256) view returns(address) -#define function addDpd(uint256, address, address, bytes32) nonpayable returns(uint256) -#define function updateDpdData(uint256, bytes32) nonpayable returns() -#define function updateDpdOwner(uint256, address) nonpayable returns() -#define function updateDpdUpdater(uint256, address) nonpayable returns() - -#define event DPDAdded(uint256 indexed, address, address, bytes32) -#define event DPDUpdated(uint256,bytes32) +/// @notice Given a DPD id, CID, owner address, and updater address, initialize a new DPD. +#define function addDpd(uint256,bytes32,address,address) nonpayable returns () + +/// @notice Given a DPD id, return its CID. +#define function dpds(uint256) view returns (bytes32) +/// @notice Given a DPD id, return its owner address. +#define function owners(uint256) view returns (address) +/// @notice Given a DPD id, return its updater address. +#define function updaters(uint256) view returns (address) + +/// @notice Update a DPD CID. +/// @notice Can only be called by the DPD's Updater address. +#define function updateDpdData(uint256, bytes32) nonpayable returns () +/// @notice Set a new DPD owner. +#define function updateDpdOwner(uint256, address) nonpayable returns () +/// @notice Set a new DPD updater. +#define function updateDpdUpdater(uint256, address) nonpayable returns () + +/// @notice Event emitted when a new DPD is added to the repository. +#define event DPDAdded(uint256, address, address,bytes32) +/// @notice Event emitted when a DPD is updated. +#define event DPDUpdated(uint256,uint256,bytes32) +/// @notice Event emitted when a DPD's owner is changed. #define event DPDOwnerChanged(uint256,address) +/// @notice Event emitted when a DPD's upgrader is changed. #define event DPDUpdaterChanged(uint256,address) /* Event Signatures */ @@ -156,13 +173,13 @@ [DPD_UPDATER_MAP_SLOT] // [salt, dpd_id, dpd_id, data] LOAD_ELEMENT_FROM_KEYS(0x00) // [updater, dpd_id, data] caller // [msg.sender, updater, dpd_id, data] - eq iszero // [msg.sender!=updater, dpd_id, data] + eq // [msg.sender==updater, dpd_id, data] dup2 // [dpd_id, msg.sender!=updater, dpd_id, data] [DPD_OWNER_MAP_SLOT] // [salt, dpd_id, msg.sender!=updater, dpd_id, data] LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, msg.sender!=updater, dpd_id, data] caller // [msg.sender, owner, msg.sender!=updater, dpd_id, data] - eq iszero // [msg.sender!=owner, msg.sender!=updater, dpd_id, data] - or // [msg.sender!=owner || msg.sender!=updater, dpd_id, data] + eq // [msg.sender==owner, msg.sender==updater, dpd_id, data] + or iszero // [!(msg.sender==owner || msg.sender==updater), dpd_id, data] error jumpi // [dpd_id, data] // Store new data. @@ -193,12 +210,12 @@ // Ensure that the sender is the DPD owner. - dup1 // [dpd_id, dpd_id, updater] - [DPD_OWNER_MAP_SLOT] // [salt, dpd_id, dpd_id, updater] - LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, dpd_id, updater] - caller // [msg.sender, owner, dpd_id, updater] - eq iszero // [msg.sender != owner, dpd_id, updater] - error jumpi // [dpd_id, updater] + dup1 // [dpd_id, dpd_id, updater] + [DPD_OWNER_MAP_SLOT] // [salt, dpd_id, dpd_id, updater] + LOAD_ELEMENT_FROM_KEYS(0x00) // [owner, dpd_id, updater] + caller // [msg.sender, owner, dpd_id, updater] + eq iszero // [msg.sender != owner, dpd_id, updater] + error jumpi // [dpd_id, updater] // Store new data. [DPD_UPDATER_MAP_SLOT] // [salt, dpd_id, updater] diff --git a/test/Benchmark.t.sol b/test/Benchmark.t.sol index ebb72dc..6643b7f 100644 --- a/test/Benchmark.t.sol +++ b/test/Benchmark.t.sol @@ -5,7 +5,7 @@ import "forge-std/Test.sol"; import "forge-std/console.sol"; import "./benchmarks/DPDRepository.sol"; -contract BenchmarkedTest is Test { +contract BenchmarkTest is Test { /// @dev Address of the Huff DPDRepository contract. Repository public repository; @@ -136,8 +136,8 @@ interface Repository { /// @notice Event emitted when a new DPD is added to the repository. event DPDAdded(uint256 indexed id, address owner, address updater, bytes32 cid); - /// @notice Event emitted when a new DPD is added to the repository. - event DPDUpdated(uint256 indexed id, bytes32 cid); + /// @notice Event emitted when a DPD is updated. + event DPDUpdated(uint256 indexed dpdId, bytes32 cid); /// @notice Event emitted when a DPD's owner is changed. event DPDOwnerUpdated(uint256 indexed id, address newOwner); diff --git a/test/Repository.t.sol b/test/Repository.t.sol index 6e1e31a..ffe63dc 100644 --- a/test/Repository.t.sol +++ b/test/Repository.t.sol @@ -5,7 +5,7 @@ import "foundry-huff/HuffDeployer.sol"; import "forge-std/Test.sol"; contract RepositoryTest is Test { - /// @dev Address of the SimpleStore contract. + /// @dev Address of the Repository contract. Repository public repository; /// @notice Event emitted when a new DPD is added to the repository. @@ -90,14 +90,25 @@ contract RepositoryTest is Test { repository.addDpd(0, address(this), address(this), bytes32(uint256(69))); } - /// @dev Ensure that you can update DPD data. - function testUpdateData() public { - vm.expectEmit(true, true, true, true); - emit DPDAdded(0, address(this), address(this), bytes32(uint256(69))); - repository.addDpd(0, address(this), address(this), bytes32(uint256(69))); + /// @dev Ensure that you can update DPD data as owner. + function testUpdateDataAsOwner() public { + repository.addDpd(0, address(this), address(0xBEEF), bytes32(uint256(69))); + repository.updateDpdData(0, bytes32(uint256(1000))); - vm.expectEmit(true, true, true, true); - emit DPDUpdated(0, bytes32(uint256(1000))); + assertEq(uint256(repository.dpds(0)), 1000); + } + + /// @dev Ensure that you can update DPD data as updater. + function testUpdateDataAsUpdater() public { + repository.addDpd(0, address(0xBEEF), address(this), bytes32(uint256(69))); + repository.updateDpdData(0, bytes32(uint256(1000))); + + assertEq(uint256(repository.dpds(0)), 1000); + } + + /// @dev Ensure that you cannot update DPD data as non-owner/updater. + function testFailUpdateDataAsNonUpdaterNonOwner() public { + repository.addDpd(0, address(0xBEEF), address(0xBEEF), bytes32(uint256(69))); repository.updateDpdData(0, bytes32(uint256(1000))); assertEq(uint256(repository.dpds(0)), 1000); @@ -152,12 +163,12 @@ interface Repository { /// @notice Event emitted when a new DPD is added to the repository. event DPDAdded(uint256 indexed id, address owner, address updater, bytes32 cid); - /// @notice Event emitted when a new DPD is added to the repository. - event DPDUpdated(uint256 indexed id, bytes32 cid); + /// @notice Event emitted when a DPD is updated. + event DPDUpdated(uint256 indexed dpdId, bytes32 cid); /// @notice Event emitted when a DPD's owner is changed. - event DPDOwnerUpdated(uint256 indexed id, address newOwner); + event DPDOwnerChanged(uint256 indexed dpdId, address newOwner); /// @notice Event emitted when a DPD's upgrader is changed. - event DPDUpdaterUpdated(uint256 indexed id, address newUpdater); + event DPDUpdaterChanged(uint256 indexed dpdId, address newUpdater); }