Skip to content

Instantly share code, notes, and snippets.

@ismaelbej
Created April 7, 2018 03:54
Show Gist options
  • Save ismaelbej/ed863c494fc713c3f9c05e147390bcd2 to your computer and use it in GitHub Desktop.
Save ismaelbej/ed863c494fc713c3f9c05e147390bcd2 to your computer and use it in GitHub Desktop.
const Tx = artifacts.require("./Parser/Tx.sol");
const Simple = artifacts.require("./Simple.sol");
module.exports = function(deployer) {
deployer.deploy(Tx);
deployer.link(Tx, Simple);
deployer.deploy(Simple);
};
pragma solidity ^0.4.2;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
function Migrations() public {
owner = msg.sender;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
pragma solidity ^0.4.18;
import "./Parser/Tx.sol";
contract Simple {
function flip32Bytes(uint a) public returns (uint) {
return Tx.flip32Bytes(a);
}
}
pragma solidity ^0.4.2;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Simple.sol";
contract TestSimple {
function testSimple() public {
Simple simple = Simple(DeployedAddresses.Simple());
uint expected = simple.flip32Bytes(0);
Assert.equal(0, expected, "Should match");
}
}
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
}
}
};
pragma solidity ^0.4.19;
library Tx {
function flip32Bytes(uint _input) internal pure returns (uint) {
uint result;
assembly {
let pos := mload(0x40)
for { let i := 0 } lt(i, 32) { i := add(i, 1) } {
mstore8(add(pos, i), byte(sub(31, i), _input))
}
result := mload(pos)
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment