Custom and numbered work examples updated to work without byte arrays. Revisit this...
[robmyers:artworld-ethereum.git] / tests / test_custom_works.py
1 from sim import Key, Simulator, load_serpent
2 from pyethereum.utils import coerce_to_bytes
3
4 class TestCustomWorks(object):
5
6     ARTIST = Key('artist') # 8802b7f0bfa5e9f5825f2fc708e1ad00d2c2b5d6
7     BEHOLDER = Key('beholder') # 7e5188934964c0c267839653f7a49c879c2c8dfc
8     ARTWORK_FOR_BEHOLDER = """<svg><rect x="23" y="23" height="123" width="123" style="fill:none;stroke:#2C8DFC;stroke-width:32" /></svg>"""
9
10     @classmethod
11     def setup_class(cls):
12         cls.code = load_serpent('serpent/custom_works.se')
13         cls.sim = Simulator({cls.ARTIST.address: 10**18,
14                              cls.BEHOLDER.address: 10**18})
15
16     def setup_method(self, method):
17         self.sim.reset()
18         self.contract = self.sim.load_contract(self.ARTIST, self.code)
19
20     def test_do_nothing(self):
21         data = []
22         response = self.sim.tx(self.BEHOLDER, self.contract, 0, data)
23         assert response[0] == 0
24
25     def test_create_work(self):
26         data = ["create"]
27         response = self.sim.tx(self.BEHOLDER, self.contract, 0, data)
28         artwork = "".join([coerce_to_bytes(fragment) for fragment in response])
29         assert artwork == self.ARTWORK_FOR_BEHOLDER
30