Skip to content

Commit

Permalink
changed data type
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfior committed Dec 18, 2024
1 parent fd21455 commit 041ce3c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/NFT/AgentCommunication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/NFT/DoubleEndedStructQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library DoubleEndedStructQueue {
struct MessageContainer {
address sender;
address recipient;
bytes32 message;
bytes message;
}

struct Bytes32Deque {
Expand Down
50 changes: 15 additions & 35 deletions test/AgentCommunication.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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);

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

0 comments on commit 041ce3c

Please sign in to comment.