-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_namecoin.py
34 lines (24 loc) · 1.09 KB
/
test_namecoin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from sim import Key, Simulator, compile_serpent
from pyethereum import utils
class TestNamecoin(object):
ALICE = Key('cow')
@classmethod
def setup_class(cls):
cls.code = compile_serpent('examples/namecoin.se')
cls.sim = Simulator({cls.ALICE.address: 10**18})
def setup_method(self, method):
self.sim.reset()
self.contract = self.sim.load_contract(self.ALICE, self.code)
def test_reservation(self):
data = ['ethereum.bit', '54.200.236.204']
ans = self.sim.tx(self.ALICE, self.contract, 0, data)
assert ans == [1]
assert self.sim.get_storage_dict(self.contract) == {utils.zpad('ethereum.bit', 32): '54.200.236.204'}
def test_double_reservation(self):
data = ['ethereum.bit', '127.0.0.1']
ans = self.sim.tx(self.ALICE, self.contract, 0, data)
assert ans == [1]
data = ['ethereum.bit', '127.0.0.2']
ans = self.sim.tx(self.ALICE, self.contract, 0, data)
assert ans == [0]
assert self.sim.get_storage_dict(self.contract) == {utils.zpad('ethereum.bit', 32): '127.0.0.1'}