Merge branch 'dev' into feat/dns-node-banner
This commit is contained in:
50 files changed
+3085
-731
No files matched your search
@@ -65,7 +65,12 @@ void main() {
|
||||
waitForReply: true,
|
||||
);
|
||||
queue.takeErr(6);
|
||||
await expectLater(pending!.completer!.future, throwsException);
|
||||
await expectLater(
|
||||
pending!.completer!.future,
|
||||
throwsA(
|
||||
isA<FirmwareCommandException>().having((e) => e.errCode, 'errCode', 6),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('timed-out entries', () {
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/storage/contact_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Future<void> _waitFor(bool Function() condition, {int seconds = 8}) async {
|
||||
final end = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!condition()) {
|
||||
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
}
|
||||
|
||||
/// Review radio that records every frame the app sends.
|
||||
class _RecordingReviewRadio extends ReviewRadio {
|
||||
final List<Uint8List> sent = [];
|
||||
|
||||
_RecordingReviewRadio()
|
||||
: super(scheduledMessageInterval: const Duration(hours: 1));
|
||||
|
||||
@override
|
||||
void handle(Uint8List frame) {
|
||||
sent.add(frame);
|
||||
super.handle(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
test('removed contact stays gone from the radio, list and store', () async {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
final retryService = MessageRetryService();
|
||||
addTearDown(retryService.dispose);
|
||||
connector.initialize(
|
||||
retryService: retryService,
|
||||
pathHistoryService: PathHistoryService(StorageService()),
|
||||
);
|
||||
final radio = _RecordingReviewRadio();
|
||||
connector.reviewRadioFactoryForTest = () => radio;
|
||||
|
||||
await connector.connectReview();
|
||||
await _waitFor(
|
||||
() => connector.hasLoadedContacts && connector.contacts.length >= 6,
|
||||
);
|
||||
final contact = connector.contacts.firstWhere((c) => c.name == 'Maya');
|
||||
|
||||
await connector.removeContact(contact);
|
||||
|
||||
bool listed() =>
|
||||
connector.contacts.any((c) => c.publicKeyHex == contact.publicKeyHex);
|
||||
expect(listed(), isFalse);
|
||||
expect(
|
||||
connector.discoveredContacts
|
||||
.firstWhere((c) => c.publicKeyHex == contact.publicKeyHex)
|
||||
.isActive,
|
||||
isFalse,
|
||||
);
|
||||
|
||||
// A full resync from the radio must not bring it back.
|
||||
await connector.getContacts();
|
||||
await _waitFor(() => connector.hasLoadedContacts);
|
||||
expect(connector.contacts, isNotEmpty);
|
||||
expect(listed(), isFalse);
|
||||
|
||||
final store = ContactStore()..setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
final saved = await store.loadContacts();
|
||||
expect(saved.any((c) => c.publicKeyHex == contact.publicKeyHex), isFalse);
|
||||
|
||||
// An open chat/repeater screen still syncs the path before each send, and
|
||||
// the favourite toggle writes flags. On firmware CMD_ADD_UPDATE_CONTACT
|
||||
// adds unknown keys, so neither may be sent for the removed contact.
|
||||
radio.sent.clear();
|
||||
await connector.setContactPath(contact, Uint8List.fromList([0x42]), 1);
|
||||
await connector.preparePathForContactSend(contact);
|
||||
await connector.setContactFlags(contact, isFavorite: true);
|
||||
expect(radio.sent.where((f) => f.first == cmdAddUpdateContact), isEmpty);
|
||||
|
||||
await connector.disconnect(manual: true);
|
||||
});
|
||||
|
||||
test('auto-add config reports which contact types come back', () {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
connector.handleFrameForTest([respCodeAutoAddConfig, autoAddRepeaterFlag]);
|
||||
|
||||
expect(connector.autoAddsContactType(advTypeRepeater), isTrue);
|
||||
expect(connector.autoAddsContactType(advTypeChat), isFalse);
|
||||
expect(connector.autoAddsContactType(advTypeRoom), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
|
||||
Contact _contact(List<int> key) => Contact(
|
||||
publicKey: Uint8List.fromList(key),
|
||||
name: 'Node',
|
||||
type: advTypeChat,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
);
|
||||
|
||||
void main() {
|
||||
final contact = _contact([0xA3, 0x0F, 0xB2, 0x44]);
|
||||
|
||||
test('formats the first pathHashByteWidth bytes as uppercase hex', () {
|
||||
expect(contact.publicKeyPrefixHex(1), 'A3');
|
||||
expect(contact.publicKeyPrefixHex(2), 'A30F');
|
||||
expect(contact.publicKeyPrefixHex(3), 'A30FB2');
|
||||
});
|
||||
|
||||
test('clamps width to the supported 1-3 range', () {
|
||||
expect(contact.publicKeyPrefixHex(0), 'A3');
|
||||
expect(contact.publicKeyPrefixHex(4), 'A30FB2');
|
||||
});
|
||||
|
||||
test('handles keys shorter than the width', () {
|
||||
expect(_contact([0x01]).publicKeyPrefixHex(3), '01');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:meshcore_open/models/map_path_trace_draft.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
|
||||
void main() {
|
||||
test('draft survives on the shared view state service', () {
|
||||
final service = UiViewStateService();
|
||||
final draft = service.mapPathTrace
|
||||
..active = true
|
||||
..returnPath = false;
|
||||
draft.pathBytes.addAll([0xAB, 0xCD]);
|
||||
draft.points.add(const LatLng(1, 2));
|
||||
|
||||
expect(identical(service.mapPathTrace, draft), isTrue);
|
||||
expect(service.mapPathTrace.hasHops, isTrue);
|
||||
expect(service.mapPathTrace.returnPath, isFalse);
|
||||
});
|
||||
|
||||
test('clear drops hops and the last result but keeps the mode', () {
|
||||
final draft = MapPathTraceDraft()
|
||||
..returnPath = false
|
||||
..lastResultFrame = Uint8List.fromList([1, 2, 3]);
|
||||
draft.pathBytes.add(0xAB);
|
||||
draft.hopWidths.add(1);
|
||||
draft.points.add(const LatLng(1, 2));
|
||||
|
||||
draft.clear();
|
||||
|
||||
expect(draft.hasHops, isFalse);
|
||||
expect(draft.hopWidths, isEmpty);
|
||||
expect(draft.points, isEmpty);
|
||||
expect(draft.lastResultFrame, isNull);
|
||||
expect(draft.returnPath, isFalse);
|
||||
});
|
||||
|
||||
test('belongsTo matches only the radio it was built on', () {
|
||||
final draft = MapPathTraceDraft();
|
||||
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
|
||||
draft.radioKey = Uint8List.fromList([1, 2]);
|
||||
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
|
||||
expect(draft.belongsTo(Uint8List.fromList([3, 4])), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/screens/map_screen.dart';
|
||||
import 'package:meshcore_open/helpers/marker_message.dart';
|
||||
|
||||
void main() {
|
||||
test('parseMarkerText accepts in-range coordinates', () {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/gif_helper.dart';
|
||||
import 'package:meshcore_open/helpers/reaction_helper.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
import 'package:meshcore_open/services/received_image_store.dart';
|
||||
import 'package:meshcore_open/widgets/marker_label_dialog.dart';
|
||||
|
||||
void main() {
|
||||
final l10n = lookupAppLocalizations(const Locale('en'));
|
||||
String format(String text) =>
|
||||
NotificationService.formatNotificationText(text, l10n);
|
||||
|
||||
test('shared locations show a summary instead of coordinates', () {
|
||||
expect(
|
||||
format(formatMarkerText(45.5, -122.6, 'Camp', 'poi')),
|
||||
'Shared a location: Camp',
|
||||
);
|
||||
expect(
|
||||
format(formatMarkerText(45.5, -122.6, '', 'poi')),
|
||||
'Shared a location',
|
||||
);
|
||||
});
|
||||
|
||||
test('reactions, GIFs and images are summarized', () {
|
||||
expect(
|
||||
format(ReactionHelper.encodeReaction('ab12', '00')),
|
||||
startsWith('Reacted '),
|
||||
);
|
||||
expect(format('👍\nabcd2345'), 'Reacted 👍');
|
||||
expect(format(GifHelper.encodeGif('xT9IgG50Fb7Mi0prBC')), 'Sent a GIF');
|
||||
expect(
|
||||
format('https://media.giphy.com/media/xT9IgG50Fb7Mi0prBC/giphy.gif'),
|
||||
'Sent a GIF',
|
||||
);
|
||||
expect(format(ReceivedImageRef.encode('0a1b2c3d4e5f60')), 'Sent an image');
|
||||
});
|
||||
|
||||
test('plain text is unchanged', () {
|
||||
expect(format('see you at m:ain street'), 'see you at m:ain street');
|
||||
expect(format('hello'), 'hello');
|
||||
});
|
||||
}
|
||||
@@ -61,30 +61,34 @@ int _readIntOption(Socket socket, int level, int option) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('connect enables TCP keepalive with short probe timings', () async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final overrides = _CapturingConnectOverrides();
|
||||
final service = TcpTransportService();
|
||||
try {
|
||||
await IOOverrides.runZoned(
|
||||
() => service.connect(
|
||||
host: InternetAddress.loopbackIPv4.address,
|
||||
port: server.port,
|
||||
),
|
||||
socketConnect: overrides.socketConnect,
|
||||
);
|
||||
final socket = overrides.socket!;
|
||||
// Linux values: SO_KEEPALIVE 9, TCP_KEEPIDLE 4, TCP_KEEPINTVL 5,
|
||||
// TCP_KEEPCNT 6.
|
||||
expect(_readIntOption(socket, RawSocketOption.levelSocket, 9), 1);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 4), 30);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 5), 10);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 6), 3);
|
||||
} finally {
|
||||
await service.disconnect();
|
||||
await server.close();
|
||||
}
|
||||
}, skip: Platform.isLinux ? false : 'Option numbers checked are Linux ones');
|
||||
test(
|
||||
'connect enables TCP keepalive with short probe timings',
|
||||
() async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final overrides = _CapturingConnectOverrides();
|
||||
final service = TcpTransportService();
|
||||
try {
|
||||
await IOOverrides.runZoned(
|
||||
() => service.connect(
|
||||
host: InternetAddress.loopbackIPv4.address,
|
||||
port: server.port,
|
||||
),
|
||||
socketConnect: overrides.socketConnect,
|
||||
);
|
||||
final socket = overrides.socket!;
|
||||
// Linux values: SO_KEEPALIVE 9, TCP_KEEPIDLE 4, TCP_KEEPINTVL 5,
|
||||
// TCP_KEEPCNT 6.
|
||||
expect(_readIntOption(socket, RawSocketOption.levelSocket, 9), 1);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 4), 30);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 5), 10);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 6), 3);
|
||||
} finally {
|
||||
await service.disconnect();
|
||||
await server.close();
|
||||
}
|
||||
},
|
||||
skip: Platform.isLinux ? false : 'Option numbers checked are Linux ones',
|
||||
);
|
||||
|
||||
test('connect/disconnect updates TCP transport state', () async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
|
||||
Reference in new issue
Block a user