Skip to content

Commit 13f5e51

Browse files
committed
chore: Added initial cid for constructor, renamed functions
1 parent f1db5e7 commit 13f5e51

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ docs/
1212

1313
# Dotenv file
1414
.env
15+
.DS_Store

script/IPCM.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract IPCMScript is Script {
1212
function run() public {
1313
vm.startBroadcast();
1414

15-
ipcm = new IPCM(msg.sender);
15+
ipcm = new IPCM(msg.sender, "ipfs://");
1616

1717
vm.stopBroadcast();
1818
}

src/IPCM.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ pragma solidity ^0.8.22;
55
import {Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
66

77
contract IPCM is Ownable {
8-
constructor(address owner) Ownable(owner) {}
9-
108
string private cidMapping;
119

10+
constructor(address owner, string memory initialCID) Ownable(owner) {
11+
cidMapping = initialCID;
12+
}
13+
1214
event MappingUpdated(string value);
1315

14-
function setValue(string memory value) public onlyOwner {
16+
function updateMapping(string memory value) public onlyOwner {
1517
cidMapping = value;
1618
emit MappingUpdated(value);
1719
}
1820

19-
function getValue() public view returns (string memory) {
21+
function getMapping() public view returns (string memory) {
2022
return cidMapping;
2123
}
2224
}

test/IPCM.t.sol

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@ contract IPCMTest is Test {
1010
string testCid = "QmTest123";
1111

1212
function setUp() public {
13-
ipcm = new IPCM(owner);
13+
ipcm = new IPCM(owner, testCid);
1414
vm.startPrank(owner);
1515
}
1616

1717
function testSetValue() public {
18-
ipcm.setValue(testCid);
19-
assertEq(ipcm.getValue(), testCid);
18+
ipcm.updateMapping(testCid);
19+
assertEq(ipcm.getMapping(), testCid);
2020
}
2121

2222
function testOnlyOwnerCanSetValue() public {
2323
vm.stopPrank();
2424
vm.startPrank(address(2));
2525
vm.expectRevert();
26-
ipcm.setValue(testCid);
26+
ipcm.updateMapping(testCid);
2727
}
2828

2929
function testEmitsEvent() public {
3030
emit IPCM.MappingUpdated(testCid);
31-
ipcm.setValue(testCid);
31+
ipcm.updateMapping(testCid);
3232
}
3333

3434
function testGetValue() public {
35-
string memory emptyValue = ipcm.getValue();
36-
assertEq(emptyValue, "");
35+
string memory initialValue = ipcm.getMapping();
36+
assertEq(initialValue, testCid);
3737

38-
ipcm.setValue(testCid);
39-
string memory newValue = ipcm.getValue();
40-
assertEq(newValue, testCid);
38+
string memory newTestCid = "QmTest456";
39+
ipcm.updateMapping(newTestCid);
40+
string memory newValue = ipcm.getMapping();
41+
assertEq(newValue, newTestCid);
4142
}
4243
}

0 commit comments

Comments
 (0)