From 041ce3c2039aee6d624fc2e5119c4dccf933d38c Mon Sep 17 00:00:00 2001 From: gabrielfior Date: Wed, 18 Dec 2024 19:31:18 -0300 Subject: [PATCH] changed data type --- README.md | 2 +- src/NFT/AgentCommunication.sol | 4 +-- src/NFT/DoubleEndedStructQueue.sol | 2 +- test/AgentCommunication.t.sol | 50 +++++++++--------------------- 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 9048dd1..5dc4511 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Repository holding the contracts made by Gnosis Labs team. | OmenThumbnailMapping | Manages IPFS hashes for market thumbnails on Omen 2.0 | [0xe0cf08311F03850497B0ed6A2cf067f1750C3eFc](https://gnosisscan.io/address/0xe0cf08311f03850497b0ed6a2cf067f1750c3efc#code) | [omen-thumbnailmapping](https://thegraph.com/studio/subgraph/omen-thumbnailmapping/) | | OmenAgentResultMapping | Maps prediction results to markets on Omen 2.0 | [0xbe1F6944496923683ca849fc0cC93fD10523cB83](https://gnosisscan.io/address/0x260E1077dEA98e738324A6cEfB0EE9A272eD471a#code) | [omen-agentresultmapping](https://thegraph.com/studio/subgraph/omen-agentresultmapping/) | | Agent NFT | Agent NFTs that control mechs for NFT game | [0x0D7C0Bd4169D090038c6F41CFd066958fe7619D0](https://gnosisscan.io/address/0x0D7C0Bd4169D090038c6F41CFd066958fe7619D0#code) | | -| Agent communication contract | Simple contract storing message queue for each agent | [0x2B620D93B3eD777a24bB25710627be9a8856a01B](https://gnosisscan.io/address/0x2b620d93b3ed777a24bb25710627be9a8856a01b#code) | | +| Agent communication contract | Simple contract storing message queue for each agent | [0x68670EDDa41d26F25DAcd9fADE75ec6E6a104AC3](https://gnosisscan.io/address/0x68670EDDa41d26F25DAcd9fADE75ec6E6a104AC3#code) | | ## Set up contracts development diff --git a/src/NFT/AgentCommunication.sol b/src/NFT/AgentCommunication.sol index 6783c31..d47f97c 100644 --- a/src/NFT/AgentCommunication.sol +++ b/src/NFT/AgentCommunication.sol @@ -10,8 +10,8 @@ contract AgentCommunication is Ownable { mapping(address => DoubleEndedStructQueue.Bytes32Deque) public queues; uint256 public minimumValueForSendingMessageInWei; - event NewMessageSent(address indexed sender, address indexed agentAddress, bytes32 message); - event MessagePopped(address indexed agentAddress, bytes32 message); + event NewMessageSent(address indexed sender, address indexed agentAddress, bytes message); + event MessagePopped(address indexed agentAddress, bytes message); constructor() Ownable(msg.sender) { minimumValueForSendingMessageInWei = 10000000000000; // 0.00001 xDAI diff --git a/src/NFT/DoubleEndedStructQueue.sol b/src/NFT/DoubleEndedStructQueue.sol index b7975ca..15950b4 100644 --- a/src/NFT/DoubleEndedStructQueue.sol +++ b/src/NFT/DoubleEndedStructQueue.sol @@ -9,7 +9,7 @@ library DoubleEndedStructQueue { struct MessageContainer { address sender; address recipient; - bytes32 message; + bytes message; } struct Bytes32Deque { diff --git a/test/AgentCommunication.t.sol b/test/AgentCommunication.t.sol index 5ed52c7..ead9e4c 100644 --- a/test/AgentCommunication.t.sol +++ b/test/AgentCommunication.t.sol @@ -11,6 +11,14 @@ contract AgentCommunicationTest is Test { address owner = address(0x123); address agent = address(0x456); + function buildMessage() public view returns (DoubleEndedStructQueue.MessageContainer memory) { + return DoubleEndedStructQueue.MessageContainer({ + sender: agent, + recipient: address(0x789), + message: "Hello, Agent!" + }); + } + function setUp() public { vm.startPrank(owner); agentComm = new AgentCommunication(); @@ -45,11 +53,7 @@ contract AgentCommunicationTest is Test { } function testSendMessage() public { - DoubleEndedStructQueue.MessageContainer memory message = DoubleEndedStructQueue.MessageContainer({ - sender: agent, // or any appropriate address - recipient: address(0x789), // or any appropriate address - message: "Hello, Agent!" // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message = buildMessage(); vm.deal(agent, 1 ether); vm.startPrank(agent); agentComm.sendMessage{value: 10000000000000}(agent, message); @@ -60,11 +64,7 @@ contract AgentCommunicationTest is Test { } function testSendMessageInsufficientValue() public { - DoubleEndedStructQueue.MessageContainer memory message = DoubleEndedStructQueue.MessageContainer({ - sender: agent, - recipient: address(0x789), // or any appropriate address - message: bytes32("Hello, Agent!") // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message = buildMessage(); vm.deal(agent, 1 ether); vm.startPrank(agent); vm.expectRevert("Insufficient message value"); @@ -74,11 +74,7 @@ contract AgentCommunicationTest is Test { function testNewMessageSentEvent() public { address recipient = address(0x789); - DoubleEndedStructQueue.MessageContainer memory message = DoubleEndedStructQueue.MessageContainer({ - sender: agent, - recipient: recipient, - message: bytes32("Hello, Agent!") // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message = buildMessage(); vm.deal(agent, 1 ether); vm.startPrank(agent); @@ -92,11 +88,7 @@ contract AgentCommunicationTest is Test { } function testPopNextMessage() public { - DoubleEndedStructQueue.MessageContainer memory message = DoubleEndedStructQueue.MessageContainer({ - sender: agent, - recipient: address(0x789), // or any appropriate address - message: bytes32("Hello, Agent!") // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message = buildMessage(); vm.deal(agent, 1 ether); vm.startPrank(agent); agentComm.sendMessage{value: 10000000000000}(agent, message); @@ -116,11 +108,7 @@ contract AgentCommunicationTest is Test { // ToDo - reset name function testPopNextMessageNotByAgent() public { - DoubleEndedStructQueue.MessageContainer memory message = DoubleEndedStructQueue.MessageContainer({ - sender: agent, - recipient: address(0x789), // or any appropriate address - message: bytes32("Hello, Agent!") // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message = buildMessage(); vm.deal(agent, 1 ether); vm.startPrank(agent); agentComm.sendMessage{value: 10000000000000}(agent, message); @@ -135,17 +123,9 @@ contract AgentCommunicationTest is Test { function testCountMessages() public { // Initialize a message - DoubleEndedStructQueue.MessageContainer memory message1 = DoubleEndedStructQueue.MessageContainer({ - sender: agent, - recipient: address(0x789), - message: bytes32("Hello, Agent 1!") // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message1 = buildMessage(); - DoubleEndedStructQueue.MessageContainer memory message2 = DoubleEndedStructQueue.MessageContainer({ - sender: agent, - recipient: address(0x789), - message: bytes32("Hello, Agent 2!") // Ensure this is a bytes32 type - }); + DoubleEndedStructQueue.MessageContainer memory message2 = buildMessage(); // Fund the agent and start the prank vm.deal(agent, 1 ether);