public Account updatePniKeys(final Account account,
      final IdentityKey pniIdentityKey,
      final Map<Byte, ECSignedPreKey> pniSignedPreKeys,
      @Nullable final Map<Byte, KEMSignedPreKey> pniPqLastResortPreKeys,
      final Map<Byte, Integer> pniRegistrationIds) throws MismatchedDevicesException {

    validateDevices(account, pniSignedPreKeys, pniPqLastResortPreKeys, pniRegistrationIds);

    final UUID aci = account.getIdentifier(IdentityType.ACI);
    final UUID pni = account.getIdentifier(IdentityType.PNI);

    final Collection<TransactWriteItem> keyWriteItems =
        buildPniKeyWriteItems(pni, pni, pniSignedPreKeys, pniPqLastResortPreKeys);

    return redisDeleteAsync(account)
        .thenCompose(ignored -> keysManager.deleteSingleUsePreKeys(pni))
        .thenCompose(ignored -> updateTransactionallyWithRetriesAsync(account,
            a -> setPniKeys(a, pniIdentityKey, pniRegistrationIds),
            accounts::updateTransactionallyAsync,
            () -> accounts.getByAccountIdentifierAsync(aci).thenApply(Optional::orElseThrow),
            a -> keyWriteItems,
            AccountChangeValidator.GENERAL_CHANGE_VALIDATOR,
            MAX_UPDATE_ATTEMPTS))
        .join();
  }
@Test
  void testPniPqUpdate_incompleteKeys() {
    final String number = "+14152222222";
    final byte deviceId2 = 2;
    List<Device> devices = List.of(DevicesHelper.createDevice(Device.PRIMARY_ID, 0L, 101),
        DevicesHelper.createDevice(deviceId2, 0L, 102));
    Account account = AccountsHelper.generateTestAccount(number, UUID.randomUUID(), UUID.randomUUID(), devices, new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH]);
    final ECKeyPair identityKeyPair = Curve.generateKeyPair();
    final Map<Byte, ECSignedPreKey> newSignedKeys = Map.of(
        Device.PRIMARY_ID, KeysHelper.signedECPreKey(1, identityKeyPair),
        deviceId2, KeysHelper.signedECPreKey(2, identityKeyPair));
    final Map<Byte, KEMSignedPreKey> newSignedPqKeys = Map.of(
        Device.PRIMARY_ID, KeysHelper.signedKEMPreKey(3, identityKeyPair));
    Map<Byte, Integer> newRegistrationIds = Map.of(Device.PRIMARY_ID, 201, deviceId2, 202);

    final IdentityKey pniIdentityKey = new IdentityKey(Curve.generateKeyPair().getPublicKey());

    assertThrows(MismatchedDevicesException.class,
        () -> accountsManager.updatePniKeys(account, pniIdentityKey, newSignedKeys, newSignedPqKeys, newRegistrationIds));

    verifyNoInteractions(accounts);
    verifyNoInteractions(keysManager);
  }