refactor: port client and related tests to nullsafety

This commit is contained in:
Nicolas Werner 2021-10-28 03:01:19 +02:00
parent 3f83e5481c
commit 32c6e0ec6e
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
4 changed files with 100 additions and 89 deletions

View File

@ -1,4 +1,3 @@
// @dart=2.9
/* /*
* Famedly Matrix SDK * Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH * Copyright (C) 2019, 2020 Famedly GmbH
@ -35,7 +34,7 @@ import 'fake_database.dart';
import 'fake_matrix_api.dart'; import 'fake_matrix_api.dart';
void main() { void main() {
Client matrix; late Client matrix;
Future<List<EventUpdate>> eventUpdateListFuture; Future<List<EventUpdate>> eventUpdateListFuture;
Future<List<ToDeviceEvent>> toDeviceUpdateListFuture; Future<List<ToDeviceEvent>> toDeviceUpdateListFuture;
@ -128,7 +127,7 @@ void main() {
expect(matrix.getDirectChatFromUserId('@bob:example.com'), expect(matrix.getDirectChatFromUserId('@bob:example.com'),
'!726s6s6q:example.com'); '!726s6s6q:example.com');
expect(matrix.rooms[1].directChatMatrixID, '@bob:example.com'); expect(matrix.rooms[1].directChatMatrixID, '@bob:example.com');
expect(matrix.directChats, matrix.accountData['m.direct'].content); expect(matrix.directChats, matrix.accountData['m.direct']?.content);
expect(matrix.presences.length, 1); expect(matrix.presences.length, 1);
expect(matrix.rooms[1].ephemerals.length, 2); expect(matrix.rooms[1].ephemerals.length, 2);
expect(matrix.rooms[1].typingUsers.length, 1); expect(matrix.rooms[1].typingUsers.length, 1);
@ -139,29 +138,30 @@ void main() {
Client.supportedGroupEncryptionAlgorithms.first); Client.supportedGroupEncryptionAlgorithms.first);
expect( expect(
matrix.rooms[1].roomAccountData['m.receipt'] matrix.rooms[1].roomAccountData['m.receipt']
.content['@alice:example.com']['ts'], ?.content['@alice:example.com']['ts'],
1436451550453); 1436451550453);
expect( expect(
matrix.rooms[1].roomAccountData['m.receipt'] matrix.rooms[1].roomAccountData['m.receipt']
.content['@alice:example.com']['event_id'], ?.content['@alice:example.com']['event_id'],
'7365636s6r6432:example.com'); '7365636s6r6432:example.com');
expect(matrix.rooms.length, 2); expect(matrix.rooms.length, 2);
expect(matrix.rooms[1].canonicalAlias, expect(matrix.rooms[1].canonicalAlias,
"#famedlyContactDiscovery:${matrix.userID.split(":")[1]}"); "#famedlyContactDiscovery:${matrix.userID!.split(":")[1]}");
expect(matrix.presences['@alice:example.com'].presence.presence, expect(matrix.presences['@alice:example.com']?.presence.presence,
PresenceType.online); PresenceType.online);
expect(presenceCounter, 1); expect(presenceCounter, 1);
expect(accountDataCounter, 9); expect(accountDataCounter, 9);
await Future.delayed(Duration(milliseconds: 50)); await Future.delayed(Duration(milliseconds: 50));
expect(matrix.userDeviceKeys.length, 4); expect(matrix.userDeviceKeys.length, 4);
expect(matrix.userDeviceKeys['@alice:example.com'].outdated, false); expect(matrix.userDeviceKeys['@alice:example.com']?.outdated, false);
expect(matrix.userDeviceKeys['@alice:example.com'].deviceKeys.length, 2); expect(matrix.userDeviceKeys['@alice:example.com']?.deviceKeys.length, 2);
expect( expect(
matrix.userDeviceKeys['@alice:example.com'].deviceKeys['JLAFKJWSCS'] matrix.userDeviceKeys['@alice:example.com']?.deviceKeys['JLAFKJWSCS']
.verified, ?.verified,
false); false);
await matrix.handleSync(SyncUpdate.fromJson({ await matrix.handleSync(SyncUpdate.fromJson({
'next_batch': 'fakesync',
'device_lists': { 'device_lists': {
'changed': [ 'changed': [
'@alice:example.com', '@alice:example.com',
@ -173,9 +173,10 @@ void main() {
})); }));
await Future.delayed(Duration(milliseconds: 50)); await Future.delayed(Duration(milliseconds: 50));
expect(matrix.userDeviceKeys.length, 3); expect(matrix.userDeviceKeys.length, 3);
expect(matrix.userDeviceKeys['@alice:example.com'].outdated, true); expect(matrix.userDeviceKeys['@alice:example.com']?.outdated, true);
await matrix.handleSync(SyncUpdate.fromJson({ await matrix.handleSync(SyncUpdate.fromJson({
'next_batch': 'fakesync',
'rooms': { 'rooms': {
'join': { 'join': {
'!726s6s6q:example.com': { '!726s6s6q:example.com': {
@ -199,7 +200,7 @@ void main() {
expect( expect(
matrix.getRoomByAlias( matrix.getRoomByAlias(
"#famedlyContactDiscovery:${matrix.userID.split(":")[1]}"), "#famedlyContactDiscovery:${matrix.userID!.split(":")[1]}"),
null); null);
}); });
@ -340,7 +341,7 @@ void main() {
expect(archive[0].id, '!5345234234:example.com'); expect(archive[0].id, '!5345234234:example.com');
expect(archive[0].membership, Membership.leave); expect(archive[0].membership, Membership.leave);
expect(archive[0].name, 'The room name'); expect(archive[0].name, 'The room name');
expect(archive[0].lastEvent.body, 'This is an example text message'); expect(archive[0].lastEvent?.body, 'This is an example text message');
expect(archive[0].roomAccountData.length, 1); expect(archive[0].roomAccountData.length, 1);
expect(archive[1].id, '!5345234235:example.com'); expect(archive[1].id, '!5345234235:example.com');
expect(archive[1].membership, Membership.leave); expect(archive[1].membership, Membership.leave);
@ -364,7 +365,7 @@ void main() {
} }
FakeMatrixApi.calledEndpoints.clear(); FakeMatrixApi.calledEndpoints.clear();
await matrix.sendToDeviceEncrypted( await matrix.sendToDeviceEncrypted(
matrix.userDeviceKeys['@alice:example.com'].deviceKeys.values matrix.userDeviceKeys['@alice:example.com']!.deviceKeys.values
.toList(), .toList(),
'm.message', 'm.message',
{ {
@ -382,7 +383,7 @@ void main() {
} }
FakeMatrixApi.calledEndpoints.clear(); FakeMatrixApi.calledEndpoints.clear();
await matrix.sendToDeviceEncryptedChunked( await matrix.sendToDeviceEncryptedChunked(
matrix.userDeviceKeys['@alice:example.com'].deviceKeys.values matrix.userDeviceKeys['@alice:example.com']!.deviceKeys.values
.toList(), .toList(),
'm.message', 'm.message',
{ {
@ -483,11 +484,11 @@ void main() {
expect( expect(
json.decode(FakeMatrixApi json.decode(FakeMatrixApi
.calledEndpoints['/client/r0/sendToDevice/foxies/floof_txnid'] .calledEndpoints['/client/r0/sendToDevice/foxies/floof_txnid']
[0])['messages'], ?[0])['messages'],
foxContent); foxContent);
expect( expect(
json.decode(FakeMatrixApi.calledEndpoints[ json.decode(FakeMatrixApi.calledEndpoints[
'/client/r0/sendToDevice/raccoon/raccoon_txnid'][0])['messages'], '/client/r0/sendToDevice/raccoon/raccoon_txnid']?[0])['messages'],
raccoonContent); raccoonContent);
FakeMatrixApi.calledEndpoints.clear(); FakeMatrixApi.calledEndpoints.clear();
await client.sendToDevice('bunny', 'bunny_txnid', bunnyContent); await client.sendToDevice('bunny', 'bunny_txnid', bunnyContent);
@ -502,7 +503,7 @@ void main() {
expect( expect(
json.decode(FakeMatrixApi json.decode(FakeMatrixApi
.calledEndpoints['/client/r0/sendToDevice/bunny/bunny_txnid'] .calledEndpoints['/client/r0/sendToDevice/bunny/bunny_txnid']
[0])['messages'], ?[0])['messages'],
bunnyContent); bunnyContent);
await client.dispose(closeDatabase: true); await client.dispose(closeDatabase: true);
}); });
@ -546,16 +547,16 @@ void main() {
expect( expect(
json.decode(FakeMatrixApi json.decode(FakeMatrixApi
.calledEndpoints['/client/r0/sendToDevice/foxies/floof_txnid'] .calledEndpoints['/client/r0/sendToDevice/foxies/floof_txnid']
[0])['messages'], ?[0])['messages'],
foxContent); foxContent);
expect( expect(
json.decode(FakeMatrixApi.calledEndpoints[ json.decode(FakeMatrixApi.calledEndpoints[
'/client/r0/sendToDevice/raccoon/raccoon_txnid'][0])['messages'], '/client/r0/sendToDevice/raccoon/raccoon_txnid']?[0])['messages'],
raccoonContent); raccoonContent);
expect( expect(
json.decode(FakeMatrixApi json.decode(FakeMatrixApi
.calledEndpoints['/client/r0/sendToDevice/bunny/bunny_txnid'] .calledEndpoints['/client/r0/sendToDevice/bunny/bunny_txnid']
[0])['messages'], ?[0])['messages'],
bunnyContent); bunnyContent);
await client.dispose(closeDatabase: true); await client.dispose(closeDatabase: true);
}); });
@ -598,9 +599,10 @@ void main() {
expect(client2.deviceName, client1.deviceName); expect(client2.deviceName, client1.deviceName);
expect(client2.rooms.length, 2); expect(client2.rooms.length, 2);
if (client2.encryptionEnabled) { if (client2.encryptionEnabled) {
expect(client2.encryption.fingerprintKey, expect(client2.encryption?.fingerprintKey,
client1.encryption.fingerprintKey); client1.encryption?.fingerprintKey);
expect(client2.encryption.identityKey, client1.encryption.identityKey); expect(
client2.encryption?.identityKey, client1.encryption?.identityKey);
expect(client2.rooms[1].id, client1.rooms[1].id); expect(client2.rooms[1].id, client1.rooms[1].id);
} }
@ -629,16 +631,18 @@ void main() {
final response = final response =
await client.uploadContent(Uint8List(0), filename: 'file.jpeg'); await client.uploadContent(Uint8List(0), filename: 'file.jpeg');
expect(response.toString(), 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'); expect(response.toString(), 'mxc://example.com/AQwafuaFswefuhsfAFAgsw');
expect(await client.database.getFile(response) != null, expect(await client.database?.getFile(response) != null,
client.database.supportsFileStoring); client.database?.supportsFileStoring);
await client.dispose(closeDatabase: true); await client.dispose(closeDatabase: true);
}); });
test('object equality', () async { test('object equality', () async {
final time1 = DateTime.fromMillisecondsSinceEpoch(1); final time1 = DateTime.fromMillisecondsSinceEpoch(1);
final time2 = DateTime.fromMillisecondsSinceEpoch(0); final time2 = DateTime.fromMillisecondsSinceEpoch(0);
final user1 = User('@user1:example.org', room: Room(id: '!room1')); final user1 =
final user2 = User('@user2:example.org', room: Room(id: '!room1')); User('@user1:example.org', room: Room(id: '!room1', client: matrix));
final user2 =
User('@user2:example.org', room: Room(id: '!room1', client: matrix));
// receipts // receipts
expect(Receipt(user1, time1) == Receipt(user1, time1), true); expect(Receipt(user1, time1) == Receipt(user1, time1), true);
expect(Receipt(user1, time1) == Receipt(user1, time2), false); expect(Receipt(user1, time1) == Receipt(user1, time2), false);
@ -649,19 +653,29 @@ void main() {
expect(user1 == user1, true); expect(user1 == user1, true);
expect(user1 == user2, false); expect(user1 == user2, false);
expect( expect(
user1 == User('@user1:example.org', room: Room(id: '!room2')), false); user1 ==
User('@user1:example.org',
room: Room(id: '!room2', client: matrix)),
false);
expect( expect(
user1 == user1 ==
User('@user1:example.org', User('@user1:example.org',
room: Room(id: '!room1'), membership: 'leave'), room: Room(id: '!room1', client: matrix),
membership: 'leave'),
false); false);
// ignore: unrelated_type_equality_checks // ignore: unrelated_type_equality_checks
expect(user1 == 'beep', false); expect(user1 == 'beep', false);
// rooms // rooms
expect(Room(id: '!room1') == Room(id: '!room1'), true); expect(
expect(Room(id: '!room1') == Room(id: '!room2'), false); Room(id: '!room1', client: matrix) ==
Room(id: '!room1', client: matrix),
true);
expect(
Room(id: '!room1', client: matrix) ==
Room(id: '!room2', client: matrix),
false);
// ignore: unrelated_type_equality_checks // ignore: unrelated_type_equality_checks
expect(Room(id: '!room1') == 'beep', false); expect(Room(id: '!room1', client: matrix) == 'beep', false);
}); });
test('clearCache', () async { test('clearCache', () async {

View File

@ -1,4 +1,3 @@
// @dart=2.9
/* /*
* Famedly Matrix SDK * Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH * Copyright (C) 2019, 2020 Famedly GmbH
@ -34,7 +33,7 @@ void main() {
var olmEnabled = true; var olmEnabled = true;
Client client; late Client client;
test('setupClient', () async { test('setupClient', () async {
try { try {
@ -135,8 +134,8 @@ void main() {
test('set blocked / verified', () async { test('set blocked / verified', () async {
if (!olmEnabled) return; if (!olmEnabled) return;
final key = final key =
client.userDeviceKeys[client.userID].deviceKeys['OTHERDEVICE']; client.userDeviceKeys[client.userID]!.deviceKeys['OTHERDEVICE']!;
client.userDeviceKeys[client.userID].deviceKeys['UNSIGNEDDEVICE'] = client.userDeviceKeys[client.userID]?.deviceKeys['UNSIGNEDDEVICE'] =
DeviceKeys.fromJson({ DeviceKeys.fromJson({
'user_id': '@test:fakeServer.notExisting', 'user_id': '@test:fakeServer.notExisting',
'device_id': 'UNSIGNEDDEVICE', 'device_id': 'UNSIGNEDDEVICE',
@ -157,10 +156,10 @@ void main() {
}, },
}, },
}, client); }, client);
final masterKey = client.userDeviceKeys[client.userID].masterKey; final masterKey = client.userDeviceKeys[client.userID]!.masterKey!;
masterKey.setDirectVerified(true); masterKey.setDirectVerified(true);
// we need to populate the ssss cache to be able to test signing easily // we need to populate the ssss cache to be able to test signing easily
final handle = client.encryption.ssss.open(); final handle = client.encryption!.ssss.open();
await handle.unlock(recoveryKey: ssssKey); await handle.unlock(recoveryKey: ssssKey);
await handle.maybeCacheAll(); await handle.maybeCacheAll();
@ -174,16 +173,16 @@ void main() {
expect(key.verified, true); // still verified via cross-sgining expect(key.verified, true); // still verified via cross-sgining
expect(key.encryptToDevice, true); expect(key.encryptToDevice, true);
expect( expect(
client.userDeviceKeys[client.userID].deviceKeys['UNSIGNEDDEVICE'] client.userDeviceKeys[client.userID]?.deviceKeys['UNSIGNEDDEVICE']
.encryptToDevice, ?.encryptToDevice,
false); false);
expect(masterKey.verified, true); expect(masterKey.verified, true);
await masterKey.setBlocked(true); await masterKey.setBlocked(true);
expect(masterKey.verified, false); expect(masterKey.verified, false);
expect( expect(
client.userDeviceKeys[client.userID].deviceKeys['UNSIGNEDDEVICE'] client.userDeviceKeys[client.userID]?.deviceKeys['UNSIGNEDDEVICE']
.encryptToDevice, ?.encryptToDevice,
true); true);
await masterKey.setBlocked(false); await masterKey.setBlocked(false);
expect(masterKey.verified, true); expect(masterKey.verified, true);
@ -205,57 +204,57 @@ void main() {
.any((k) => k == '/client/r0/keys/signatures/upload'), .any((k) => k == '/client/r0/keys/signatures/upload'),
false); false);
expect(key.directVerified, false); expect(key.directVerified, false);
client.userDeviceKeys[client.userID].deviceKeys.remove('UNSIGNEDDEVICE'); client.userDeviceKeys[client.userID]?.deviceKeys.remove('UNSIGNEDDEVICE');
}); });
test('verification based on signatures', () async { test('verification based on signatures', () async {
if (!olmEnabled) return; if (!olmEnabled) return;
final user = client.userDeviceKeys[client.userID]; final user = client.userDeviceKeys[client.userID]!;
user.masterKey.setDirectVerified(true); user.masterKey?.setDirectVerified(true);
expect(user.deviceKeys['GHTYAJCE'].crossVerified, true); expect(user.deviceKeys['GHTYAJCE']?.crossVerified, true);
expect(user.deviceKeys['GHTYAJCE'].signed, true); expect(user.deviceKeys['GHTYAJCE']?.signed, true);
expect(user.getKey('GHTYAJCE').crossVerified, true); expect(user.getKey('GHTYAJCE')?.crossVerified, true);
expect(user.deviceKeys['OTHERDEVICE'].crossVerified, true); expect(user.deviceKeys['OTHERDEVICE']?.crossVerified, true);
expect(user.selfSigningKey.crossVerified, true); expect(user.selfSigningKey?.crossVerified, true);
expect( expect(
user user
.getKey('F9ypFzgbISXCzxQhhSnXMkc1vq12Luna3Nw5rqViOJY') .getKey('F9ypFzgbISXCzxQhhSnXMkc1vq12Luna3Nw5rqViOJY')
.crossVerified, ?.crossVerified,
true); true);
expect(user.userSigningKey.crossVerified, true); expect(user.userSigningKey?.crossVerified, true);
expect(user.verified, UserVerifiedStatus.verified); expect(user.verified, UserVerifiedStatus.verified);
user.masterKey.setDirectVerified(false); user.masterKey?.setDirectVerified(false);
expect(user.deviceKeys['GHTYAJCE'].crossVerified, false); expect(user.deviceKeys['GHTYAJCE']?.crossVerified, false);
expect(user.deviceKeys['OTHERDEVICE'].crossVerified, false); expect(user.deviceKeys['OTHERDEVICE']?.crossVerified, false);
expect(user.verified, UserVerifiedStatus.unknown); expect(user.verified, UserVerifiedStatus.unknown);
user.deviceKeys['OTHERDEVICE'].setDirectVerified(true); user.deviceKeys['OTHERDEVICE']?.setDirectVerified(true);
expect(user.verified, UserVerifiedStatus.verified); expect(user.verified, UserVerifiedStatus.verified);
user.deviceKeys['OTHERDEVICE'].setDirectVerified(false); user.deviceKeys['OTHERDEVICE']?.setDirectVerified(false);
user.masterKey.setDirectVerified(true); user.masterKey?.setDirectVerified(true);
user.deviceKeys['GHTYAJCE'].signatures[client.userID] user.deviceKeys['GHTYAJCE']?.signatures?[client.userID]
.removeWhere((k, v) => k != 'ed25519:GHTYAJCE'); ?.removeWhere((k, v) => k != 'ed25519:GHTYAJCE');
expect(user.deviceKeys['GHTYAJCE'].verified, expect(user.deviceKeys['GHTYAJCE']?.verified,
true); // it's our own device, should be direct verified true); // it's our own device, should be direct verified
expect( expect(user.deviceKeys['GHTYAJCE']?.signed,
user.deviceKeys['GHTYAJCE'].signed, false); // not verified for others false); // not verified for others
user.deviceKeys['OTHERDEVICE'].signatures.clear(); user.deviceKeys['OTHERDEVICE']?.signatures?.clear();
expect(user.verified, UserVerifiedStatus.unknownDevice); expect(user.verified, UserVerifiedStatus.unknownDevice);
}); });
test('start verification', () async { test('start verification', () async {
if (!olmEnabled) return; if (!olmEnabled) return;
var req = client var req = client
.userDeviceKeys['@alice:example.com'].deviceKeys['JLAFKJWSCS'] .userDeviceKeys['@alice:example.com']?.deviceKeys['JLAFKJWSCS']
.startVerification(); ?.startVerification();
expect(req != null, true); expect(req != null, true);
expect(req.room != null, false); expect(req?.room != null, false);
req = req = await client.userDeviceKeys['@alice:example.com']
await client.userDeviceKeys['@alice:example.com'].startVerification(); ?.startVerification();
expect(req != null, true); expect(req != null, true);
expect(req.room != null, true); expect(req?.room != null, true);
}); });
test('dispose client', () async { test('dispose client', () async {

View File

@ -1,4 +1,3 @@
// @dart=2.9
/* /*
* Famedly Matrix SDK * Famedly Matrix SDK
* Copyright (C) 2020 Famedly GmbH * Copyright (C) 2020 Famedly GmbH
@ -27,7 +26,7 @@ import 'fake_database.dart';
void main() { void main() {
group('Databse', () { group('Databse', () {
Logs().level = Level.error; Logs().level = Level.error;
final room = Room(id: '!room:blubb'); final room = Room(id: '!room:blubb', client: Client('testclient'));
test('setupDatabase', () async { test('setupDatabase', () async {
final database = await getDatabase(null); final database = await getDatabase(null);
await database.insertClient( await database.insertClient(
@ -59,7 +58,7 @@ void main() {
); );
await database.storeEventUpdate(update, client); await database.storeEventUpdate(update, client);
var event = await database.getEventById('\$event-1', room); var event = await database.getEventById('\$event-1', room);
expect(event.eventId, '\$event-1'); expect(event?.eventId, '\$event-1');
// insert a transaction id // insert a transaction id
update = EventUpdate( update = EventUpdate(
@ -76,7 +75,7 @@ void main() {
); );
await database.storeEventUpdate(update, client); await database.storeEventUpdate(update, client);
event = await database.getEventById('transaction-1', room); event = await database.getEventById('transaction-1', room);
expect(event.eventId, 'transaction-1'); expect(event?.eventId, 'transaction-1');
update = EventUpdate( update = EventUpdate(
type: EventUpdateType.timeline, type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
@ -112,7 +111,7 @@ void main() {
); );
await database.storeEventUpdate(update, client); await database.storeEventUpdate(update, client);
event = await database.getEventById('\$event-3', room); event = await database.getEventById('\$event-3', room);
expect(event.eventId, '\$event-3'); expect(event?.eventId, '\$event-3');
update = EventUpdate( update = EventUpdate(
type: EventUpdateType.timeline, type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
@ -130,8 +129,8 @@ void main() {
); );
await database.storeEventUpdate(update, client); await database.storeEventUpdate(update, client);
event = await database.getEventById('\$event-3', room); event = await database.getEventById('\$event-3', room);
expect(event.eventId, '\$event-3'); expect(event?.eventId, '\$event-3');
expect(event.status, EventStatus.sent); expect(event?.status, EventStatus.sent);
event = await database.getEventById('transaction-2', room); event = await database.getEventById('transaction-2', room);
expect(event, null); expect(event, null);
@ -150,7 +149,7 @@ void main() {
); );
await database.storeEventUpdate(update, client); await database.storeEventUpdate(update, client);
event = await database.getEventById('\$event-4', room); event = await database.getEventById('\$event-4', room);
expect(event.eventId, '\$event-4'); expect(event?.eventId, '\$event-4');
update = EventUpdate( update = EventUpdate(
type: EventUpdateType.timeline, type: EventUpdateType.timeline,
roomID: room.id, roomID: room.id,
@ -168,8 +167,8 @@ void main() {
); );
await database.storeEventUpdate(update, client); await database.storeEventUpdate(update, client);
event = await database.getEventById('\$event-4', room); event = await database.getEventById('\$event-4', room);
expect(event.eventId, '\$event-4'); expect(event?.eventId, '\$event-4');
expect(event.status, EventStatus.synced); expect(event?.status, EventStatus.synced);
event = await database.getEventById('transaction-3', room); event = await database.getEventById('transaction-3', room);
expect(event, null); expect(event, null);
}); });

View File

@ -1,4 +1,3 @@
// @dart=2.9
/* /*
* Famedly Matrix SDK * Famedly Matrix SDK
* Copyright (C) 2019, 2020 Famedly GmbH * Copyright (C) 2019, 2020 Famedly GmbH
@ -37,9 +36,9 @@ void main() {
final insertList = <int>[]; final insertList = <int>[];
var olmEnabled = true; var olmEnabled = true;
Client client; late Client client;
Room room; late Room room;
Timeline timeline; late Timeline timeline;
test('create stuff', () async { test('create stuff', () async {
try { try {
await olm.init(); await olm.init();
@ -233,18 +232,18 @@ void main() {
test('getEventById', () async { test('getEventById', () async {
var event = await timeline.getEventById('abc'); var event = await timeline.getEventById('abc');
expect(event.content, {'msgtype': 'm.text', 'body': 'Testcase'}); expect(event?.content, {'msgtype': 'm.text', 'body': 'Testcase'});
event = await timeline.getEventById('not_found'); event = await timeline.getEventById('not_found');
expect(event, null); expect(event, null);
event = await timeline.getEventById('unencrypted_event'); event = await timeline.getEventById('unencrypted_event');
expect(event.body, 'This is an example text message'); expect(event?.body, 'This is an example text message');
if (olmEnabled) { if (olmEnabled) {
event = await timeline.getEventById('encrypted_event'); event = await timeline.getEventById('encrypted_event');
// the event is invalid but should have traces of attempting to decrypt // the event is invalid but should have traces of attempting to decrypt
expect(event.messageType, MessageTypes.BadEncrypted); expect(event?.messageType, MessageTypes.BadEncrypted);
} }
}); });