|
| 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