Last active
September 20, 2018 19:46
-
-
Save MidnightLightning/49fa4547aa0d3ca94a379129ecd91ad1 to your computer and use it in GitHub Desktop.
Sample Solidity contract
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
pragma solidity ^0.4.25; | |
contract Sampler { | |
string public name = "Sample Contract"; | |
address public owner = msg.sender; | |
event NewOwner(address indexed newOwner); | |
modifier onlyOwner { | |
require(msg.sender == owner, "Sender is not the Owner"); | |
_; | |
} | |
function changeOwner(address _newOwner) onlyOwner public { | |
owner = _newOwner; | |
emit NewOwner(_newOwner); | |
} | |
} |
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
pragma solidity ^0.4.0; | |
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "./Sampler.sol"; | |
contract SamplerTest { | |
Sampler sampler; | |
function beforeAll () public { | |
sampler = new Sampler(); | |
} | |
function checkName () public { | |
bytes32 name; | |
string memory givenName = sampler.name(); | |
assembly { | |
name := mload(add(givenName, 32)) | |
} | |
Assert.equal(name, bytes32("Sample Contract"), "Name not set"); | |
} | |
function checkOwner () public { | |
Assert.equal(sampler.owner(), address(this), "Not the owner"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment