Skip to content

Commit

Permalink
contracts: Require message() call to be signed
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Feb 20, 2024
1 parent 034a99f commit fe6ac40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions backend/contracts/MessageBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
pragma solidity ^0.8.0;

contract MessageBox {
string public message;
string private _message;
address public author;

function setMessage(string calldata in_message) external {
message = in_message;
_message = in_message;
author = msg.sender;
}

function message() external view returns (string memory) {
if (msg.sender!=author) {
revert("not allowed");
}
return _message;
}
}
2 changes: 1 addition & 1 deletion backend/test/MessageBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("MessageBox", function () {
return { messageBox };
}

it("Should send message", async function () {
it("Should set message", async function () {
const {messageBox} = await deployMessageBox();

await messageBox.setMessage("hello world");
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function handleError(error: Error, errorMessage: string) {
}
async function fetchMessage(): Promise<Message> {
const message = await uwMessageBox.value!.message();
const author = await uwMessageBox.value!.author();
const message = await messageBox.value!.message();
const author = await messageBox.value!.author();
return { message, author };
}
Expand Down

0 comments on commit fe6ac40

Please sign in to comment.