Skip to content

Instantly share code, notes, and snippets.

@MidnightLightning
Last active September 20, 2018 19:46
Show Gist options
  • Save MidnightLightning/49fa4547aa0d3ca94a379129ecd91ad1 to your computer and use it in GitHub Desktop.
Save MidnightLightning/49fa4547aa0d3ca94a379129ecd91ad1 to your computer and use it in GitHub Desktop.
Sample Solidity contract
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);
}
}
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