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

changed metadata hash to metadata uri #21

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions src/voting/ISimpleGaugeVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
pragma solidity ^0.8.0;

interface IGauge {
/// @param metadataURI URI for the metadata of the gauge
struct Gauge {
bool active;
uint256 created; // timestamp or epoch
bytes32 metadata;
string metadataURI;
// more space for data as this is a struct in a mapping
}
}
Expand Down Expand Up @@ -36,10 +37,10 @@ interface IGaugeVote {
//////////////////////////////////////////////////////////////*/

interface IGaugeManagerEvents {
event GaugeCreated(address indexed gauge, address indexed creator, string metadata);
event GaugeCreated(address indexed gauge, address indexed creator, string metadataURI);
event GaugeDeactivated(address indexed gauge);
event GaugeActivated(address indexed gauge);
event GaugeMetadataUpdated(address indexed gauge, string metadata);
event GaugeMetadataUpdated(address indexed gauge, string metadataURI);
}

interface IGaugeManagerErrors {
Expand Down
16 changes: 10 additions & 6 deletions src/voting/SimpleGaugeVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ contract SimpleGaugeVoter is

function createGauge(
address _gauge,
string calldata _metadata
string calldata _metadataURI
) external auth(GAUGE_ADMIN_ROLE) nonReentrant returns (address gauge) {
if (_gauge == address(0)) revert ZeroGauge();
if (gaugeExists(_gauge)) revert GaugeExists();

gauges[_gauge] = Gauge(true, block.timestamp, bytes32(abi.encode(_metadata)));
gauges[_gauge] = Gauge(true, block.timestamp, _metadataURI);
gaugeList.push(_gauge);

emit GaugeCreated(_gauge, _msgSender(), _metadata);
emit GaugeCreated(_gauge, _msgSender(), _metadataURI);
return _gauge;
}

Expand All @@ -267,11 +267,11 @@ contract SimpleGaugeVoter is

function updateGaugeMetadata(
address _gauge,
string calldata _metadata
string calldata _metadataURI
) external auth(GAUGE_ADMIN_ROLE) {
if (!gaugeExists(_gauge)) revert GaugeDoesNotExist(_gauge);
gauges[_gauge].metadata = keccak256(abi.encode(_metadata));
emit GaugeMetadataUpdated(_gauge, _metadata);
gauges[_gauge].metadataURI = _metadataURI;
emit GaugeMetadataUpdated(_gauge, _metadataURI);
}

/*///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -307,6 +307,10 @@ contract SimpleGaugeVoter is
Getters: Mappings
//////////////////////////////////////////////////////////////*/

function getGauge(address _gauge) external view returns (Gauge memory) {
return gauges[_gauge];
}

function getAllGauges() external view returns (address[] memory) {
return gaugeList;
}
Expand Down
12 changes: 12 additions & 0 deletions test/voting/GaugeManage.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ contract TestGaugeManage is GaugeVotingBase {
voter.updateGaugeMetadata(_gauge, newMetadata);
}

function testFuzz_canUpdateGaugeMetadata(address _gauge, string calldata metadata) public {
vm.assume(_gauge != address(0));
voter.createGauge(_gauge, metadata);

assertEq(voter.getGauge(_gauge).metadataURI, metadata);

string memory newMetadata = "new metadata";
voter.updateGaugeMetadata(_gauge, newMetadata);

assertEq(voter.getGauge(_gauge).metadataURI, newMetadata);
}

// can pause votes and resets
function testCanPauseVoteAndResets() public {
bytes memory err = "Pausable: paused";
Expand Down