Created
March 2, 2015 07:22
-
-
Save jorisbontje/da7abdc089d3446e4c2b to your computer and use it in GitHub Desktop.
test_ecrecover.py
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
import bitcoin as b | |
from pyethereum import tester, utils | |
class TestECRecover(object): | |
CONTRACT = """ | |
def test_ecrecover(h, v, r, s): | |
return(ecrecover(h, v, r, s)) | |
""" | |
def setup_class(cls): | |
cls.s = tester.state() | |
cls.c = cls.s.abi_contract(cls.CONTRACT) | |
cls.snapshot = cls.s.snapshot() | |
def setup_method(self, method): | |
self.s.revert(self.snapshot) | |
def test_ecrecover(self): | |
priv = b.sha256('some big long brainwallet password') | |
pub = b.privtopub(priv) | |
msghash = b.sha256('the quick brown fox jumps over the lazy dog') | |
V, R, S = b.ecdsa_raw_sign(msghash, priv) | |
assert b.ecdsa_raw_verify(msghash, (V, R, S), pub) | |
addr = utils.big_endian_to_int(utils.sha3(b.encode_pubkey(pub, 'bin')[1:])[12:]) | |
assert int(utils.privtoaddr(priv), 16) == addr | |
result = self.c.test_ecrecover(utils.big_endian_to_int(msghash.decode('hex')), V, R, S) | |
assert result == addr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment