-
Notifications
You must be signed in to change notification settings - Fork 12
/
namecoin.py
32 lines (24 loc) · 1.19 KB
/
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
from sim import Contract, Simulation, Tx, stop
class Namecoin(Contract):
"""Namecoin contract example from https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-White-Paper#wiki-identity-and-reputation-systems"""
def run(self, tx, contract, block):
if tx.value < block.basefee * 200:
stop("Insufficient fee")
if contract.storage[tx.data[0]] or tx.data[0] < 100:
stop("Key already reserved")
contract.storage[tx.data[0]] = tx.data[1]
class NamecoinRun(Simulation):
contract = Namecoin()
def test_insufficient_fee(self):
tx = Tx(sender='alice', value=10)
self.run(tx, self.contract)
assert self.stopped == 'Insufficient fee'
def test_reservation(self):
tx = Tx(sender='alice', value=200, data=['ethereum.bit', '54.200.236.204'])
self.run(tx, self.contract)
assert self.contract.storage['ethereum.bit'] == '54.200.236.204'
def test_double_reservation(self):
tx = Tx(sender='alice', value=200, data=['ethereum.bit', '127.0.0.1'])
self.run(tx, self.contract)
assert self.stopped == 'Key already reserved'
assert self.contract.storage['ethereum.bit'] == '54.200.236.204'