Skip to content

Commit

Permalink
allow only game master or player to create character
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Apr 4, 2024
1 parent 7803c1f commit a34b233
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
53 changes: 27 additions & 26 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CharacterAccountTest:testEquipAndUnequipViaMultiSendDelegateCall() (gas: 863855)
CharacterAccountTest:testEquipItemToCharacter() (gas: 876542)
CharacterAccountTest:testEquipViaMultiSendDelegateCall() (gas: 883979)
CharacterAccountTest:testUnequipItemToCharacter() (gas: 871537)
CharacterAccountTest:test_Owner() (gas: 591747)
CharacterAccountTest:testEquipAndUnequipViaMultiSendDelegateCall() (gas: 863921)
CharacterAccountTest:testEquipItemToCharacter() (gas: 876608)
CharacterAccountTest:testEquipViaMultiSendDelegateCall() (gas: 884045)
CharacterAccountTest:testUnequipItemToCharacter() (gas: 871603)
CharacterAccountTest:test_Owner() (gas: 591813)
CharacterEligibilityAdaptorTest:testIsEligible() (gas: 53561)
CharacterEligibilityAdaptorTest:testSupportsInterface() (gas: 13427)
CharacterSheetsFactoryTest:testCreateAndInitialize() (gas: 3886107)
Expand All @@ -18,36 +18,37 @@ CharacterSheetsFactoryTest:testDeploymentRevert() (gas: 16700)
CharacterSheetsFactoryTest:testInitializeContracts() (gas: 3839130)
CharacterSheetsFactoryTest:testUpdateImplementationAddressStorage() (gas: 21541)
CharacterSheetsTest:testChangeBaseUri() (gas: 71664)
CharacterSheetsTest:testChangeBaseUriRevertNotAdmin() (gas: 71564)
CharacterSheetsTest:testEquipItemToCharacter() (gas: 333968)
CharacterSheetsTest:testChangeBaseUriRevertNotAdmin() (gas: 71586)
CharacterSheetsTest:testEquipItemToCharacter() (gas: 333990)
CharacterSheetsTest:testEquipItemToCharacterReverts() (gas: 218588)
CharacterSheetsTest:testGetCharacterSheetByCharacterId() (gas: 25397)
CharacterSheetsTest:testGetCharacterSheetByCharacterId() (gas: 25419)
CharacterSheetsTest:testGetPlayerIdFromAccountAddress() (gas: 30207)
CharacterSheetsTest:testRemovePlayer() (gas: 948632)
CharacterSheetsTest:testRemovePlayer() (gas: 948786)
CharacterSheetsTest:testRenounceSheet() (gas: 73170)
CharacterSheetsTest:testRenounceSheetReverts() (gas: 72911)
CharacterSheetsTest:testRestoreSheetAfterRemove() (gas: 788729)
CharacterSheetsTest:testRestoreSheetAfterRenounce() (gas: 745588)
CharacterSheetsTest:testRollCharacterSheet() (gas: 590142)
CharacterSheetsTest:testRollCharacterSheetFailNonMember() (gas: 61385)
CharacterSheetsTest:testRollCharacterSheetRevertAlreadyACharacter() (gas: 68037)
CharacterSheetsTest:testRollFailsForRenouncedSheet() (gas: 116739)
CharacterSheetsTest:testSafeTransferFrom() (gas: 469091)
CharacterSheetsTest:testSafeTransferFromBackAndForth() (gas: 268387)
CharacterSheetsTest:testTransferFrom() (gas: 480040)
CharacterSheetsTest:testUnequipItemFromCharacter() (gas: 317317)
CharacterSheetsTest:testRenounceSheetReverts() (gas: 72846)
CharacterSheetsTest:testRestoreSheetAfterRemove() (gas: 788817)
CharacterSheetsTest:testRestoreSheetAfterRenounce() (gas: 745654)
CharacterSheetsTest:testRollCharacterSheet() (gas: 590154)
CharacterSheetsTest:testRollCharacterSheetAsGameMaster() (gas: 607867)
CharacterSheetsTest:testRollCharacterSheetFailNonMember() (gas: 61384)
CharacterSheetsTest:testRollCharacterSheetRevertAlreadyACharacter() (gas: 68125)
CharacterSheetsTest:testRollFailsForRenouncedSheet() (gas: 116738)
CharacterSheetsTest:testSafeTransferFrom() (gas: 469024)
CharacterSheetsTest:testSafeTransferFromBackAndForth() (gas: 268404)
CharacterSheetsTest:testTransferFrom() (gas: 480062)
CharacterSheetsTest:testUnequipItemFromCharacter() (gas: 317339)
CharacterSheetsTest:testUpdateCharacterMetadata() (gas: 98927)
CharacterSheetsTest:testUpdateContractImplementation() (gas: 5165408)
ClassLevelAdaptorTest:testFuzz_GetCurrentLevel(uint256) (runs: 256, μ: 36519, ~: 31620)
CharacterSheetsTest:testUpdateContractImplementation() (gas: 5233610)
ClassLevelAdaptorTest:testFuzz_GetCurrentLevel(uint256) (runs: 256, μ: 36877, ~: 31620)
ClassLevelAdaptorTest:testSupportsInterface() (gas: 13427)
ClassesTest:testAssignClass() (gas: 281864)
ClassesTest:testClaimClass() (gas: 156835)
ClassesTest:testClassExp() (gas: 256984)
ClassesTest:testCreateClass() (gas: 134641)
ClassesTest:testFuzz_BalanceOf(uint256) (runs: 256, μ: 297015, ~: 306426)
ClassesTest:testFuzz_BalanceOf(uint256) (runs: 256, μ: 297066, ~: 306426)
ClassesTest:testRenounceClass() (gas: 240954)
ClassesTest:testRevokeClass() (gas: 213123)
ClassesTest:testTransferClass() (gas: 762398)
ClassesTest:testTransferClass() (gas: 762464)
ExperienceTest:testBurnExp() (gas: 195494)
ExperienceTest:testDropExp() (gas: 252018)
ExperienceTest:testExperienceDeployment() (gas: 18173)
Expand All @@ -57,7 +58,7 @@ HatsAdaptorTest:testIsCharacter() (gas: 87252)
HatsAdaptorTest:testIsGameMaster() (gas: 63906)
HatsAdaptorTest:testIsPlayer() (gas: 86846)
HatsAdaptorTest:testMintCharacterHat() (gas: 213375)
HatsAdaptorTest:testMintPlayerHat() (gas: 698318)
HatsAdaptorTest:testMintPlayerHat() (gas: 698384)
HatsAdaptorTest:test_CheckCharacterHatEligibility() (gas: 93138)
HatsAdaptorTest:test_addValidGame() (gas: 211)
ItemsTest:testClaimItem() (gas: 877546)
Expand All @@ -75,7 +76,7 @@ ItemsTest:testCreateItemTypeRevert() (gas: 63965)
ItemsTest:testDeleteItem() (gas: 240249)
ItemsTest:testDismantleItems() (gas: 1175062)
ItemsTest:testDismantleItemsRevert() (gas: 1233012)
ItemsTest:testDropLoot() (gas: 1248244)
ItemsTest:testDropLoot() (gas: 1248310)
ItemsTest:testDropLootRevert() (gas: 258077)
ItemsTest:testInvalidTreeAnd() (gas: 633183)
ItemsTest:testInvalidTreeNot() (gas: 850493)
Expand Down
2 changes: 1 addition & 1 deletion addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"network": "sepolia",
"Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921",
"CharacterAccount": "0x42D6c5A636f6359C36e37cBaA09568627B8F6Afc",
"CharacterSheetsImplementation": "0x6639BD11fA55384184208ae8bC49d5235E5eA30B",
"CharacterSheetsImplementation": "0x07677B64D6394beC320147a8fBC3CF859b85703F",
"ClassesImplementation": "0xC75219c28E8E9CAaBa6c2928519f179543daee0F",
"CharacterSheetsFactory": "0xAfFCc11509C4EBCfA78b72128eB1a2256504F135",
"ClassLevelAdaptor": "0x12b097B25BE1Ca56fB9943e8725b1965CF0908c2",
Expand Down
4 changes: 4 additions & 0 deletions src/implementations/CharacterSheetsImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ contract CharacterSheetsImplementation is
address player,
string calldata _tokenURI
) external returns (uint256) {
if (msg.sender != player && !IHatsAdaptor(clones.hatsAdaptor()).isGameMaster(msg.sender)) {
revert Errors.PlayerOrGameMasterOnly();
}

_checkRollReverts(player);

uint256 existingCharacterId = _playerSheets[player];
Expand Down
1 change: 1 addition & 0 deletions src/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ abstract contract Errors {
error RequirementError();
error ItemError();
error LengthMismatch();
error PlayerOrGameMasterOnly();

error CraftItemsError();
error CraftItemError();
Expand Down
9 changes: 9 additions & 0 deletions test/CharacterSheet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ contract CharacterSheetsTest is SetUp {
assertEq(deployments.characterSheets.tokenURI(3), "test_base_uri_character_sheets/test_token_uri/");
}

function testRollCharacterSheetAsGameMaster() public {
dao.addMember(accounts.admin);
vm.prank(accounts.gameMaster);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.admin, "test_token_uri/");

assertEq(tokenId, 3, "Incorrect tokenId");
assertEq(deployments.characterSheets.tokenURI(3), "test_base_uri_character_sheets/test_token_uri/");
}

function testChangeBaseUri() public {
string memory newBaseUri = "new_base_uri/";
vm.prank(accounts.admin);
Expand Down

0 comments on commit a34b233

Please sign in to comment.