fix blockchain args

This commit is contained in:
Yostra 2020-01-23 11:41:48 -08:00
parent 7f115d70e4
commit ca053e5a60
3 changed files with 34 additions and 17 deletions

View File

@ -49,9 +49,9 @@ class TestRpc:
await store._clear_database()
blocks = bt.get_consecutive_blocks(test_constants, 10, [], 10)
unspent_store = await UnspentStore.create("blockchain_test")
mempool = Mempool()
mempool = Mempool(unspent_store)
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
await store.add_block(blocks[0])
for i in range(1, 9):
result, removed = await b.receive_block(blocks[i])

View File

@ -38,21 +38,21 @@ async def setup_two_nodes():
store_2 = await FullNodeStore.create("blockchain_test_2")
await store_1._clear_database()
await store_2._clear_database()
unspent_store1 = await UnspentStore.create("blockchain_test")
mempool1 = Mempool()
unspent_store2 = await UnspentStore.create("blockchain_test")
mempool2 = Mempool()
b_1: Blockchain = await Blockchain.create({}, unspent_store1, test_constants)
b_2: Blockchain = await Blockchain.create({}, unspent_store2, test_constants)
unspent_store_1 = await UnspentStore.create("blockchain_test")
mempool_1 = Mempool(unspent_store_1)
unspent_store_2 = await UnspentStore.create("blockchain_test_2")
mempool_2 = Mempool(unspent_store_2)
b_1: Blockchain = await Blockchain.create({}, unspent_store_1, store_1, test_constants)
b_2: Blockchain = await Blockchain.create({}, unspent_store_2, store_2, test_constants)
await store_1.add_block(FullBlock.from_bytes(test_constants["GENESIS_BLOCK"]))
await store_2.add_block(FullBlock.from_bytes(test_constants["GENESIS_BLOCK"]))
full_node_1 = FullNode(store_1, b_1, mempool1, unspent_store1)
full_node_1 = FullNode(store_1, b_1, mempool_1, unspent_store_1)
server_1 = ChiaServer(21234, full_node_1, NodeType.FULL_NODE)
_ = await server_1.start_server("127.0.0.1", full_node_1._on_connect)
full_node_1._set_server(server_1)
full_node_2 = FullNode(store_2, b_2, mempool2, unspent_store2)
full_node_2 = FullNode(store_2, b_2, mempool_2, unspent_store_2)
server_2 = ChiaServer(21235, full_node_2, NodeType.FULL_NODE)
full_node_2._set_server(server_2)
@ -67,3 +67,5 @@ async def setup_two_nodes():
await server_2.await_closed()
await store_1.close()
await store_2.close()
await unspent_store_1.close()
await unspent_store_2.close()

View File

@ -8,6 +8,7 @@ from blspy import PrivateKey
from src.blockchain import Blockchain, ReceiveBlockResult
from src.consensus.constants import constants
from src.mempool import Mempool
from src.store import FullNodeStore
from src.types.body import Body
from src.types.coinbase import CoinbaseInfo
from src.types.full_block import FullBlock
@ -46,7 +47,9 @@ class TestGenesisBlock:
@pytest.mark.asyncio
async def test_basic_blockchain(self):
unspent_store = await UnspentStore.create("blockchain_test")
bc1 = await Blockchain.create({}, unspent_store)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
bc1 = await Blockchain.create({}, unspent_store, store)
assert len(bc1.get_current_tips()) == 1
genesis_block = bc1.get_current_tips()[0]
assert genesis_block.height == 0
@ -67,8 +70,10 @@ class TestBlockValidation:
Provides a list of 10 valid blocks, as well as a blockchain with 9 blocks added to it.
"""
blocks = bt.get_consecutive_blocks(test_constants, 10, [], 10)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
unspent_store = await UnspentStore.create("blockchain_test")
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
for i in range(1, 9):
result, removed = await b.receive_block(blocks[i])
assert (result == ReceiveBlockResult.ADDED_TO_HEAD)
@ -250,7 +255,9 @@ class TestBlockValidation:
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 2)
unspent_store = await UnspentStore.create("blockchain_test")
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
for i in range(1, num_blocks):
result, removed = await b.receive_block(blocks[i])
assert (result == ReceiveBlockResult.ADDED_TO_HEAD)
@ -283,7 +290,9 @@ class TestReorgs:
async def test_basic_reorg(self):
blocks = bt.get_consecutive_blocks(test_constants, 100, [], 9)
unspent_store = await UnspentStore.create("blockchain_test")
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
for block in blocks:
await b.receive_block(block)
@ -306,7 +315,9 @@ class TestReorgs:
async def test_reorg_from_genesis(self):
blocks = bt.get_consecutive_blocks(test_constants, 20, [], 9, b"0")
unspent_store = await UnspentStore.create("blockchain_test")
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
for block in blocks:
await b.receive_block(block)
assert b.get_current_tips()[0].height == 20
@ -341,7 +352,9 @@ class TestReorgs:
async def test_lca(self):
blocks = bt.get_consecutive_blocks(test_constants, 5, [], 9, b"0")
unspent_store = await UnspentStore.create("blockchain_test")
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
for block in blocks:
await b.receive_block(block)
@ -363,7 +376,9 @@ class TestReorgs:
async def test_get_header_hashes(self):
blocks = bt.get_consecutive_blocks(test_constants, 5, [], 9, b"0")
unspent_store = await UnspentStore.create("blockchain_test")
b: Blockchain = await Blockchain.create({}, unspent_store, test_constants)
store = await FullNodeStore.create("blockchain_test")
await store._clear_database()
b: Blockchain = await Blockchain.create({}, unspent_store, store, test_constants)
for block in blocks:
await b.receive_block(block)
header_hashes = b.get_header_hashes(blocks[-1].header_hash)