Writing a non-trivial test in Puya

Hi,

I have gone through the online examples and training on Youtube of how to implement smart contracts and write client tests in Pytest/Puya, but when I try and write a test for my own smart contract, no matter what I do the test won’t compile. I have tried 10-15 different ways now :sweat_smile:

I am looking to build a test that uses test fixtures to build up the session, a dispenser wallert and create the other accounts that I am going to be using for the (functionality) test itself. The smart contract function I want to test is below, which compiles/seems to work. How would I write the test for this in Puya/Pytest (not Pyteal) for this function?

@arc4.abimethod(allow_actions=["NoOp"], create="require")
    def createPatientRecord(
        self,
        patient_ID: arc4.String,
        patient_first_name: arc4.String,
        patient_last_name: arc4.String,
        patient_DOB: arc4.String,
        patient_gender: arc4.String,
        patient_address: arc4.String,    
        patient_phone_number: arc4.String,
        patient_email: arc4.String,
        patient_emergency_contact_name: arc4.String,
        patient_emergency_contact_phone_number: arc4.String,
        patient_nationality: arc4.String,
        patient_national_ID: arc4.String,
        patient_insurance_provider: arc4.String,
        patient_insurance_provider_policy_number: arc4.String,
        initial_patient_alergies: arc4.String,
        initial_patient_chronic_conditions: arc4.String,
        initial_patient_current_medications: arc4.String,
        initial_patient_other_notes: arc4.String, ) -> None:
        # validate that it is the administrative company that is creating the system
        assert Txn.sender == Global.creator_address
        # Set the initial patient profile
        self.patient_ID = patient_ID
        self.patient_first_name = patient_first_name
        self.patient_last_name = patient_last_name
        self.patient_DOB = patient_DOB
        self.patient_gender = patient_gender
        self.patient_address = patient_address    
        self.patient_phone_number = patient_phone_number
        self.patient_email = patient_email
        self.patient_emergency_contact_name = patient_emergency_contact_name
        self.patient_emergency_contact_phone_number = patient_emergency_contact_phone_number
        self.patient_nationality = patient_nationality
        self.patient_national_ID = patient_national_ID
        self.patient_onboarding_status = arc4.String("onboarding_initiated")
        self.patient_insurance_provider = patient_insurance_provider
        self.patient_insurance_provider_policy_number = patient_insurance_provider_policy_number
        self.patient_alergies.append(initial_patient_alergies)
        self.patient_chronic_conditions.append(initial_patient_chronic_conditions)
        self.patient_current_medications.append(initial_patient_current_medications)
        self.patient_other_notes.append(initial_patient_other_notes)
        self.updateAllPatientRecordsData(self.patient_ID)
    
    @arc4.abimethod
    def updateAllPatientRecordsData(self, patient_ID: arc4.String) -> DynamicArray[arc4.String]:
        assert patient_ID == self.patient_ID
        # ensure that there is a consultation object if one is not already created
        if(self.patient_consultation_notes.length == 0):
            self.patient_consultation_notes.append(arc4.String(""))

        # append non-array data
        self.all_patient_data_records.append(self.patient_ID)
        self.all_patient_data_records.append(self.patient_first_name)
        self.all_patient_data_records.append(self.patient_last_name)
        self.all_patient_data_records.append(self.patient_DOB)
        self.all_patient_data_records.append(self.patient_gender)
        self.all_patient_data_records.append(self.patient_address)
        self.all_patient_data_records.append(self.patient_phone_number)
        self.all_patient_data_records.append(self.patient_email)
        self.all_patient_data_records.append(self.patient_emergency_contact_name)
        self.all_patient_data_records.append(self.patient_emergency_contact_phone_number)
        self.all_patient_data_records.append(self.patient_nationality)
        self.all_patient_data_records.append(self.patient_national_ID)
        self.all_patient_data_records.append(self.patient_onboarding_status)
        self.all_patient_data_records.append(self.patient_insurance_provider)
        self.all_patient_data_records.append(self.patient_insurance_provider_policy_number)
        
        #append array data
        for x in self.patient_alergies:
            y = arc4.String("Allergy: ") + x
            self.all_patient_data_records.append(y) 
    
        for x in self.patient_chronic_conditions:
            y = arc4.String("Chronic Condition: ") + x
            self.all_patient_data_records.append(y) 
        
        for x in self.patient_current_medications:
            y = arc4.String("Current Medication: ") + x
            self.all_patient_data_records.append(y) 

        for x in self.patient_other_notes:
            y = arc4.String("Other Notes: ") + x
            self.all_patient_data_records.append(y) 
        
        for x in self.patient_consultation_notes:
            y = arc4.String("consultation notes: ") + x
            self.all_patient_data_records.append(y)

        return self.all_patient_data_records

Many thanks!

1 Like