parent
14d301801e
commit
854ddd2f96
@ -0,0 +1,31 @@ |
||||
/* eslint-env node, mocha */ |
||||
/* global artifacts, contract, assert */ |
||||
|
||||
const Web3 = require('web3'); |
||||
const ethUtil = require('ethereumjs-util'); |
||||
|
||||
const provider = new Web3.providers.HttpProvider('http://localhost:8555'); // testrpc-sc
|
||||
const web3 = new Web3(provider); |
||||
const Simple = artifacts.require('./Simple.sol'); |
||||
|
||||
contract('Simple', accounts => { |
||||
it('should set x to 5', () => { |
||||
let simple; |
||||
return Simple.deployed() |
||||
.then(instance => instance.test(5)) // We need this line to generate some coverage
|
||||
.then(() => { |
||||
const message = 'Enclosed is my formal application for permanent residency in New Zealand'; |
||||
const messageSha3 = web3.sha3(message); |
||||
const signature = web3.eth.sign(accounts[0], messageSha3); |
||||
|
||||
const messageBuffer = new Buffer(messageSha3.replace('0x', ''), 'hex'); |
||||
const messagePersonalHash = ethUtil.hashPersonalMessage(messageBuffer); |
||||
|
||||
const sigParams = ethUtil.fromRpcSig(signature); |
||||
const publicKey = ethUtil.ecrecover(messagePersonalHash, sigParams.v, sigParams.r, sigParams.s); |
||||
const senderBuffer = ethUtil.pubToAddress(publicKey); |
||||
const sender = ethUtil.bufferToHex(senderBuffer); |
||||
assert.equal(sender, accounts[0]); |
||||
}); |
||||
}); |
||||
}); |
@ -1,22 +1,22 @@ |
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs') |
||||
const request = require('request') |
||||
const fs = require('fs'); |
||||
const request = require('request'); |
||||
|
||||
request({ |
||||
uri: 'http://localhost:8888', |
||||
body: { |
||||
jsonrpc: "2.0", |
||||
method: "web3_clientVersion", |
||||
jsonrpc: '2.0', |
||||
method: 'web3_clientVersion', |
||||
params: [], |
||||
id: 0 |
||||
id: 0, |
||||
}, |
||||
json: true |
||||
json: true, |
||||
}, (error, response, body) => { |
||||
if(error) { |
||||
console.error(error) |
||||
process.exit(1) |
||||
if (error) { |
||||
console.error(error); |
||||
process.exit(1); |
||||
} |
||||
fs.writeFileSync('../allFiredEvents', 'foobar') |
||||
process.exit(0) |
||||
}) |
||||
fs.writeFileSync('../allFiredEvents', 'foobar'); |
||||
process.exit(0); |
||||
}); |
||||
|
Loading…
Reference in new issue