Skip to content

Zone traits fix #1372

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

Merged
merged 3 commits into from
May 2, 2024
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
26 changes: 13 additions & 13 deletions contracts/src/Zones721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract Zones721 is ERC721 {
uint256 public mintPrice = 1 ether;
string public baseURI = "https://assets.downstream.game";

uint256 public currentTokenId;
uint256 public lastTokenId;
address owner; // The ZoneRule owns this
State state;

Expand Down Expand Up @@ -79,19 +79,19 @@ contract Zones721 is ERC721 {
_;
}

constructor(address _owner) ERC721("DownstreamZone", "DSZ") {
constructor(address _owner) ERC721("Downstream Zone", "DSZ") {
owner = _owner;
}

function mintTo(address recipient) public payable returns (uint256) {
if (msg.value != mintPrice) {
revert MintPriceNotPaid();
}
uint256 newTokenId = currentTokenId + 1;
uint256 newTokenId = lastTokenId + 1;
if (newTokenId > TOTAL_SUPPLY) {
revert MaxSupply();
}
currentTokenId = newTokenId;
lastTokenId = newTokenId;
_safeMint(recipient, newTokenId);

// setup zone data
Expand Down Expand Up @@ -172,11 +172,11 @@ contract Zones721 is ERC721 {
"[",
getTraitLocation(tokenId),
",",
getTraitGooType(),
getTraitGooType(tokenId),
",",
getTraitTileRotation(),
getTraitTileRotation(tokenId),
",",
getTraitHistoricalGovernance(),
getTraitHistoricalGovernance(tokenId),
"]"
);
}
Expand All @@ -187,33 +187,33 @@ contract Zones721 is ERC721 {
);
}

function getTraitGooType() internal view returns (bytes memory) {
function getTraitGooType(uint256 tokenId) internal view returns (bytes memory) {
return abi.encodePacked(
"{\"trait_type\": \"",
GOO_TYPE_LABEL,
"\", \"value\": \"",
GOO_TYPE_VALUES[getTraitIndex(currentTokenId, GOO_TYPE_LABEL, GOO_TYPE_COUNT)],
GOO_TYPE_VALUES[getTraitIndex(tokenId, GOO_TYPE_LABEL, GOO_TYPE_COUNT)],
"\"}"
);
}

function getTraitTileRotation() internal view returns (bytes memory) {
function getTraitTileRotation(uint256 tokenId) internal view returns (bytes memory) {
return abi.encodePacked(
"{\"trait_type\": \"",
TILE_ROTATION_LABEL,
"\", \"value\": \"",
TILE_ROTATION_VALUES[getTraitIndex(currentTokenId, TILE_ROTATION_LABEL, TILE_ROTATION_COUNT)],
TILE_ROTATION_VALUES[getTraitIndex(tokenId, TILE_ROTATION_LABEL, TILE_ROTATION_COUNT)],
"\"}"
);
}

function getTraitHistoricalGovernance() internal view returns (bytes memory) {
function getTraitHistoricalGovernance(uint256 tokenId) internal view returns (bytes memory) {
return abi.encodePacked(
"{\"trait_type\": \"",
HISTORICAL_GOVERNANCE_LABEL,
"\", \"value\": \"",
HISTORICAL_GOVERNANCE_VALUES[getTraitIndex(
currentTokenId, HISTORICAL_GOVERNANCE_LABEL, HISTORICAL_GOVERNANCE_COUNT
tokenId, HISTORICAL_GOVERNANCE_LABEL, HISTORICAL_GOVERNANCE_COUNT
)],
"\"}"
);
Expand Down
23 changes: 15 additions & 8 deletions contracts/test/rules/Zones.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ contract ZoneTest is Test, GameTest {
}

function test_mint() public {
zoneOwnership.mintTo{value: 1 ether}(address(1));
for (uint256 i = 1; i <= 100; i++) {
zoneOwnership.mintTo{value: 1 ether}(address(1));
}

console2.log("100 zones have been minted.");

// Output the data for zone 1
string memory dataURI1 = zoneOwnership.tokenURI(1);
console2.log(dataURI1);
zoneOwnership.mintTo{value: 1 ether}(address(1));
string memory dataURI2 = zoneOwnership.tokenURI(2);
console2.log(dataURI2);
console2.log("Data for zone 1: ", dataURI1);

// Output the data for zone 42
string memory dataURI2 = zoneOwnership.tokenURI(42);
console2.log("Data for zone 42: ", dataURI2);
}

function test_transferZoneOwnership() public {
Expand Down Expand Up @@ -49,10 +56,10 @@ contract ZoneTest is Test, GameTest {
}

function test_RevertMintMaxSupplyReached() public {
uint256 slot = stdstore.target(address(zoneOwnership)).sig("currentTokenId()").find();
uint256 slot = stdstore.target(address(zoneOwnership)).sig("lastTokenId()").find();
bytes32 loc = bytes32(slot);
bytes32 mockedCurrentTokenId = bytes32(abi.encode(32000));
vm.store(address(zoneOwnership), loc, mockedCurrentTokenId);
bytes32 mockedLastTokenId = bytes32(abi.encode(32000));
vm.store(address(zoneOwnership), loc, mockedLastTokenId);
vm.expectRevert(MaxSupply.selector);
zoneOwnership.mintTo{value: 1 ether}(address(1));
}
Expand Down
Loading