You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.2 KiB
31 lines
1.2 KiB
7 years ago
|
/* eslint-env node, mocha */
|
||
|
/* global artifacts, contract, assert */
|
||
|
|
||
|
const ethUtil = require('ethereumjs-util');
|
||
|
|
||
|
const Simple = artifacts.require('./Simple.sol');
|
||
|
|
||
|
contract('Simple', accounts => {
|
||
|
it('should set x to 5', () => {
|
||
|
let simple;
|
||
6 years ago
|
let messageSha3;
|
||
7 years ago
|
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';
|
||
6 years ago
|
messageSha3 = web3.utils.sha3(message);
|
||
|
const signature = web3.eth.sign(messageSha3, accounts[0]);
|
||
|
return signature;
|
||
|
})
|
||
|
.then((signature) => {
|
||
7 years ago
|
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);
|
||
6 years ago
|
assert.equal(sender, accounts[0].toLowerCase());
|
||
7 years ago
|
});
|
||
|
});
|
||
|
});
|