2020-02-06 18:12:33 +03:00
|
|
|
import asyncio
|
|
|
|
import pytest
|
2020-06-29 21:46:27 +03:00
|
|
|
from typing import List
|
|
|
|
from tests.setup_nodes import setup_full_system
|
2020-06-11 17:56:59 +03:00
|
|
|
from src.util.ints import uint32
|
2020-06-17 02:46:51 +03:00
|
|
|
from src.types.full_block import FullBlock
|
2020-06-30 17:28:33 +03:00
|
|
|
from src.util.make_test_constants import make_test_constants_with_genesis
|
2020-06-18 09:11:42 +03:00
|
|
|
from tests.time_out_assert import time_out_assert, time_out_assert_custom_interval
|
2020-04-21 07:29:47 +03:00
|
|
|
|
2020-06-28 17:26:10 +03:00
|
|
|
|
2020-07-06 09:06:55 +03:00
|
|
|
test_constants, bt = make_test_constants_with_genesis(
|
2020-06-29 12:42:57 +03:00
|
|
|
{
|
2020-07-13 19:40:32 +03:00
|
|
|
"DIFFICULTY_STARTING": 1000,
|
|
|
|
"MIN_ITERS_STARTING": 100000,
|
2020-06-29 12:42:57 +03:00
|
|
|
"NUMBER_ZERO_BITS_CHALLENGE_SIG": 1,
|
|
|
|
}
|
|
|
|
)
|
2020-02-06 18:12:33 +03:00
|
|
|
|
|
|
|
|
2020-06-18 09:11:42 +03:00
|
|
|
def node_height_at_least(node, h):
|
|
|
|
if (max([h.height for h in node.blockchain.get_current_tips()])) >= h:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2020-02-06 18:12:33 +03:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def event_loop():
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
yield loop
|
|
|
|
|
|
|
|
|
|
|
|
class TestSimulation:
|
2020-02-07 03:01:18 +03:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
async def simulation(self):
|
2020-07-19 03:35:43 +03:00
|
|
|
async for _ in setup_full_system(test_constants):
|
2020-02-07 03:01:18 +03:00
|
|
|
yield _
|
|
|
|
|
2020-02-06 18:12:33 +03:00
|
|
|
@pytest.mark.asyncio
|
2020-02-07 03:01:18 +03:00
|
|
|
async def test_simulation_1(self, simulation):
|
2020-06-11 23:08:30 +03:00
|
|
|
node1, node2, _, _, _, _, _, _, _ = simulation
|
2020-06-17 02:46:51 +03:00
|
|
|
|
2020-06-18 09:11:42 +03:00
|
|
|
# Use node2 to test node communication, since only node1 extends the chain.
|
2020-07-13 19:40:32 +03:00
|
|
|
await time_out_assert(500, node_height_at_least, True, node2, 10)
|
2020-06-11 17:56:59 +03:00
|
|
|
|
|
|
|
# Wait additional 2 minutes to get a compact block.
|
2020-06-18 09:11:42 +03:00
|
|
|
max_height = node1.blockchain.lca_block.height
|
|
|
|
|
2020-06-18 10:09:34 +03:00
|
|
|
async def has_compact(node1, node2, max_height):
|
2020-06-11 17:56:59 +03:00
|
|
|
for h in range(1, max_height):
|
|
|
|
blocks_1: List[FullBlock] = await node1.block_store.get_blocks_at(
|
|
|
|
[uint32(h)]
|
|
|
|
)
|
|
|
|
blocks_2: List[FullBlock] = await node2.block_store.get_blocks_at(
|
|
|
|
[uint32(h)]
|
|
|
|
)
|
|
|
|
has_compact_1 = False
|
|
|
|
has_compact_2 = False
|
|
|
|
for block in blocks_1:
|
2020-06-17 02:46:51 +03:00
|
|
|
assert block.proof_of_time is not None
|
2020-06-11 17:56:59 +03:00
|
|
|
if block.proof_of_time.witness_type == 0:
|
|
|
|
has_compact_1 = True
|
|
|
|
break
|
|
|
|
for block in blocks_2:
|
2020-06-17 02:46:51 +03:00
|
|
|
assert block.proof_of_time is not None
|
2020-06-11 17:56:59 +03:00
|
|
|
if block.proof_of_time.witness_type == 0:
|
|
|
|
has_compact_2 = True
|
|
|
|
break
|
2020-06-18 10:09:34 +03:00
|
|
|
if has_compact_1 and has_compact_2:
|
|
|
|
return True
|
2020-06-18 09:11:42 +03:00
|
|
|
return True
|
|
|
|
|
2020-06-18 09:35:13 +03:00
|
|
|
await time_out_assert_custom_interval(
|
2020-06-18 10:09:34 +03:00
|
|
|
120, 2, has_compact, True, node1, node2, max_height
|
2020-06-18 09:35:13 +03:00
|
|
|
)
|