Skip to content

Instantly share code, notes, and snippets.

import 'dapple/test/test.sol';
import 'mydapp/math.sol';
contract MathTest is Test {
Math m;
function setUp() {
m = new Math();
}
function testAdd() {
// tests start with `test`. Each is called on a new
@nmushegian
nmushegian / test.sol
Created August 23, 2015 11:47
dappsys/test/test.sol
import 'dappsys/test/debug.sol';
contract Test is Debug {
bytes32 testname;
address me;
// easy way to detect if its a test from the abi
bool public IS_TEST;
bool public failed;
function Test() {
me = address(this);
### Keybase proof
I hereby claim:
* I am nmushegian on github.
* I am nikolai (https://keybase.io/nikolai) on keybase.
* I have a public key ASDofU01Z_R3rrE14Z8hXW7SoYlDl8TngurdU66CLi_w0Qo
To claim this, I am signing this object:
contract MyTargetInterface {
function func1(int arg1, int arg2) returns (int ret);
function func2(bytes32 arg1) returns (bytes32 ret);
}
contract MyActions is DSControlledAction, MyTargetInterface {
function MyActions( DSController env ) DSControlledAction( env ) {}
function func1(int arg1, int arg2) returns (int ret) {
setReturn(bytes32(arg1 + arg2));
return 0; // doesn't matter
contract MyTargetInterface {
function func1(int arg1, int arg2) returns (int ret);
function func2(bytes32 arg1) returns (bytes32 ret);
}
contract MyActions is DSControlledAction, MyTargetInterface {
function MyActions( DSController env ) DSControlledAction( env ) {}
function func1(int arg1, int arg2) returns (int ret) {
setReturn(bytes32(arg1 + arg2));
return 0; // doesn't matter
contract MyTargetInterface {
function func1(int arg1, int arg2) returns (int ret);
function func2(bytes32 arg1) returns (bytes32 ret);
}
contract MyActions is DSControlledAction, MyTargetInterface {
function MyActions( DSNullMap env ) DSControlledAction( env ) {}
function func1(int arg1, int arg2) returns (int ret) {
setReturn(bytes32(arg1 + arg2));
return 0; // doesn't matter
import 'erc20/erc20.sol'
import 'feedbase/user.sol';
contract TokenOption is FeedBaseUser(0) {
address _beneficiary;
ERC20 _token;
ERC20 _buy_with;
address _optionee;
uint _expiration;
uint _price;
```
// This code snippet shows how an external function can use a pattern like
// python's `try..except..else` with `.call`, `throw`, and reentry
contract TryExceptElsePatternUser {
address _sender;
function tryExceptElsePatternExample()
external // must be external
{
if( msg.sender == address(this) ) {
@nmushegian
nmushegian / rate_accumulator.sol
Last active September 1, 2019 00:55
continuous growth/decay with variable rate - from maker-core
// This is a really bad and wasteful pattern from a long time ago!
// Just prorate against an internal continuously-growing conversion rate!
// See Maker code or similar
import 'dappsys/auth.sol';
import 'misc/math.sol';
// maintain a `last_touched` with each balance, then prorate it before any time it is touched.
// addPoint to change the rate
// this will ensure all balances appear to have the correct continuous growth/decay even if
@nmushegian
nmushegian / when.sol
Created February 2, 2017 19:06
degeneracy
contract When {
modifier when(bool b) { b||1/0;_; }
}