Skip to content

Commit f1db5e7

Browse files
committed
feat: Updated contract with minimal mvp
1 parent 0fdc5fb commit f1db5e7

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

script/IPCM.s.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.8.13;
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.22;
33

44
import {Script, console} from "forge-std/Script.sol";
55
import {IPCM} from "../src/IPCM.sol";
@@ -12,7 +12,7 @@ contract IPCMScript is Script {
1212
function run() public {
1313
vm.startBroadcast();
1414

15-
ipcm = new IPCM();
15+
ipcm = new IPCM(msg.sender);
1616

1717
vm.stopBroadcast();
1818
}

src/IPCM.sol

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.8.13;
1+
// SPDX-License-Identifier: MIT
2+
// Compatible with OpenZeppelin Contracts ^5.0.0
3+
pragma solidity ^0.8.22;
34

4-
contract IPCM {
5-
uint256 public number;
5+
import {Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
66

7-
function setNumber(uint256 newNumber) public {
8-
number = newNumber;
7+
contract IPCM is Ownable {
8+
constructor(address owner) Ownable(owner) {}
9+
10+
string private cidMapping;
11+
12+
event MappingUpdated(string value);
13+
14+
function setValue(string memory value) public onlyOwner {
15+
cidMapping = value;
16+
emit MappingUpdated(value);
917
}
1018

11-
function increment() public {
12-
number++;
19+
function getValue() public view returns (string memory) {
20+
return cidMapping;
1321
}
1422
}

test/IPCM.t.sol

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.8.13;
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.22;
33

44
import {Test, console} from "forge-std/Test.sol";
55
import {IPCM} from "../src/IPCM.sol";
66

77
contract IPCMTest is Test {
88
IPCM public ipcm;
9+
address owner = address(1);
10+
string testCid = "QmTest123";
911

1012
function setUp() public {
11-
ipcm = new IPCM();
13+
ipcm = new IPCM(owner);
14+
vm.startPrank(owner);
15+
}
16+
17+
function testSetValue() public {
18+
ipcm.setValue(testCid);
19+
assertEq(ipcm.getValue(), testCid);
20+
}
21+
22+
function testOnlyOwnerCanSetValue() public {
23+
vm.stopPrank();
24+
vm.startPrank(address(2));
25+
vm.expectRevert();
26+
ipcm.setValue(testCid);
27+
}
28+
29+
function testEmitsEvent() public {
30+
emit IPCM.MappingUpdated(testCid);
31+
ipcm.setValue(testCid);
32+
}
33+
34+
function testGetValue() public {
35+
string memory emptyValue = ipcm.getValue();
36+
assertEq(emptyValue, "");
37+
38+
ipcm.setValue(testCid);
39+
string memory newValue = ipcm.getValue();
40+
assertEq(newValue, testCid);
1241
}
1342
}

0 commit comments

Comments
 (0)