mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-17 16:06:28 +10:00
Merge branch 'main' into fix/linux-ble-pairing-flow
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/models/companion_radio_stats.dart';
|
||||
|
||||
void main() {
|
||||
test('CompanionRadioStats.tryParse golden 14-byte radio frame', () {
|
||||
// noise -90 (0xA6FF LE), rssi -70 (0xBA), snr raw 8 -> 2.0 dB,
|
||||
// tx_air 1000 LE, rx_air 2000 LE
|
||||
final frame = Uint8List.fromList([
|
||||
respCodeStats,
|
||||
statsTypeRadio,
|
||||
0xA6,
|
||||
0xFF,
|
||||
0xBA,
|
||||
0x08,
|
||||
0xE8,
|
||||
0x03,
|
||||
0x00,
|
||||
0x00,
|
||||
0xD0,
|
||||
0x07,
|
||||
0x00,
|
||||
0x00,
|
||||
]);
|
||||
final s = CompanionRadioStats.tryParse(frame);
|
||||
expect(s, isNotNull);
|
||||
expect(s!.noiseFloorDbm, -90);
|
||||
expect(s.lastRssiDbm, -70);
|
||||
expect(s.lastSnrDb, 2.0);
|
||||
expect(s.txAirSecs, 1000);
|
||||
expect(s.rxAirSecs, 2000);
|
||||
});
|
||||
|
||||
test('CompanionRadioStats.tryParse rejects short frame', () {
|
||||
expect(CompanionRadioStats.tryParse(Uint8List(10)), isNull);
|
||||
});
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
|
||||
/// Replicates the SHA-256 computation from [MessageRetryService.computeExpectedAckHash]
|
||||
/// so tests can cross-check without calling the real implementation twice.
|
||||
Uint8List _manualAckHash(
|
||||
int _manualAckHash(
|
||||
int timestampSeconds,
|
||||
int attemptMasked, // already masked to 0x03
|
||||
String text,
|
||||
@@ -35,7 +35,8 @@ Uint8List _manualAckHash(
|
||||
buffer.setRange(offset, offset + senderPubKey.length, senderPubKey);
|
||||
|
||||
final hash = sha256.convert(buffer);
|
||||
return Uint8List.fromList(hash.bytes.sublist(0, 4));
|
||||
final bytes = Uint8List.fromList(hash.bytes.sublist(0, 4));
|
||||
return (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
|
||||
}
|
||||
|
||||
Uint8List _makeKey(int seed) {
|
||||
@@ -169,16 +170,6 @@ void main() {
|
||||
expect(first, equals(second));
|
||||
});
|
||||
|
||||
test('hash is exactly 4 bytes long', () {
|
||||
final hash = MessageRetryService.computeExpectedAckHash(
|
||||
fixedTs,
|
||||
0,
|
||||
fixedText,
|
||||
fixedKey,
|
||||
);
|
||||
expect(hash.length, equals(4));
|
||||
});
|
||||
|
||||
test('hash matches manual SHA-256 computation', () {
|
||||
for (int attempt = 0; attempt < 4; attempt++) {
|
||||
final actual = MessageRetryService.computeExpectedAckHash(
|
||||
@@ -509,7 +500,7 @@ void main() {
|
||||
fixedText,
|
||||
fixedKey,
|
||||
);
|
||||
final hex = hash.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
||||
final hex = hash.toRadixString(16).padLeft(8, '0');
|
||||
expect(
|
||||
hashes.containsKey(hex),
|
||||
isFalse,
|
||||
|
||||
Reference in New Issue
Block a user