Skip to content

Instantly share code, notes, and snippets.

@jorisbontje
Created March 3, 2015 14:07
Show Gist options
  • Save jorisbontje/f19a6355983fc45102f4 to your computer and use it in GitHub Desktop.
Save jorisbontje/f19a6355983fc45102f4 to your computer and use it in GitHub Desktop.
test_sha256.py
import bitcoin as b
from pyethereum import tester, utils
class TestSHA256(object):
CONTRACT = """
def func():
return(sha256([1,2], items=2))
"""
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_func(self):
ints = ''.join([utils.zpad(utils.int_to_big_endian(x), 32) for x in [1, 2]])
hash = b.sha256(ints)
assert self.c.func() == int(hash, 16) - 2**256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment