Skip to content

Commit

Permalink
Merge pull request #45 from raid-guild/feat/rollCharacterSheetForPlayer
Browse files Browse the repository at this point in the history
support creation of sheet for player
  • Loading branch information
dan13ram authored Mar 26, 2024
2 parents 826da15 + 3c53687 commit 5e26999
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 55 deletions.
44 changes: 22 additions & 22 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CharacterAccountTest:testEquipAndUnequipViaMultiSendDelegateCall() (gas: 862930)
CharacterAccountTest:testEquipItemToCharacter() (gas: 875668)
CharacterAccountTest:testEquipViaMultiSendDelegateCall() (gas: 883105)
CharacterAccountTest:testUnequipItemToCharacter() (gas: 870458)
CharacterAccountTest:test_Owner() (gas: 591129)
CharacterAccountTest:testEquipAndUnequipViaMultiSendDelegateCall() (gas: 863206)
CharacterAccountTest:testEquipItemToCharacter() (gas: 875944)
CharacterAccountTest:testEquipViaMultiSendDelegateCall() (gas: 883381)
CharacterAccountTest:testUnequipItemToCharacter() (gas: 870734)
CharacterAccountTest:test_Owner() (gas: 591405)
CharacterEligibilityAdaptorTest:testIsEligible() (gas: 53561)
CharacterEligibilityAdaptorTest:testSupportsInterface() (gas: 13427)
CharacterSheetsFactoryTest:testCreateAndInitialize() (gas: 3886107)
Expand All @@ -23,31 +23,31 @@ CharacterSheetsTest:testEquipItemToCharacter() (gas: 331712)
CharacterSheetsTest:testEquipItemToCharacterReverts() (gas: 216798)
CharacterSheetsTest:testGetCharacterSheetByCharacterId() (gas: 23246)
CharacterSheetsTest:testGetPlayerIdFromAccountAddress() (gas: 28011)
CharacterSheetsTest:testRemovePlayer() (gas: 947946)
CharacterSheetsTest:testRenounceSheet() (gas: 73174)
CharacterSheetsTest:testRemovePlayer() (gas: 948444)
CharacterSheetsTest:testRenounceSheet() (gas: 73170)
CharacterSheetsTest:testRenounceSheetReverts() (gas: 72911)
CharacterSheetsTest:testRestoreSheetAfterRemove() (gas: 786115)
CharacterSheetsTest:testRestoreSheetAfterRenounce() (gas: 722615)
CharacterSheetsTest:testRollCharacterSheet() (gas: 589678)
CharacterSheetsTest:testRollCharacterSheetFailNonMember() (gas: 61141)
CharacterSheetsTest:testRollCharacterSheetRevertAlreadyACharacter() (gas: 67815)
CharacterSheetsTest:testRollFailsForRenouncedSheet() (gas: 118687)
CharacterSheetsTest:testSafeTransferFrom() (gas: 466673)
CharacterSheetsTest:testSafeTransferFromBackAndForth() (gas: 250158)
CharacterSheetsTest:testTransferFrom() (gas: 459741)
CharacterSheetsTest:testRestoreSheetAfterRemove() (gas: 786375)
CharacterSheetsTest:testRestoreSheetAfterRenounce() (gas: 722875)
CharacterSheetsTest:testRollCharacterSheet() (gas: 589954)
CharacterSheetsTest:testRollCharacterSheetFailNonMember() (gas: 61385)
CharacterSheetsTest:testRollCharacterSheetRevertAlreadyACharacter() (gas: 68037)
CharacterSheetsTest:testRollFailsForRenouncedSheet() (gas: 118943)
CharacterSheetsTest:testSafeTransferFrom() (gas: 466665)
CharacterSheetsTest:testSafeTransferFromBackAndForth() (gas: 250152)
CharacterSheetsTest:testTransferFrom() (gas: 459737)
CharacterSheetsTest:testUnequipItemFromCharacter() (gas: 314856)
CharacterSheetsTest:testUpdateCharacterMetadata() (gas: 98930)
CharacterSheetsTest:testUpdateContractImplementation() (gas: 5106237)
ClassLevelAdaptorTest:testFuzz_GetCurrentLevel(uint256) (runs: 256, μ: 36922, ~: 31620)
CharacterSheetsTest:testUpdateContractImplementation() (gas: 5126700)
ClassLevelAdaptorTest:testFuzz_GetCurrentLevel(uint256) (runs: 256, μ: 37699, ~: 31620)
ClassLevelAdaptorTest:testSupportsInterface() (gas: 13427)
ClassesTest:testAssignClass() (gas: 281864)
ClassesTest:testClaimClass() (gas: 156784)
ClassesTest:testClassExp() (gas: 256831)
ClassesTest:testCreateClass() (gas: 134641)
ClassesTest:testFuzz_BalanceOf(uint256) (runs: 256, μ: 296667, ~: 306324)
ClassesTest:testFuzz_BalanceOf(uint256) (runs: 256, μ: 296695, ~: 306324)
ClassesTest:testRenounceClass() (gas: 240903)
ClassesTest:testRevokeClass() (gas: 213123)
ClassesTest:testTransferClass() (gas: 761708)
ClassesTest:testTransferClass() (gas: 762005)
ExperienceTest:testBurnExp() (gas: 195443)
ExperienceTest:testDropExp() (gas: 251916)
ExperienceTest:testExperienceDeployment() (gas: 18173)
Expand All @@ -57,7 +57,7 @@ HatsAdaptorTest:testIsCharacter() (gas: 83743)
HatsAdaptorTest:testIsGameMaster() (gas: 63906)
HatsAdaptorTest:testIsPlayer() (gas: 86846)
HatsAdaptorTest:testMintCharacterHat() (gas: 213222)
HatsAdaptorTest:testMintPlayerHat() (gas: 697854)
HatsAdaptorTest:testMintPlayerHat() (gas: 698130)
HatsAdaptorTest:test_CheckCharacterHatEligibility() (gas: 93087)
HatsAdaptorTest:test_addValidGame() (gas: 211)
ItemsTest:testClaimItem() (gas: 877294)
Expand All @@ -75,7 +75,7 @@ ItemsTest:testCreateItemTypeRevert() (gas: 63965)
ItemsTest:testDeleteItem() (gas: 240189)
ItemsTest:testDismantleItems() (gas: 1157990)
ItemsTest:testDismantleItemsRevert() (gas: 1215991)
ItemsTest:testDropLoot() (gas: 1247374)
ItemsTest:testDropLoot() (gas: 1247650)
ItemsTest:testDropLootRevert() (gas: 258002)
ItemsTest:testInvalidTreeAnd() (gas: 633033)
ItemsTest:testInvalidTreeNot() (gas: 850268)
Expand Down
2 changes: 1 addition & 1 deletion addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"network": "sepolia",
"Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921",
"CharacterAccount": "0xd29c191C281905E450028A97a7609dbD8833451E",
"CharacterSheetsImplementation": "0xD60e36945160281eB456A962408295B1FC257796",
"CharacterSheetsImplementation": "0xC64cce0680aE98e8Ce80a94675e9D980cdcceD93",
"ClassesImplementation": "0xaa80C864194bBd6c51D2aB13e83e70BA086AA7FE",
"CharacterSheetsFactory": "0x86e4dBE87d157b81701c810044600FF6638a192E",
"ClassLevelAdaptor": "0x84fe7896069D556fbAC53C30271c0380E43Fa7EB",
Expand Down
2 changes: 1 addition & 1 deletion scripts/CharacterSheetsImplementation.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract ExecuteCharacterSheetsImplementation is BaseExecutor {
console2.log("SHEET URI: ", sheetUri);

vm.broadcast(deployerPrivateKey);
uint256 tokenId = sheetsImp.rollCharacterSheet(sheetUri);
uint256 tokenId = sheetsImp.rollCharacterSheet(memberAddress, sheetUri);
console.log("Character Id:", tokenId);
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/implementations/CharacterSheetsImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ contract CharacterSheetsImplementation is ERC721URIStorageUpgradeable, UUPSUpgra
* @param _tokenURI the uri of the character sheet metadata
* if no uri is stored then it will revert to the base uri of the contract
*/
function rollCharacterSheet(string calldata _tokenURI) external returns (uint256) {
_checkRollReverts(msg.sender);
function rollCharacterSheet(address player, string calldata _tokenURI) external returns (uint256) {
_checkRollReverts(player);

uint256 existingCharacterId = _playerSheets[msg.sender];
uint256 existingCharacterId = _playerSheets[player];

if (existingCharacterId != 0 || _sheets[existingCharacterId].playerAddress == msg.sender) {
if (existingCharacterId != 0 || _sheets[existingCharacterId].playerAddress == player) {
// must restore sheet
revert Errors.PlayerError();
}
Expand All @@ -162,11 +162,11 @@ contract CharacterSheetsImplementation is ERC721URIStorageUpgradeable, UUPSUpgra
// setting salt as characterId

_sheets[characterId] =
CharacterSheet({accountAddress: characterAccount, playerAddress: msg.sender, inventory: new uint256[](0)});
CharacterSheet({accountAddress: characterAccount, playerAddress: player, inventory: new uint256[](0)});

_mintSheet(msg.sender, characterAccount, characterId, _tokenURI);
_mintSheet(player, characterAccount, characterId, _tokenURI);

emit NewCharacterSheetRolled(msg.sender, characterAccount, characterId);
emit NewCharacterSheetRolled(player, characterAccount, characterId);
return characterId;
}

Expand Down Expand Up @@ -473,28 +473,28 @@ contract CharacterSheetsImplementation is ERC721URIStorageUpgradeable, UUPSUpgra
return baseTokenURI;
}

function _checkRollReverts(address sender) internal view {
function _checkRollReverts(address player) internal view {
if (erc6551CharacterAccount == address(0) || erc6551Registry == address(0)) {
revert Errors.NotInitialized();
}

// check the eligibility adaptor to see if the player is eligible to roll a character sheet
if (
clones.characterEligibilityAdaptor() != address(0)
&& !ICharacterEligibilityAdaptor(clones.characterEligibilityAdaptor()).isEligible(sender)
&& !ICharacterEligibilityAdaptor(clones.characterEligibilityAdaptor()).isEligible(player)
) {
revert Errors.EligibilityError();
}
// a character cannot be a character
if (_characterSheets[sender] != 0) {
if (_characterSheets[player] != 0) {
revert Errors.CharacterError();
}

if (jailed[sender]) {
if (jailed[player]) {
revert Errors.Jailed();
}

if (balanceOf(sender) != 0) {
if (balanceOf(player) != 0) {
revert Errors.TokenBalanceError();
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/CharacterAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract CharacterAccountTest is SetUp {
function testEquipItemToCharacter() public {
dao.addMember(accounts.rando);
vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("new_test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "new_test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

assertEq(deployments.characterSheets.tokenURI(tokenId), "test_base_uri_character_sheets/new_test_token_uri/");
Expand Down Expand Up @@ -39,7 +39,7 @@ contract CharacterAccountTest is SetUp {
function testUnequipItemToCharacter() public {
dao.addMember(accounts.rando);
vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

assertEq(deployments.characterSheets.tokenURI(tokenId), "test_base_uri_character_sheets/test_token_uri/");
Expand Down Expand Up @@ -76,7 +76,7 @@ contract CharacterAccountTest is SetUp {
function testEquipViaMultiSendDelegateCall() public {
dao.addMember(accounts.rando);
vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

assertEq(deployments.characterSheets.tokenURI(tokenId), "test_base_uri_character_sheets/test_token_uri/");
Expand Down Expand Up @@ -110,7 +110,7 @@ contract CharacterAccountTest is SetUp {
function testEquipAndUnequipViaMultiSendDelegateCall() public {
dao.addMember(accounts.rando);
vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

assertEq(deployments.characterSheets.tokenURI(tokenId), "test_base_uri_character_sheets/test_token_uri/");
Expand Down Expand Up @@ -151,7 +151,7 @@ contract CharacterAccountTest is SetUp {
function test_Owner() public {
dao.addMember(accounts.rando);
vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");
address char = deployments.characterSheets.getCharacterSheetByCharacterId(tokenId).accountAddress;
CharacterAccount account = CharacterAccount(payable(char));
Expand Down
16 changes: 8 additions & 8 deletions test/CharacterSheet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract CharacterSheetsTest is SetUp {
function testRollCharacterSheet() public {
dao.addMember(accounts.admin);
vm.prank(accounts.admin);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.admin, "test_token_uri/");

assertEq(tokenId, 2, "Incorrect tokenId");
assertEq(deployments.characterSheets.tokenURI(2), "test_base_uri_character_sheets/test_token_uri/");
Expand Down Expand Up @@ -90,7 +90,7 @@ contract CharacterSheetsTest is SetUp {
dao.addMember(accounts.rando);

vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

vm.prank(accounts.rando);
Expand Down Expand Up @@ -137,7 +137,7 @@ contract CharacterSheetsTest is SetUp {
dao.addMember(accounts.rando);

vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

vm.prank(accounts.gameMaster);
Expand All @@ -153,7 +153,7 @@ contract CharacterSheetsTest is SetUp {

vm.prank(accounts.rando);
vm.expectRevert();
deployments.characterSheets.rollCharacterSheet("test_token_uri/");
deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
}

function testRestoreSheetAfterRemove() public {
Expand Down Expand Up @@ -192,7 +192,7 @@ contract CharacterSheetsTest is SetUp {
dao.addMember(accounts.rando);

vm.prank(accounts.rando);
uint256 tokenId = deployments.characterSheets.rollCharacterSheet("test_token_uri/");
uint256 tokenId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
assertEq(tokenId, 2, "characterId not assigned");

vm.prank(accounts.gameMaster);
Expand Down Expand Up @@ -282,13 +282,13 @@ contract CharacterSheetsTest is SetUp {
function testRollCharacterSheetFailNonMember() public {
vm.prank(accounts.rando);
vm.expectRevert(Errors.EligibilityError.selector);
deployments.characterSheets.rollCharacterSheet("test_token_uri/");
deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri/");
}

function testRollCharacterSheetRevertAlreadyACharacter() public {
vm.prank(accounts.player1);
vm.expectRevert(Errors.TokenBalanceError.selector);
deployments.characterSheets.rollCharacterSheet("test_token_uri/");
deployments.characterSheets.rollCharacterSheet(accounts.player1, "test_token_uri/");
}

function testChangeBaseUriRevertNotAdmin() public {
Expand Down Expand Up @@ -339,7 +339,7 @@ contract CharacterSheetsTest is SetUp {

vm.prank(accounts.player1);
vm.expectRevert();
deployments.characterSheets.rollCharacterSheet("test_token_uri/");
deployments.characterSheets.rollCharacterSheet(accounts.player1, "test_token_uri/");
}

function testTransferFrom() public {
Expand Down
2 changes: 1 addition & 1 deletion test/Classes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract ClassesTest is SetUp {
dao.addMember(accounts.rando);

vm.prank(accounts.rando);
uint256 randoId = deployments.characterSheets.rollCharacterSheet("test");
uint256 randoId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test");
assertEq(randoId, 2, "incorrect character id");

address character3 = deployments.characterSheets.getCharacterSheetByCharacterId(randoId).accountAddress;
Expand Down
2 changes: 1 addition & 1 deletion test/HatsAdaptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract HatsAdaptorTest is SetUp {
dao.addMember(accounts.rando);

vm.prank(accounts.rando);
deployments.characterSheets.rollCharacterSheet("rando_token_uri");
deployments.characterSheets.rollCharacterSheet(accounts.rando, "rando_token_uri");

assertTrue(hatsContracts.hats.isWearerOfHat(accounts.rando, _hatsData.playerHatId), "not wearing player hat");
}
Expand Down
3 changes: 2 additions & 1 deletion test/HatsEligibilityModules.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ contract Base is SetUp {

dao.addMember(playerHatWearer);
vm.prank(playerHatWearer);
uint256 testCharacterId = deployments.characterSheets.rollCharacterSheet("test_player_hat_wearer_uri");
uint256 testCharacterId =
deployments.characterSheets.rollCharacterSheet(playerHatWearer, "test_player_hat_wearer_uri");

characterHatWearer = deployments.characterSheets.getCharacterSheetByCharacterId(testCharacterId).accountAddress;

Expand Down
2 changes: 1 addition & 1 deletion test/Items.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract ItemsTest is SetUp {
dao.addMember(accounts.rando);

vm.prank(accounts.rando);
uint256 randoId = deployments.characterSheets.rollCharacterSheet("test_token_uri1/");
uint256 randoId = deployments.characterSheets.rollCharacterSheet(accounts.rando, "test_token_uri1/");

vm.startPrank(accounts.gameMaster);

Expand Down
4 changes: 2 additions & 2 deletions test/setup/SetUp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ contract SetUp is Test, Accounts, TestStructs {
//add player to dao
dao.addMember(accounts.player1);
// roll characterSheet for player 1
sheetsData.characterId1 = deployments.characterSheets.rollCharacterSheet("player1_test_uri");
sheetsData.characterId1 = deployments.characterSheets.rollCharacterSheet(accounts.player1, "player1_test_uri");

//store character address
accounts.character1 =
Expand All @@ -138,7 +138,7 @@ contract SetUp is Test, Accounts, TestStructs {
//add player to dao
dao.addMember(accounts.player2);
// roll characterSheet for player 2
sheetsData.characterId2 = deployments.characterSheets.rollCharacterSheet("player2_test_uri");
sheetsData.characterId2 = deployments.characterSheets.rollCharacterSheet(accounts.player2, "player2_test_uri");

//store character address
accounts.character2 =
Expand Down

0 comments on commit 5e26999

Please sign in to comment.