Skip to content
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
18 changes: 6 additions & 12 deletions the-guild-smart-contracts/script/CreateBadgesFromJson.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract CreateBadgesFromJson is Script {

struct BadgeData {
bytes32 name;
bytes32 description;
string description;
}

function run() public {
Expand Down Expand Up @@ -76,7 +76,7 @@ contract CreateBadgesFromJson is Script {
": ",
vm.toString(badges[i].name),
" - ",
vm.toString(badges[i].description)
badges[i].description
)
)
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -226,7 +220,7 @@ contract CreateBadgesFromJson is Script {
": ",
vm.toString(badge.name),
" - ",
vm.toString(badge.description)
badge.description
)
)
);
Expand Down
6 changes: 3 additions & 3 deletions the-guild-smart-contracts/script/FullDeploymentScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions the-guild-smart-contracts/script/TheGuildBadgeRegistry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions the-guild-smart-contracts/src/TheGuildBadgeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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");

Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 22 additions & 11 deletions the-guild-smart-contracts/test/TheGuildBadgeRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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");
Expand All @@ -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 {
Expand All @@ -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");
}
}
Loading