def test_fernet_keyshare():
    rounds = ManualGameSequencer([InsecureOrderedClient, FernetKeyshareClient])
    x = start_async_rounds(rounds, 3)
    assert x[0]['shared_fernet_key_params'] is not None
    assert all([
        y['shared_fernet_key_params'] == x[0]['shared_fernet_key_params']
        for y in x
    ])
def test_secure_deck_shuffling():
    rounds = ManualGameSequencer(
        [DeckShuffleClient, SecureShuffleSampleDecryptor])
    x = start_async_rounds(rounds, 3)
    deck_states = []
    for client in x:
        deck_states.append(client.get(PokerWords.DECK_STATE))
    assert deck_states[0] != list(range(10, 62))
    assert sorted(deck_states[0]) == list(range(10, 62))
    assert (all(d == deck_states[0] for d in deck_states))
def test_RSA_keys_match_three_way():
    rounds = ManualGameSequencer([RSAKeyShareClient])
    x = start_async_rounds(rounds, 3)
    # For each client's state, extract it's own pubkey and ident as [(pk, id)]
    actual_pubkeys = [(y['ident'], y['pubkey']) for y in x]
    # Extract each player's list of external public keys
    playerlists = [y['playerlist'] for y in x]

    assert playerlists is not None
    assert actual_pubkeys is not None

    # Assert that all players lists of public keys match the actual values
    for player in playerlists:
        for pk_entry in player:
            assert pk_entry in actual_pubkeys
def test_secure_player_ordering():
    rounds = ManualGameSequencer([InsecureOrderedClient, PlayerShuffleClient])
    start_async_rounds(rounds, 3)
def test_shuffling_client():
    rounds = ManualGameSequencer([ShufflingClient])
    x = start_async_rounds(rounds, 3)
    decks = [y['deck'] for y in x]
    assert (all(d == decks[0] for d in decks))
    assert (all(d != list(range(10)) for d in decks))
def test_insecure_ordering():
    """Assert that all clients produce the same ordering"""
    rounds = ManualGameSequencer([InsecureOrderedClient])
    x = start_async_rounds(rounds, 3)
    peermaps = [y['peer_map'] for y in x]
    assert all(x == peermaps[0] for x in peermaps)
def test_greeting_client():
    rounds = ManualGameSequencer([GreetingCli])
    x = start_async_rounds(rounds, 3)
    assert [y.get('greetings_sent') for y in x] == [2, 1, 0]
def test_card_reveal_client():
    rounds = ManualGameSequencer([DeckShuffleClient, CardRevealClient])
    x = start_async_rounds(rounds, 3)
    for state in x:
        if state['crypto_deck_state'][0].locks_present is []:
            assert state['crypto_deck_state'][0].value in range(10, 62)