Exemple #1
0
sys.path.append('lib')
import mocknet

nodes = mocknet.get_nodes()

validators = nodes[0].get_validators()['result']
validator_accounts = set(
    map(lambda v: v['account_id'], validators['current_validators']))
# Nodes 0, 1, 2, 3 are initially validators
assert validator_accounts == {'node0', 'node1', 'node2', 'node3'}

epoch_length = mocknet.get_epoch_length_in_blocks(nodes[0])

# Function to do a transfer, but not using the first node
check_transfer = lambda: mocknet.transfer_between_nodes(nodes[1:])


# Function to wait until the next epoch
def wait_until_next_epoch(current_start_height, query_node):
    while query_node.get_validators(
    )['result']['epoch_start_height'] <= current_start_height:
        time.sleep(5)


print('INFO: Starting Outage test.')

# Ensure we start the test closer to the beginning of an epoch than the end.
current_height = nodes[0].get_status()['sync_info']['latest_block_height']
if current_height > validators['epoch_start_height'] + (epoch_length / 2):
    print(
Exemple #2
0
# Stop all mocknet nodes, wait 1s, then start all nodes again.
# Nodes should be responsive again after this operation.

import sys, time
from rc import pmap

sys.path.append('lib')
import mocknet

nodes = mocknet.get_nodes()

# stop nodes
pmap(mocknet.stop_node, nodes)

# wait 1s
time.sleep(1)

# start nodes
pmap(mocknet.start_node, nodes)

# give some time to come back up
time.sleep(5)

# test network still functions
mocknet.transfer_between_nodes(nodes)
Exemple #3
0
total_stake = sum(map(lambda v: int(v['stake']), validators))
offline_validators = []
offline_stake = 0
for v in validators:
    next_stake = int(v['stake'])
    if len(offline_validators) > 0 and (offline_stake +
                                        next_stake) / total_stake >= 0.25:
        break
    offline_validators.append(v['account_id'])
    offline_stake += next_stake
first_online_index = len(offline_validators)

epoch_length = mocknet.get_epoch_length_in_blocks(nodes[0])

# Function to do a transfer, but not using the offline nodes
check_transfer = lambda: mocknet.transfer_between_nodes(nodes[
    first_online_index:])


# Function to wait until the next epoch
def wait_until_next_epoch(current_start_height, query_node):
    while query_node.get_validators(
    )['result']['epoch_start_height'] <= current_start_height:
        time.sleep(5)


logger.info('INFO: Starting Outage test.')

# Ensure we start the test closer to the beginning of an epoch than the end.
epoch_start_height = nodes[0].get_validators()['result']['epoch_start_height']
current_height = nodes[0].get_status()['sync_info']['latest_block_height']
if current_height > epoch_start_height + (epoch_length / 2):