110 lines
3.3 KiB
Dart
110 lines
3.3 KiB
Dart
|
|
@Tags(['integration'])
|
||
|
|
library;
|
||
|
|
|
||
|
|
import 'dart:convert';
|
||
|
|
|
||
|
|
import 'package:bip340/bip340.dart' as bip340;
|
||
|
|
import 'package:swarm/swarm.dart';
|
||
|
|
import 'package:test/test.dart';
|
||
|
|
|
||
|
|
const _privKey =
|
||
|
|
'0000000000000000000000000000000000000000000000000000000000000001';
|
||
|
|
|
||
|
|
const _relayUrl = 'wss://relay.otherwhere.app/';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
late NostrSignerActor signer;
|
||
|
|
late NostrPublishActor publisher;
|
||
|
|
late String pubkey;
|
||
|
|
|
||
|
|
setUp(() {
|
||
|
|
signer = NostrSignerActor(_privKey);
|
||
|
|
publisher = NostrPublishActor(relayUrls: [_relayUrl]);
|
||
|
|
pubkey = bip340.getPublicKey(_privKey);
|
||
|
|
});
|
||
|
|
|
||
|
|
Future<RelayOutcome> signAndPublish(SignEvent msg) async {
|
||
|
|
final signed = await signer.handle(msg);
|
||
|
|
final result = await publisher.handle(
|
||
|
|
PublishBatch([(signed as EventSigned).event]),
|
||
|
|
);
|
||
|
|
return (result as BatchPublished).outcomes[_relayUrl]!;
|
||
|
|
}
|
||
|
|
|
||
|
|
group('relay.otherwhere.app', () {
|
||
|
|
test('kind 0 (metadata) is confirmed', () async {
|
||
|
|
final outcome = await signAndPublish(
|
||
|
|
const SignEvent(
|
||
|
|
kind: 0,
|
||
|
|
content: '{"name":"swarm-integration-test"}',
|
||
|
|
),
|
||
|
|
);
|
||
|
|
expect(outcome, isA<RelayConfirmed>());
|
||
|
|
}, timeout: const Timeout(Duration(seconds: 15)));
|
||
|
|
|
||
|
|
test('kind 3 (contacts) is confirmed', () async {
|
||
|
|
final outcome = await signAndPublish(
|
||
|
|
const SignEvent(kind: 3, content: ''),
|
||
|
|
);
|
||
|
|
expect(outcome, isA<RelayConfirmed>());
|
||
|
|
}, timeout: const Timeout(Duration(seconds: 15)));
|
||
|
|
|
||
|
|
test('kind 37515 (place) is confirmed', () async {
|
||
|
|
final expiration =
|
||
|
|
DateTime.now().add(const Duration(days: 30)).millisecondsSinceEpoch ~/
|
||
|
|
1000;
|
||
|
|
final outcome = await signAndPublish(
|
||
|
|
SignEvent(
|
||
|
|
kind: 37515,
|
||
|
|
tags: [
|
||
|
|
['d', 'place:swarmtest0'],
|
||
|
|
['g', 'u33dbf'],
|
||
|
|
['expiration', '$expiration'],
|
||
|
|
],
|
||
|
|
content: jsonEncode({
|
||
|
|
'type': 'Feature',
|
||
|
|
'geometry': {
|
||
|
|
'type': 'Point',
|
||
|
|
'coordinates': [13.405, 52.52],
|
||
|
|
},
|
||
|
|
'properties': {
|
||
|
|
'name': 'Swarm Test Place',
|
||
|
|
'description': 'Integration test fixture',
|
||
|
|
'type': 'test',
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
expect(outcome, isA<RelayConfirmed>());
|
||
|
|
}, timeout: const Timeout(Duration(seconds: 15)));
|
||
|
|
|
||
|
|
test('kind 37518 (check-in) is confirmed', () async {
|
||
|
|
final expiration =
|
||
|
|
DateTime.now().add(const Duration(days: 1)).millisecondsSinceEpoch ~/
|
||
|
|
1000;
|
||
|
|
final outcome = await signAndPublish(
|
||
|
|
SignEvent(
|
||
|
|
kind: 37518,
|
||
|
|
tags: [
|
||
|
|
['a', '37515:$pubkey:place:swarmtest0'],
|
||
|
|
['d', 'checkin:swarmtest0'],
|
||
|
|
['g', 'u33dbf'],
|
||
|
|
['alt', 'Check-in at Swarm Test Place'],
|
||
|
|
['expiration', '$expiration'],
|
||
|
|
['t', 'test'],
|
||
|
|
],
|
||
|
|
content: jsonEncode({'note': 'Integration test check-in'}),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
expect(outcome, isA<RelayConfirmed>());
|
||
|
|
}, timeout: const Timeout(Duration(seconds: 15)));
|
||
|
|
|
||
|
|
test('kind 1 (text note) is rejected by allowlist', () async {
|
||
|
|
final outcome = await signAndPublish(
|
||
|
|
const SignEvent(kind: 1, content: 'this should be rejected'),
|
||
|
|
);
|
||
|
|
expect(outcome, isA<RelayRejected>());
|
||
|
|
}, timeout: const Timeout(Duration(seconds: 15)));
|
||
|
|
});
|
||
|
|
}
|