-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updated contract with minimal mvp
- Loading branch information
1 parent
0fdc5fb
commit f1db5e7
Showing
3 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
// SPDX-License-Identifier: MIT | ||
// Compatible with OpenZeppelin Contracts ^5.0.0 | ||
pragma solidity ^0.8.22; | ||
|
||
contract IPCM { | ||
uint256 public number; | ||
import {Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
|
||
function setNumber(uint256 newNumber) public { | ||
number = newNumber; | ||
contract IPCM is Ownable { | ||
constructor(address owner) Ownable(owner) {} | ||
|
||
string private cidMapping; | ||
|
||
event MappingUpdated(string value); | ||
|
||
function setValue(string memory value) public onlyOwner { | ||
cidMapping = value; | ||
emit MappingUpdated(value); | ||
} | ||
|
||
function increment() public { | ||
number++; | ||
function getValue() public view returns (string memory) { | ||
return cidMapping; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import {IPCM} from "../src/IPCM.sol"; | ||
|
||
contract IPCMTest is Test { | ||
IPCM public ipcm; | ||
address owner = address(1); | ||
string testCid = "QmTest123"; | ||
|
||
function setUp() public { | ||
ipcm = new IPCM(); | ||
ipcm = new IPCM(owner); | ||
vm.startPrank(owner); | ||
} | ||
|
||
function testSetValue() public { | ||
ipcm.setValue(testCid); | ||
assertEq(ipcm.getValue(), testCid); | ||
} | ||
|
||
function testOnlyOwnerCanSetValue() public { | ||
vm.stopPrank(); | ||
vm.startPrank(address(2)); | ||
vm.expectRevert(); | ||
ipcm.setValue(testCid); | ||
} | ||
|
||
function testEmitsEvent() public { | ||
emit IPCM.MappingUpdated(testCid); | ||
ipcm.setValue(testCid); | ||
} | ||
|
||
function testGetValue() public { | ||
string memory emptyValue = ipcm.getValue(); | ||
assertEq(emptyValue, ""); | ||
|
||
ipcm.setValue(testCid); | ||
string memory newValue = ipcm.getValue(); | ||
assertEq(newValue, testCid); | ||
} | ||
} |