63 lines
1.5 KiB
Python
63 lines
1.5 KiB
Python
from dexorder.blockstate import BlockState, BlockDict
|
|
from dexorder.database.model.block import Block
|
|
|
|
block_10 = Block(chain=1, height=10, hash=bytes.fromhex('10'), parent=bytes.fromhex('09'), data=None)
|
|
block_11a = Block(chain=1, height=11, hash=bytes.fromhex('1a'), parent=block_10.hash, data=None)
|
|
block_11b = Block(chain=1, height=11, hash=bytes.fromhex('1b'), parent=block_10.hash, data=None)
|
|
block_12a = Block(chain=1, height=12, hash=bytes.fromhex('12'), parent=block_11a.hash, data=None)
|
|
state = BlockState(block_10, {'series':{'foo':'bar'}})
|
|
BlockState.set_cur(state)
|
|
d = BlockDict('series')
|
|
|
|
def start_block(b):
|
|
Block.set_cur(b)
|
|
state.add_block(b)
|
|
|
|
start_block(block_11a)
|
|
del d['foo']
|
|
d['foue'] = 'barre'
|
|
|
|
start_block(block_12a)
|
|
d['foo'] = 'bar2'
|
|
|
|
start_block(block_11b)
|
|
d['fu'] = 'ku'
|
|
|
|
def print_dict(x:dict=d):
|
|
for k, v in x.items():
|
|
print(f'{k:>10} : {v}')
|
|
|
|
for block in [block_10,block_11a,block_12a,block_11b]:
|
|
Block.set_cur(block)
|
|
print()
|
|
print(Block.cur().hash)
|
|
print_dict()
|
|
|
|
def test11b():
|
|
Block.set_cur(block_11b)
|
|
assert 'fu' in d
|
|
assert d['fu'] == 'ku'
|
|
assert 'foo' in d
|
|
assert d['foo'] == 'bar'
|
|
|
|
def test12a():
|
|
Block.set_cur(block_12a)
|
|
assert 'fu' not in d
|
|
assert 'foo' in d
|
|
assert d['foo'] == 'bar2'
|
|
assert 'foue' in d
|
|
assert d['foue'] == 'barre'
|
|
|
|
test11b()
|
|
test12a()
|
|
state.promote_root(block_11a)
|
|
print()
|
|
print('promoted root')
|
|
print_dict(state.root_state)
|
|
test12a()
|
|
state.promote_root(block_12a)
|
|
print()
|
|
print('promoted root')
|
|
print_dict(state.root_state)
|
|
test12a()
|