Testing Scenarios for Airline Model

Hi,

I am learning DAML and I want to ask something related to Airline Model.

I want to ask about this test script or if you can explain 2 or 4 testing scenarios for this Model.

dajet = script do
da ← allocateParty “DA”
passengers@[p1, p2, p3, p4, p5]
← mapA allocateParty [“P1”, “P2”, “P3”, “P4”, “P5”]
let
flightNumber = “DA Force One”
classes = [Coach, Coach, Business, Business, First]
seatClasses = TM.fromList
[ (“1A”, First)
, (“1B”, First)
, (“2A”, Business)
, (“2B”, Business)
, (“3A”, Coach)
, (“3B”, Coach) ]
tickets = map
((seq, passenger, ticketClass) →
Ticket with
ticketClass
ticketRef = show seq
flightNumber
airline = da
passenger
seatChoice = ticketClass > Coach
)
(zip3 [1…5] passengers classes)
(inviteCids, flightCid) ← submit da do
inviteCids ← mapA (\ticket → createCmd FlightInvite with ticket) tickets
flightCid ← createCmd Flight with
seatClasses
allocation = TM.empty
flightNumber
airline = da
invitedPassengers = passengers
passengers =
return (inviteCids, flightCid)

Please provide code samples in-between triple-ticks (```), otherwise it’s impossible to read.

1 Like

(dajet = script do
da ← allocateParty “DA”
passengers@[p1, p2, p3, p4, p5]
← mapA allocateParty [“P1”, “P2”, “P3”, “P4”, “P5”]
let
flightNumber = “DA Force One”
classes = [Coach, Coach, Business, Business, First]
seatClasses = TM.fromList
[ (“1A”, First)
, (“1B”, First)
, (“2A”, Business)
, (“2B”, Business)
, (“3A”, Coach)
, (“3B”, Coach) ]
tickets = map
((seq, passenger, ticketClass) →
Ticket with
ticketClass
ticketRef = show seq
flightNumber
airline = da
passenger
seatChoice = ticketClass > Coach
)
(zip3 [1…5] passengers classes)

(inviteCids, flightCid) ← submit da do
inviteCids ← mapA (\ticket → createCmd FlightInvite with ticket) tickets
flightCid ← createCmd Flight with
seatClasses
allocation = TM.empty
flightNumber
airline = da
invitedPassengers = passengers
passengers =
return (inviteCids, flightCid)

@Zerum
As far as I can see the code snippet you included is taken from ex-models/Airline.daml at ca6818c10923360f7158e03a4c50dabe156f5419 · digital-asset/ex-models · GitHub
Do you have some specific questions about this code?
The fragment of the Daml script that you included performs the following actions:

  1. Allocates a party named “DA”, which acts as a flight operator, and 5 parties named “P1” … “P5”, which represent 5 passengers.
  2. It maps seat numbers to travel classes.
  3. It iterates over the list of passengers and for each passenger creates a Ticket record (note, this is a Ticket record, not a Ticket contract).
  4. For each Ticker record created in the previous step the script creates a FlightInvite contract. And it also creates a Flight contract with the list of invited passenger and an empty allocation of passengers to seats.

The rest of the script, which you did not include, iterates over the list of passengers and for each passenger exercises Accept_Invite choice on the passenger’s FlightInvite contract, which creates a list of Ticket contracts (one Ticket contract for each passenger). The script then does a bunch of submitMustFail tests (e.g. it checks that passenger p1 cannot check in for the flight with the seat “1A” because “1A” is a First Class seat and passenger p1’s ticket is in Coach). And finally the script exercises CheckIn choice on the Ticket contract for each passenger party with correct seat, which then allows TakeOff choice to be exercised on the Flight contract (since all passengers have checked in and been allocated to their seats).
This is a rather high level description of what the script does. I appreciate you may have further questions. If you do, please don’t hesitate to post them here.