Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 6429f14

Browse files
committed
add test for OrderInstructions
1 parent 8e14dab commit 6429f14

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'dart:convert';
2+
3+
import 'package:tbdex/src/protocol/models/order_instructions.dart';
4+
import 'package:tbdex/tbdex.dart';
5+
import 'package:test/test.dart';
6+
import 'package:typeid/typeid.dart';
7+
8+
import '../../helpers/test_data.dart';
9+
10+
void main() async {
11+
await TestData.initializeDids();
12+
13+
group('OrderInstructions', () {
14+
test('can create a new order instruction', () {
15+
final orderInstructions = OrderInstructions.create(
16+
TestData.pfi,
17+
TestData.alice,
18+
TypeId.generate(MessageKind.rfq.name),
19+
OrderInstructionsData(
20+
payin: PaymentInstruction(instruction: 'just do it'),
21+
payout: PaymentInstruction(instruction: 'just receive it'),
22+
),
23+
);
24+
25+
expect(
26+
orderInstructions.metadata.id,
27+
startsWith(MessageKind.orderinstructions.name),
28+
);
29+
expect(
30+
orderInstructions.metadata.kind,
31+
equals(MessageKind.orderinstructions),
32+
);
33+
expect(orderInstructions.metadata.protocol, equals('1.0'));
34+
expect(orderInstructions.data.payin.instruction, equals('just do it'));
35+
expect(
36+
orderInstructions.data.payout.instruction,
37+
equals('just receive it'),
38+
);
39+
});
40+
41+
test('can parse and verify order instructions from a json string',
42+
() async {
43+
final orderInstructions = TestData.getOrderInstructions();
44+
await orderInstructions.sign(TestData.pfiDid);
45+
final json = jsonEncode(orderInstructions.toJson());
46+
final parsed = await OrderInstructions.parse(json);
47+
48+
expect(parsed, isA<OrderInstructions>());
49+
expect(parsed.toString(), equals(json));
50+
});
51+
});
52+
}

0 commit comments

Comments
 (0)