Skip to content
Merged
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
39 changes: 39 additions & 0 deletions test/Identity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ contract IdentityTest is Test {
assertEq(id.tokenURI(agentId), "ipfs://agent-1");
}

function test_agentIdsIncrease() public {
address op2 = makeAddr("operator2");
vm.prank(operator);
uint256 first = id.registerAgent(runtime, "ipfs://agent-1");

address runtime2 = makeAddr("runtime2");
vm.prank(op2);
uint256 second = id.registerAgent(runtime2, "ipfs://agent-2");

assertEq(first, 1);
assertEq(second, 2);
assertEq(id.ownerOf(first), operator);
assertEq(id.ownerOf(second), op2);
}

Comment thread
Viscous106 marked this conversation as resolved.
Resolved
function test_registerAgentEmitsEvent() public {
vm.expectEmit(true, true, false, true);
emit IIdentity.AgentRegistered(1, operator, runtime, "ipfs://a");
Expand All @@ -45,22 +60,46 @@ contract IdentityTest is Test {
id.setRuntimeKey(agentId, stranger);

address next = makeAddr("next");
vm.expectEmit(true, false, false, true);
emit IIdentity.RuntimeKeyChanged(agentId, next);
vm.prank(operator);
id.setRuntimeKey(agentId, next);
assertEq(id.runtimeKeyOf(agentId), next);
}

function test_setRuntimeKeyRejectsUnknownAgent() public {
address next = makeAddr("next");
vm.prank(operator);
vm.expectRevert(abi.encodeWithSelector(IIdentity.UnknownAgent.selector, 42));
id.setRuntimeKey(42, next);
}

function test_setRuntimeKeyRejectsZeroAddress() public {
Comment thread
Viscous106 marked this conversation as resolved.
Resolved
vm.prank(operator);
uint256 agentId = id.registerAgent(runtime, "");

vm.prank(operator);
vm.expectRevert(IIdentity.ZeroRuntimeKey.selector);
id.setRuntimeKey(agentId, address(0));
}

function test_runtimeKeyFollowsTokenTransferOwnership() public {
Comment thread
Viscous106 marked this conversation as resolved.
Resolved
vm.prank(operator);
uint256 agentId = id.registerAgent(runtime, "");
address buyer = makeAddr("buyer");
vm.prank(operator);
id.transferFrom(operator, buyer, agentId);
assertEq(id.operatorOf(agentId), buyer);
assertEq(id.runtimeKeyOf(agentId), runtime);
}

function test_unknownAgentReverts() public {
vm.expectRevert(abi.encodeWithSelector(IIdentity.UnknownAgent.selector, 42));
id.runtimeKeyOf(42);
}

function test_tokenURIOfUnknownAgentReverts() public {
vm.expectRevert(abi.encodeWithSelector(IIdentity.UnknownAgent.selector, 42));
id.tokenURI(42);
}
}
Loading