diff --git a/the-guild-smart-contracts/script/CreateBadgesFromJson.s.sol b/the-guild-smart-contracts/script/CreateBadgesFromJson.s.sol index 757d8c1..dea6327 100644 --- a/the-guild-smart-contracts/script/CreateBadgesFromJson.s.sol +++ b/the-guild-smart-contracts/script/CreateBadgesFromJson.s.sol @@ -13,7 +13,7 @@ contract CreateBadgesFromJson is Script { struct BadgeData { bytes32 name; - bytes32 description; + string description; } function run() public { @@ -76,7 +76,7 @@ contract CreateBadgesFromJson is Script { ": ", vm.toString(badges[i].name), " - ", - vm.toString(badges[i].description) + badges[i].description ) ) ); @@ -126,20 +126,14 @@ contract CreateBadgesFromJson is Script { name := mload(add(nameBytes, 32)) } - // Parse description with proper bytes32 conversion - string memory descriptionStr = abi.decode( + // Parse description as string + string memory description = abi.decode( vm.parseJson( jsonData, string(abi.encodePacked(basePath, ".description")) ), (string) ); - bytes32 description; - bytes memory descriptionBytes = bytes(descriptionStr); - require(descriptionBytes.length <= 32, "description too long"); - assembly { - description := mload(add(descriptionBytes, 32)) - } tempBadges[count] = BadgeData({ name: name, @@ -215,7 +209,7 @@ contract CreateBadgesFromJson is Script { continue; } - try badgeRegistry.createBadge(badge.name, badge.description) { + try badgeRegistry.createBadge(badge.name, bytes(badge.description)) { console.log( string( abi.encodePacked( @@ -226,7 +220,7 @@ contract CreateBadgesFromJson is Script { ": ", vm.toString(badge.name), " - ", - vm.toString(badge.description) + badge.description ) ) ); diff --git a/the-guild-smart-contracts/script/FullDeploymentScript.s.sol b/the-guild-smart-contracts/script/FullDeploymentScript.s.sol index a70bfb5..86f4baf 100644 --- a/the-guild-smart-contracts/script/FullDeploymentScript.s.sol +++ b/the-guild-smart-contracts/script/FullDeploymentScript.s.sol @@ -56,15 +56,15 @@ contract FullDeploymentScript is Script { // Create some badges badgeRegistry.createBadge( bytes32("Rust"), - bytes32("Know how to code in Rust") + bytes("Know how to code in Rust") ); badgeRegistry.createBadge( bytes32("Solidity"), - bytes32("Know how to code in Solidity") + bytes("Know how to code in Solidity") ); badgeRegistry.createBadge( bytes32("TypeScript"), - bytes32("Know how to code in TypeScript") + bytes("Know how to code in TypeScript") ); // Deploy or attach to existing badge ranking via CREATE2 diff --git a/the-guild-smart-contracts/script/TheGuildBadgeRegistry.s.sol b/the-guild-smart-contracts/script/TheGuildBadgeRegistry.s.sol index 52e5da9..c7ae85d 100644 --- a/the-guild-smart-contracts/script/TheGuildBadgeRegistry.s.sol +++ b/the-guild-smart-contracts/script/TheGuildBadgeRegistry.s.sol @@ -15,31 +15,31 @@ contract TheGuildBadgeRegistryScript is Script { }(); registry.createBadge( bytes32("Rust"), - bytes32("Know how to code in Rust") + bytes("Know how to code in Rust") ); registry.createBadge( bytes32("Solidity"), - bytes32("Know how to code in Solidity") + bytes("Know how to code in Solidity") ); registry.createBadge( bytes32("Python"), - bytes32("Know how to code in Python") + bytes("Know how to code in Python") ); registry.createBadge( bytes32("JavaScript"), - bytes32("Know how to code in JavaScript") + bytes("Know how to code in JavaScript") ); registry.createBadge( bytes32("TypeScript"), - bytes32("Know how to code in TypeScript") + bytes("Know how to code in TypeScript") ); registry.createBadge( bytes32("React"), - bytes32("Know how to code in React") + bytes("Know how to code in React") ); registry.createBadge( bytes32("Next.js"), - bytes32("Know how to code in Next.js") + bytes("Know how to code in Next.js") ); vm.stopBroadcast(); } diff --git a/the-guild-smart-contracts/src/TheGuildBadgeRegistry.sol b/the-guild-smart-contracts/src/TheGuildBadgeRegistry.sol index 966f902..dce90ac 100644 --- a/the-guild-smart-contracts/src/TheGuildBadgeRegistry.sol +++ b/the-guild-smart-contracts/src/TheGuildBadgeRegistry.sol @@ -8,14 +8,14 @@ contract TheGuildBadgeRegistry { /// @notice Representation of a badge. struct Badge { bytes32 name; - bytes32 description; + bytes description; address creator; } /// @notice Emitted when a new badge is created. event BadgeCreated( bytes32 indexed name, - bytes32 description, + bytes description, address indexed creator ); @@ -30,7 +30,7 @@ contract TheGuildBadgeRegistry { /// @notice Create a new badge with a unique name. /// @param name The unique badge name (bytes32). /// @param description The badge description (bytes32). - function createBadge(bytes32 name, bytes32 description) external { + function createBadge(bytes32 name, bytes calldata description) external { require(name != bytes32(0), "EMPTY_NAME"); require(!nameExists[name], "DUPLICATE_NAME"); @@ -50,7 +50,7 @@ contract TheGuildBadgeRegistry { /// @dev Reverts if the badge does not exist. function getBadge( bytes32 name - ) external view returns (bytes32, bytes32, address) { + ) external view returns (bytes32, bytes memory, address) { require(nameExists[name], "NOT_FOUND"); Badge memory b = nameToBadge[name]; return (b.name, b.description, b.creator); @@ -76,7 +76,7 @@ contract TheGuildBadgeRegistry { /// @dev Reverts if index is out of bounds. function getBadgeAt( uint256 index - ) external view returns (bytes32, bytes32, address) { + ) external view returns (bytes32, bytes memory, address) { bytes32 name = badgeNames[index]; Badge memory b = nameToBadge[name]; return (b.name, b.description, b.creator); diff --git a/the-guild-smart-contracts/test/TheGuildAttestationResolver.t.sol b/the-guild-smart-contracts/test/TheGuildAttestationResolver.t.sol index 93bf719..5d17218 100644 --- a/the-guild-smart-contracts/test/TheGuildAttestationResolver.t.sol +++ b/the-guild-smart-contracts/test/TheGuildAttestationResolver.t.sol @@ -51,7 +51,7 @@ contract TheGuildAttestationResolverTest is Test { // Ensure badge exists badgeRegistry.createBadge( bytes32("Rust"), - bytes32("Know how to code in Rust") + bytes("Know how to code in Rust") ); // Build attestation request @@ -142,7 +142,7 @@ contract TheGuildAttestationResolverTest is Test { bytes32 schemaId = _registerSchema(); badgeRegistry.createBadge( bytes32("Rust"), - bytes32("Know how to code in Rust") + bytes("Know how to code in Rust") ); vm.prank(attester); @@ -171,7 +171,7 @@ contract TheGuildAttestationResolverTest is Test { bytes32 schemaId = _registerSchema(); badgeRegistry.createBadge( bytes32("Rust"), - bytes32("Know how to code in Rust") + bytes("Know how to code in Rust") ); vm.prank(attester); @@ -204,7 +204,7 @@ contract TheGuildAttestationResolverTest is Test { // Ensure badge exists badgeRegistry.createBadge( bytes32("Rust"), - bytes32("Know how to code in Rust") + bytes("Know how to code in Rust") ); AttestationRequest memory request = AttestationRequest({ diff --git a/the-guild-smart-contracts/test/TheGuildBadgeRanking.t.sol b/the-guild-smart-contracts/test/TheGuildBadgeRanking.t.sol index ba91b97..1b280e0 100644 --- a/the-guild-smart-contracts/test/TheGuildBadgeRanking.t.sol +++ b/the-guild-smart-contracts/test/TheGuildBadgeRanking.t.sol @@ -18,7 +18,7 @@ contract TheGuildBadgeRankingTest is Test { ranking = new TheGuildBadgeRanking(registry); // Create a badge for testing - registry.createBadge(badgeName, bytes32("A test badge")); + registry.createBadge(badgeName, bytes("A test badge")); } function test_UpvoteBadge_SucceedsAndEmitsEvent() public { diff --git a/the-guild-smart-contracts/test/TheGuildBadgeRegistry.t.sol b/the-guild-smart-contracts/test/TheGuildBadgeRegistry.t.sol index 3aa3523..d9685ca 100644 --- a/the-guild-smart-contracts/test/TheGuildBadgeRegistry.t.sol +++ b/the-guild-smart-contracts/test/TheGuildBadgeRegistry.t.sol @@ -13,7 +13,7 @@ contract TheGuildBadgeRegistryTest is Test { function test_CreateBadge_SucceedsAndEmitsEvent() public { bytes32 name = bytes32("BADGE_ALPHA"); - bytes32 description = bytes32("First badge"); + bytes memory description = bytes("First badge"); vm.expectEmit(true, false, false, true); emit TheGuildBadgeRegistry.BadgeCreated( @@ -24,7 +24,7 @@ contract TheGuildBadgeRegistryTest is Test { registry.createBadge(name, description); - (bytes32 rName, bytes32 rDesc, address creator) = registry.getBadge( + (bytes32 rName, bytes memory rDesc, address creator) = registry.getBadge( name ); assertEq(rName, name, "name mismatch"); @@ -37,10 +37,10 @@ contract TheGuildBadgeRegistryTest is Test { function test_CreateBadge_RevertOnDuplicate() public { bytes32 name = bytes32("BADGE_DUP"); - registry.createBadge(name, bytes32("desc")); + registry.createBadge(name, bytes("desc")); vm.expectRevert(bytes("DUPLICATE_NAME")); - registry.createBadge(name, bytes32("another")); + registry.createBadge(name, bytes("another")); } function test_GetBadge_RevertOnMissing() public { @@ -50,23 +50,34 @@ contract TheGuildBadgeRegistryTest is Test { function test_CreateBadge_RevertOnEmptyName() public { vm.expectRevert(bytes("EMPTY_NAME")); - registry.createBadge(bytes32(0), bytes32("desc")); + registry.createBadge(bytes32(0), bytes("desc")); } function test_GetBadgeAt_ByIndex() public { bytes32 a = bytes32("BADGE_A"); bytes32 b = bytes32("BADGE_B"); - registry.createBadge(a, bytes32("descA")); - registry.createBadge(b, bytes32("descB")); + registry.createBadge(a, bytes("descA")); + registry.createBadge(b, bytes("descB")); - (bytes32 n0, bytes32 d0, address c0) = registry.getBadgeAt(0); + (bytes32 n0, bytes memory d0, address c0) = registry.getBadgeAt(0); assertEq(n0, a); - assertEq(d0, bytes32("descA")); + assertEq(keccak256(d0), keccak256(bytes("descA"))); assertEq(c0, address(this)); - (bytes32 n1, bytes32 d1, address c1) = registry.getBadgeAt(1); + (bytes32 n1, bytes memory d1, address c1) = registry.getBadgeAt(1); assertEq(n1, b); - assertEq(d1, bytes32("descB")); + assertEq(keccak256(d1), keccak256(bytes("descB"))); assertEq(c1, address(this)); } + function test_CreateBadge_AllowsLongDescription() public { + bytes32 name = bytes32("BADGE_LONG"); + bytes memory longDesc = bytes( + "Long descriptions matter. Short buffers do not. This test proves it." + ); + + registry.createBadge(name, longDesc); + + (, bytes memory rDesc,) = registry.getBadge(name); + assertEq(keccak256(rDesc), keccak256(longDesc), "long description mismatch"); + } }