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
var MetaCoin = artifacts.require("./MetaCoin.sol"); | |
contract('MetaCoin', function(accounts) { | |
it("should put 10000 MetaCoin in the first account", async function() { | |
let meta = await MetaCoin.deployed(); | |
let balance = await meta.getBalance.call(accounts[0]); | |
assert.equal(balance.valueOf(), 10000, "10000 wasn't in teh first account") | |
}); |
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.8; | |
contract Verifier { | |
function recoverAddr(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (address) { | |
return ecrecover(msgHash, v, r, s); | |
} | |
function isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (bool) { | |
return ecrecover(msgHash, v, r, s) == _addr; | |
} | |
} |
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
const Web3 = require('web3') | |
const provider = new Web3.providers.HttpProvider('http://localhost:8545') | |
const web3 = new Web3(provider) | |
function toHex(str) { | |
var hex = '' | |
for(var i=0;i<str.length;i++) { | |
hex += ''+str.charCodeAt(i).toString(16) | |
} | |
return hex |
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
curl -X POST localhost:8545 --data '{ | |
"jsonrpc":"2.0", | |
"method": "eth_sign", | |
"params":["0x2fb5949a6a1dc03b6d59d4723bc913230a155d0d", "0x0564b25c8fcd6766f672d43252c8ee2597ad6c7a35315cf13e3b4d00bafc2e9f"], | |
"id":1 | |
}' |
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
signature = signature.substr(2); //remove 0x | |
const r = '0x' + signature.slice(0, 64) | |
const s = '0x' + signature.slice(64, 128) | |
const v = '0x' + signature.slice(128, 130) | |
const v_decimal = web3.toDecimal(v) |
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
//... | |
const SignVerifyArtifact = require('./contracts/SignAndVerifyExample') | |
const SignVerify = contract(SignVerifyArtifact) | |
SignVerify.setProvider(provider) | |
//... | |
SignVerify | |
.deployed() | |
.then(instance => { | |
let fixed_msg = `\x19Ethereum Signed Message:\n${msg.length}${msg}` | |
let fixed_msg_sha = web3.sha3(fixed_msg) |
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
const status = () => { | |
return MetaCoin.deployed() | |
.then(instance => { | |
return instance.getBalance.call(accounts[0]); | |
}) | |
.then(balance => { | |
assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); | |
}) | |
} |
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
const operationOne = function async (data) { | |
let step1 = await somePromise(data) | |
let step2 = await anotherPromise(step1) | |
return step2.data | |
} | |
actionOne() | |
.then(operationOne) | |
.then(data => { | |
//more work | |
}) |
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
var MetaCoin = artifacts.require("./MetaCoin.sol"); | |
// ... more code | |
contract('MetaCoin', function(accounts) { | |
it("should put 10000 MetaCoin in the first account", async function() { | |
let meta = await MetaCoin.deployed(); | |
let balance = await meta.getBalance.call(accounts[0]); | |
assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account") | |
}); | |
// ... more code |
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
it("should fail because function does not exist on contract", async function () { | |
let meta = await MetaCoin.deployed(); | |
try { | |
await meta.someNonExistentFn.call(); | |
} catch (e) { | |
return true; | |
} | |
throw new Error("I should never see this!") | |
}) |
OlderNewer