package serverRequest_test

import "seekia/internal/network/serverRequest"

import "seekia/internal/byteRange"
import "seekia/internal/cryptocurrency/ethereumAddress"
import "seekia/internal/cryptocurrency/cardanoAddress"
import "seekia/internal/cryptography/csidh"
import "seekia/internal/cryptography/frodo"
import "seekia/internal/cryptography/mlkem"
import "seekia/internal/cryptography/nacl"
import "seekia/internal/generate"
import "seekia/internal/genetics/geneticReferences/traits"
import "seekia/internal/genetics/geneticReferences/monogenicDiseases"
import "seekia/internal/genetics/geneticReferences/polygenicDiseases"
import "seekia/internal/helpers"
import "seekia/internal/identity"
import "seekia/internal/messaging/inbox"
import "seekia/internal/parameters/readParameters"
import "seekia/internal/profiles/profileFormat"

import "testing"
import "reflect"
import "crypto/rand"
import "errors"
import "slices"


//TODO: Add None Case
//TODO: Replace the Random retrieval of certain parameters with a for loop that will cycle through each option
//		For example, instead of choosing a profileType to retrieve by random, try all profileTypes
//		This way, the tests will not have to be run multiple times to test all profileTypes

func getNewRandomConnectionKey()([32]byte, error){

	var newKeyArray [32]byte

	_, err := rand.Read(newKeyArray[:])
	if (err != nil) { return [32]byte{}, err }

	return newKeyArray, nil
}


func TestCreateAndReadRequest_EstablishConnectionKey(t *testing.T){

	randomHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil){
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	requestorNaclPublicKey, err := nacl.GetNewRandomPublicNaclKey()
	if (err != nil) {
		t.Fatal("GetNewRandomPublicNaclKey failed: " + err.Error())
	}

	requestorMlkemPublicKey, err := mlkem.GetNewRandomPublicMlkemKey()
	if (err != nil) {
		t.Fatal("GetNewRandomPublicMlkemKey failed: " + err.Error())
	}

	requestorCsidhPublicKey, _, err := csidh.GetNewRandomPublicPrivateCsidhKeys()
	if (err != nil) {
		t.Fatal("GetNewRandomPublicPrivateCsidhKeys failed: " + err.Error())
	}

	requestorFrodoPublicKey, _, err := frodo.GetNewRandomPublicPrivateFrodoKeys()
	if (err != nil) {
		t.Fatal("GetNewRandomPublicPrivateFrodoKeys failed: " + err.Error())
	}

	serverRequestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_EstablishConnectionKey(randomHostIdentityHash, networkType, requestorNaclPublicKey, requestorMlkemPublicKey, requestorCsidhPublicKey, requestorFrodoPublicKey)
	if (err != nil) {
		t.Fatal("Failed to create EstablishConnectionKey request: " + err.Error())
	}

	receivedHostIdentityHash, requestIdentifier_Received, requestNetworkType_Received, requestorNaclKey_Received, requestorMlkemKey_Received, requestorCsidhKey_Received, requestorFrodoKey_Received, err := serverRequest.ReadServerRequest_EstablishConnectionKey(serverRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read EstablishConnectionKey request: " + err.Error())
	}

	if (randomHostIdentityHash != receivedHostIdentityHash){
		t.Fatal("EstablishConnectionKey receivedHostIdentityHash does not match.")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("EstablishConnectionKey requestIdentifier does not match.")
	}
	if (networkType != requestNetworkType_Received){
		t.Fatal("EstablishConnectionKey networkType does not match.")
	}

	if (requestorNaclPublicKey != requestorNaclKey_Received){
		t.Fatal("EstablishConnectionKey receivedRequestorNaclKey does not match.")
	}
	if (requestorMlkemPublicKey != requestorMlkemKey_Received){
		t.Fatal("EstablishConnectionKey receivedRequestorMlkemKey does not match.")
	}
	if (requestorCsidhPublicKey != requestorCsidhKey_Received){
		t.Fatal("EstablishConnectionKey receivedRequestorCsidhKey does not match.")
	}
	if (requestorFrodoPublicKey != requestorFrodoKey_Received){
		t.Fatal("EstablishConnectionKey receivedRequestorFrodoKey does not match.")
	}
}



func TestCreateAndReadRequest_GetParametersInfo(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil){
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetParametersInfo(recipientHostIdentityHash, connectionKey, networkType)
	if (err != nil) {
		t.Fatal("Failed to create GetParametersInfo server request: " + err.Error())
	}
	
	ableToDecrypt, decryptedRequest, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetParametersInfo server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetParametersInfo request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequest)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetParametersInfo request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetParametersInfo request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetParametersInfo"){
		t.Fatal("Failed to read decrypted GetParametersInfo request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetParametersInfo request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetParametersInfo request: Mismatched networkType")
	}
}



func TestCreateAndReadRequest_GetParameters(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	allParametersTypesList := readParameters.GetAllParametersTypesList()

	parametersTypesList := make([]string, 0)

	for index, element := range allParametersTypesList{
		
		randomBool := helpers.GetRandomBool()

		if (index == 0 || randomBool == true){
			// We always include the first item, so we always include at least 1 parametersType
			parametersTypesList = append(parametersTypesList, element)
		}
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetParameters(recipientHostIdentityHash, connectionKey, networkType, parametersTypesList)
	if (err != nil) {
		t.Fatal("Failed to create GetParameters server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequest, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetParameters server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetParameters request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequest)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetParameters request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetParameters request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetParameters"){
		t.Fatal("Failed to read decrypted GetParameters request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetParameters request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetParameters request: Mismatched networkType")
	}

	parametersTypesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetParameters(decryptedRequest)
	if (err != nil){
		t.Fatal("Failed to read GetParameters non-standard decrypted: " + err.Error())
	}

	areEqual := slices.Equal(parametersTypesList, parametersTypesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetParameters request: Mismatched parametersTypesList")			
	}

}

func TestCreateAndReadRequest_GetProfilesInfo(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	acceptableVersionsList := []int{1, 2}

	profileTypeToRetrieve, err := helpers.GetRandomItemFromList([]string{"Mate", "Host", "Moderator"})
	if (err != nil) {
		t.Fatal("Failed to get random profileType: " + err.Error())
	}

	rangeStart, err := identity.GetNewRandomIdentityHash(false, "")
	if (err != nil) {
		t.Fatal("Failed to create random identity hash: " + err.Error())
	}
	rangeEnd, err := identity.GetNewRandomIdentityHash(false, "")
	if (err != nil) {
		t.Fatal("Failed to create random identity hash: " + err.Error())
	}

	identityHashesList := make([][16]byte, 0)

	for i:=0; i < 100; i++{

		newIdentityHash, err := identity.GetNewRandomIdentityHash(true, profileTypeToRetrieve)
		if (err != nil) {
			t.Fatal("Failed to create random identity hash: " + err.Error())
		}

		isWithinRange, err := byteRange.CheckIfIdentityHashIsWithinRange(rangeStart, rangeEnd, newIdentityHash)
		if (err != nil){
			t.Fatal("Failed to check if identity hash is within range: " + err.Error())
		}
		if (isWithinRange == true){
			identityHashesList = append(identityHashesList, newIdentityHash)
		}		
	}

	//TODO: Add random criteria

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetProfilesInfo(recipientHostIdentityHash, connectionKey, networkType, acceptableVersionsList, profileTypeToRetrieve, rangeStart, rangeEnd, identityHashesList, nil, false, true)
	if (err != nil) {
		t.Fatal("Failed to create GetProfilesInfo server request: " + err.Error())
	}
	
	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetProfilesInfo server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetProfiles request.")
	}


	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetProfilesInfo request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetProfilesInfo"){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched networkType")
	}

	acceptableVersionsList_Received, profileTypeToRetrieve_Received, rangeStart_Received, rangeEnd_Received, identityHashesList_Received, criteria_Received, getNewestProfilesOnly_Received, getViewableProfilesOnly_Received, err := serverRequest.ReadDecryptedServerRequest_GetProfilesInfo(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetProfilesInfo non-standard decrypted: " + err.Error())
	}

	if (profileTypeToRetrieve_Received != profileTypeToRetrieve){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched profileTypeToRetrieve")
	}
	if (rangeStart != rangeStart_Received){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched rangeStart")
	}
	if (rangeEnd != rangeEnd_Received){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched rangeEnd")
	}
	if (getNewestProfilesOnly_Received != false){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched getNewestProfilesOnly")
	}
	if (getViewableProfilesOnly_Received != true){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched getViewableProfilesOnly")
	}
	if (criteria_Received != nil){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched criteria")
	}

	areEqual := slices.Equal(identityHashesList, identityHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched identityHashesList")
	}
	
	areEqual = slices.Equal(acceptableVersionsList, acceptableVersionsList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetProfilesInfo request: Mismatched acceptableVersionsList")
	}
}


func TestCreateAndReadRequest_GetProfiles(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	profileTypeToRetrieve, err := helpers.GetRandomItemFromList([]string{"Mate", "Moderator", "Host"})
	if (err != nil) {
		t.Fatal("Failed to get random profileType: " + err.Error())
	}

	profileHashesList := make([][28]byte, 0, 100)

	for i:=0; i < 100; i++{

		newProfileHash, err := helpers.GetNewRandomProfileHash(true, profileTypeToRetrieve, false, false)
		if (err != nil) {
			t.Fatal("Failed to get random profile hash: " + err.Error())
		}
		profileHashesList = append(profileHashesList, newProfileHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetProfiles(recipientHostIdentityHash, connectionKey, networkType, profileTypeToRetrieve, profileHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetProfiles server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetProfiles server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetProfiles request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetProfiles request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetProfiles request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetProfiles"){
		t.Fatal("Failed to read decrypted GetProfiles request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetProfiles request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetProfiles request: Mismatched networkType")
	}

	profileTypeToRetrieve_Received, profileHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetProfiles(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetProfiles non-standard decrypted: " + err.Error())
	}

	if (profileTypeToRetrieve_Received != profileTypeToRetrieve){
		t.Fatal("Failed to read decrypted GetProfiles request: Mismatched profileTypeToRetrieve")
	}

	areEqual := slices.Equal(profileHashesList, profileHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetProfiles request: Mismatched profileHashesList")			
	}
}


func TestCreateAndReadRequest_GetMessageHashesList(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	acceptableVersionsList := []int{1, 2, 3}

	rangeStart, err := inbox.GetNewRandomInbox()
	if (err != nil) {
		t.Fatal("GetNewRandomInbox failed: " + err.Error())
	}

	rangeEnd, err := inbox.GetNewRandomInbox()
	if (err != nil) {
		t.Fatal("GetNewRandomInbox failed: " + err.Error())
	}

	inboxesList := make([][10]byte, 0)

	for i:=0; i < 100; i++{

		newInbox, err := inbox.GetNewRandomInbox()
		if (err != nil){
			t.Fatal("GetNewRandomInbox failed: " + err.Error())
		}

		isWithinRange, err := byteRange.CheckIfInboxIsWithinRange(rangeStart, rangeEnd, newInbox)
		if (err != nil){
			t.Fatal("Failed to CheckIfInboxIsWithinRange: " + err.Error())
		}

		if (isWithinRange == true){

			inboxesList = append(inboxesList, newInbox)
		}
	}

	getViewableMessagesOnly := helpers.GetRandomBool()
	getDecryptableMessagesOnly := helpers.GetRandomBool()

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetMessageHashesList(recipientHostIdentityHash, connectionKey, networkType, acceptableVersionsList, rangeStart, rangeEnd, inboxesList, getViewableMessagesOnly, getDecryptableMessagesOnly)
	if (err != nil) {
		t.Fatal("Failed to create GetMessageHashesList server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetMessageHashesList server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetMessageHashesList request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetMessageHashesList request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetMessageHashesList"){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched networkType")
	}

	acceptableVersionsList_Received, rangeStart_Received, rangeEnd_Received, inboxesList_Received, getViewableMessagesOnly_Received, getDecryptableMessagesOnly_Received, err := serverRequest.ReadDecryptedServerRequest_GetMessageHashesList(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetMessageHashesList non-standard decrypted: " + err.Error())
	}

	if (rangeStart != rangeStart_Received){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched rangeStart")
	}
	if (rangeEnd != rangeEnd_Received){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched rangeEnd")
	}
	if (getViewableMessagesOnly_Received != getViewableMessagesOnly){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched getViewableMessagesOnly")
	}
	if (getDecryptableMessagesOnly_Received != getDecryptableMessagesOnly){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched getDecryptableMessagesOnly")
	}

	areEqual := slices.Equal(acceptableVersionsList, acceptableVersionsList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched acceptableVersionsList")	
	}
	
	areEqual = slices.Equal(inboxesList, inboxesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageHashesList request: Mismatched inboxesList")			
	}
}


func TestCreateAndReadRequest_GetMessages(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	messageHashesList := make([][26]byte, 0, 100)

	for i:=0; i < 100; i++{

		newMessageHash, err := helpers.GetNewRandomMessageHash()
		if (err != nil){
			t.Fatal("GetNewRandomMessageHash failed: " + err.Error())
		}
		messageHashesList = append(messageHashesList, newMessageHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetMessages(recipientHostIdentityHash, connectionKey, networkType, messageHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetMessages server request: " + err.Error())
	}
	
	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetMessages server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetMessages request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetMessages request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetMessages request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetMessages"){
		t.Fatal("Failed to read decrypted GetMessages request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetMessages request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetMessages request: Mismatched networkType")
	}

	messageHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetMessages(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetMessages non-standard decrypted: " + err.Error())
	}

	areEqual := slices.Equal(messageHashesList, messageHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessages request: Mismatched messageHashesList")
	}
}



func TestCreateAndReadRequest_GetIdentityReviewsInfo(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	acceptableVersionsList := []int{1, 2, 3, 4, 5}

	identityTypeToRetrieve, err := helpers.GetRandomItemFromList([]string{"Mate", "Host", "Moderator"})
	if (err != nil) {
		t.Fatal("Failed to get random identityType: " + err.Error())
	}

	rangeStart, err := identity.GetNewRandomIdentityHash(false, "")
	if (err != nil){
		t.Fatal("Failed to create random identity hash: " + err.Error())
	}

	rangeEnd, err := identity.GetNewRandomIdentityHash(false, "")
	if (err != nil){
		t.Fatal("Failed to create random identity hash: " + err.Error())
	}

	reviewedIdentityHashesList := make([][16]byte, 0)

	for i:=0; i < 100; i++{

		newIdentityHash, err := identity.GetNewRandomIdentityHash(true, identityTypeToRetrieve)
		if (err != nil) {
			t.Fatal("Failed to create random identity hash: " + err.Error())
		}

		isWithinRange, err := byteRange.CheckIfIdentityHashIsWithinRange(rangeStart, rangeEnd, newIdentityHash)
		if (err != nil){
			t.Fatal("CheckIfIdentityHashIsWithinRange failed: " + err.Error())
		}

		if (isWithinRange == true){
			reviewedIdentityHashesList = append(reviewedIdentityHashesList, newIdentityHash)
		}
	}
	
	reviewersList := make([][16]byte, 0, 100)

	for i:=0; i < 100; i++{

		newIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Moderator")
		if (err != nil) {
			t.Fatal("Failed to create random identity hash: " + err.Error())
		}

		reviewersList = append(reviewersList, newIdentityHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetIdentityReviewsInfo(recipientHostIdentityHash, connectionKey, networkType, acceptableVersionsList, identityTypeToRetrieve, rangeStart, rangeEnd, reviewedIdentityHashesList, reviewersList)
	if (err != nil) {
		t.Fatal("Failed to create GetIdentityReviewsInfo server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetIdentityReviewsInfo server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetIdentityReviewsInfo request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetIdentityReviewsInfo"){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Invalid requestType: " + requestType_Received)
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched networkType")
	}

	acceptableVersionsList_Received, identityTypeToRetrieve_Received, rangeStart_Received, rangeEnd_Received, reviewedIdentityHashesList_Received, reviewersList_Received, err := serverRequest.ReadDecryptedServerRequest_GetIdentityReviewsInfo(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetIdentityReviewsInfo non-standard decrypted: " + err.Error())
	}
	if (identityTypeToRetrieve_Received != identityTypeToRetrieve){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched identityType" + identityTypeToRetrieve_Received)
	}
	if (rangeStart != rangeStart_Received){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched rangeStart")
	}
	if (rangeEnd != rangeEnd_Received){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched rangeEnd")
	}

	areEqual := slices.Equal(acceptableVersionsList, acceptableVersionsList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched acceptableVersionsList")			
	}

	areEqual = slices.Equal(reviewedIdentityHashesList, reviewedIdentityHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched reviewedIdentityHashesList")			
	}

	areEqual = slices.Equal(reviewersList, reviewersList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetIdentityReviewsInfo request: Mismatched reviewersList")			
	}
}



func TestCreateAndReadRequest_GetMessageReviewsInfo(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	acceptableVersionsList := []int{1, 2, 3, 4, 5}

	rangeStart, err := inbox.GetNewRandomInbox()
	if (err != nil) {
		t.Fatal("GetNewRandomInbox failed: " + err.Error())
	}

	rangeEnd, err := inbox.GetNewRandomInbox()
	if (err != nil) {
		t.Fatal("GetNewRandomInbox failed: " + err.Error())
	}

	reviewedMessageHashesList := make([][26]byte, 0, 100)

	for i:=0; i < 100; i++{

		newMessageHash, err := helpers.GetNewRandomMessageHash()
		if (err != nil) {
			t.Fatal("GetNewRandomMessageHash failed: " + err.Error())
		}

		reviewedMessageHashesList = append(reviewedMessageHashesList, newMessageHash)
	}

	reviewersList := make([][16]byte, 0, 100)

	for i:=0; i < 100; i++{

		newIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Moderator")
		if (err != nil) {
			t.Fatal("Failed to create random identity hash: " + err.Error())
		}

		reviewersList = append(reviewersList, newIdentityHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetMessageReviewsInfo(recipientHostIdentityHash, connectionKey, networkType, acceptableVersionsList, rangeStart, rangeEnd, reviewedMessageHashesList, reviewersList)
	if (err != nil) {
		t.Fatal("Failed to create GetMessageReviewsInfo server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetMessageReviewsInfo server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetMessageReviewsInfo request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetMessageReviewsInfo"){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched networkType")
	}

	acceptableVersionsList_Received, rangeStart_Received, rangeEnd_Received, reviewedMessageHashesList_Received, reviewersList_Received, err := serverRequest.ReadDecryptedServerRequest_GetMessageReviewsInfo(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetMessageReviewsInfo non-standard decrypted: " + err.Error())
	}

	if (rangeStart != rangeStart_Received){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched rangeStart")
	}
	if (rangeEnd != rangeEnd_Received){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched rangeEnd")
	}

	areEqual := slices.Equal(acceptableVersionsList, acceptableVersionsList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched acceptableVersionsList")			
	}

	areEqual = slices.Equal(reviewedMessageHashesList, reviewedMessageHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched reviewedHashesList")			
	}

	areEqual = slices.Equal(reviewersList, reviewersList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageReviewsInfo request: Mismatched reviewersList")			
	}
}



func TestCreateAndReadRequest_GetReviews(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	reviewHashesList := make([][29]byte, 0, 100)

	for i:=0; i < 100; i++{

		newReviewHash, err := helpers.GetNewRandomReviewHash(false, "")
		if (err != nil){
			t.Fatal("GetNewRandomReviewHash failed: " + err.Error())
		}

		reviewHashesList = append(reviewHashesList, newReviewHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetReviews(recipientHostIdentityHash, connectionKey, networkType, reviewHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetReviews server request: " + err.Error())
	}
	
	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetReviews server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetReviews request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetReviews request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetReviews request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetReviews"){
		t.Fatal("Failed to read decrypted GetReviews request: Invalid requestType")
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetReviews request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetReviews request: Mismatched networkType")
	}

	reviewHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetReviews(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetReviews non-standard decrypted: " + err.Error())
	}

	areEqual := slices.Equal(reviewHashesList, reviewHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetReviews request: Mismatched messageHashesList")			
	}
}

func TestCreateAndReadRequest_GetIdentityReportsInfo(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	acceptableVersionsList := []int{2}

	identityTypeToRetrieve, err := helpers.GetRandomItemFromList([]string{"Mate", "Host", "Moderator"})
	if (err != nil) {
		t.Fatal("Failed to get random identityType: " + err.Error())
	}

	rangeStart, err := identity.GetNewRandomIdentityHash(false, "")
	if (err != nil) {
		t.Fatal("Failed to create random identity hash: " + err.Error())
	}

	rangeEnd, err := identity.GetNewRandomIdentityHash(false, "")
	if (err != nil) {
		t.Fatal("Failed to create random identity hash: " + err.Error())
	}

	reportedIdentityHashesList := make([][16]byte, 0)
	
	for i:=0; i < 100; i++{

		newIdentityHash, err := identity.GetNewRandomIdentityHash(true, identityTypeToRetrieve)
		if (err != nil) {
			t.Fatal("Failed to create random identity hash")
		}

		isWithinRange, err := byteRange.CheckIfIdentityHashIsWithinRange(rangeStart, rangeEnd, newIdentityHash)
		if (err != nil){
			t.Fatal("GetIdentityHashWithinRange failed: " + err.Error())
		}

		if (isWithinRange == true){
			reportedIdentityHashesList = append(reportedIdentityHashesList, newIdentityHash)
		}
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetIdentityReportsInfo(recipientHostIdentityHash, connectionKey, networkType, acceptableVersionsList, identityTypeToRetrieve, rangeStart, rangeEnd, reportedIdentityHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetIdentityReportsInfo server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetIdentityReportsInfo server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetIdentityReportsInfo request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetIdentityReportsInfo"){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Invalid requestType: " + requestType_Received)
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched networkType")
	}

	acceptableVersionsList_Received, identityTypeToRetrieve_Received, rangeStart_Received, rangeEnd_Received, reportedIdentityHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetIdentityReportsInfo(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetIdentityReportsInfo non-standard decrypted: " + err.Error())
	}

	if (identityTypeToRetrieve_Received != identityTypeToRetrieve){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched identityType: " + identityTypeToRetrieve_Received)
	}

	if (rangeStart != rangeStart_Received){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched rangeStart")
	}
	if (rangeEnd != rangeEnd_Received){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched rangeEnd")
	}

	areEqual := slices.Equal(acceptableVersionsList, acceptableVersionsList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched acceptableVersionsList")
	}

	areEqual = slices.Equal(reportedIdentityHashesList, reportedIdentityHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetIdentityReportsInfo request: Mismatched reportedIdentityHashesList")
	}
}


func TestCreateAndReadRequest_GetMessageReportsInfo(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	acceptableVersionsList := []int{2}

	rangeStart, err := inbox.GetNewRandomInbox()
	if (err != nil) {
		t.Fatal("GetNewRandomInbox failed: " + err.Error())
	}
	rangeEnd, err := inbox.GetNewRandomInbox()
	if (err != nil) {
		t.Fatal("GetNewRandomInbox failed: " + err.Error())
	}

	reportedMessageHashesList := make([][26]byte, 0, 100)
	
	for i:=0; i < 100; i++{

		newMessageHash, err := helpers.GetNewRandomMessageHash()
		if (err != nil) {
			t.Fatal("GetNewRandomMessageHash failed: " + err.Error())
		}

		reportedMessageHashesList = append(reportedMessageHashesList, newMessageHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetMessageReportsInfo(recipientHostIdentityHash, connectionKey, networkType, acceptableVersionsList, rangeStart, rangeEnd, reportedMessageHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetMessageReportsInfo server request: " + err.Error())
	}

	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetMessageReportsInfo server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetMessageReportsInfo request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetMessageReportsInfo"){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Invalid requestType: " + requestType_Received)
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched networkType")
	}

	acceptableVersionsList_Received, rangeStart_Received, rangeEnd_Received, reportedMessageHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetMessageReportsInfo(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetMessageReportsInfo non-standard decrypted: " + err.Error())
	}

	if (rangeStart != rangeStart_Received){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched rangeStart")
	}
	if (rangeEnd != rangeEnd_Received){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched rangeEnd")
	}

	areEqual := slices.Equal(acceptableVersionsList, acceptableVersionsList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched acceptableVersionsList")
	}

	areEqual = slices.Equal(reportedMessageHashesList, reportedMessageHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetMessageReportsInfo request: Mismatched reportedHashesList")			
	}

}


func TestCreateAndReadRequest_GetReports(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	reportHashesList := make([][30]byte, 0, 100)

	for i:=0; i < 100; i++{

		newReportHash, err := helpers.GetNewRandomReportHash(false, "")
		if (err != nil){
			t.Fatal("GetNewRandomReportHash failed: " + err.Error())
		}

		reportHashesList = append(reportHashesList, newReportHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetReports(recipientHostIdentityHash, connectionKey, networkType, reportHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetReports server request: " + err.Error())
	}
	
	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetReports server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetReports request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetReports request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetReports request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetReports"){
		t.Fatal("Failed to read decrypted GetReports request: Invalid requestType: " + requestType_Received)
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetReports request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetReports request: Mismatched networkType")
	}

	reportHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetReports(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetReports non-standard decrypted: " + err.Error())
	}

	areEqual := slices.Equal(reportHashesList, reportHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetReports request: Mismatched messageHashesList")
	}
}

func TestCreateAndReadRequest_GetAddressDeposits(t *testing.T){

	cryptocurrencyNamesList := []string{"Ethereum", "Cardano"}

	for _, cryptocurrencyName := range cryptocurrencyNamesList{

		recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
		if (err != nil) {
			t.Fatal("Failed to create random host identity hash: " + err.Error())
		}

		connectionKey, err := getNewRandomConnectionKey()
		if (err != nil) {
			t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
		}

		networkType, err := helpers.GetRandomByteWithinRange(1, 2)
		if (err != nil) {
			t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
		}

		cryptocurrencyAddressesList := make([]string, 0, 100)
		
		for i:=0; i < 100; i++{

			if (cryptocurrencyName == "Ethereum"){

				newAddress, err := ethereumAddress.GetNewRandomEthereumAddress()
				if (err != nil) {
					t.Fatal("Failed to create random Ethereum address: " + err.Error())
				}

				cryptocurrencyAddressesList = append(cryptocurrencyAddressesList, newAddress)

			} else if (cryptocurrencyName == "Cardano"){

				newAddress, err := cardanoAddress.GetNewRandomCardanoAddress()
				if (err != nil) {
					t.Fatal("Failed to create random Cardano address: " + err.Error())
				}

				cryptocurrencyAddressesList = append(cryptocurrencyAddressesList, newAddress)
			}
		}

		requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetAddressDeposits(recipientHostIdentityHash, connectionKey, networkType, cryptocurrencyName, cryptocurrencyAddressesList)
		if (err != nil) {
			t.Fatal("Failed to create GetAddressDeposits server request: " + err.Error())
		}
		
		ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
		if (err != nil) {
			t.Fatal("Failed to decrypt GetAddressDeposits server request: invalid inputs: " + err.Error())
		}
		if (ableToDecrypt == false) {
			t.Fatal("Failed to decrypt GetProfileHashesList request.")
		}

		recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
		if (err != nil) {
			t.Fatal("Failed to read decrypted GetAddressDeposits request: " + err.Error())
		}

		if (recipientHost_Received != recipientHostIdentityHash){
			t.Fatal("Failed to read decrypted GetAddressDeposits request: Mismatched recipientHost")
		}
		if (requestType_Received != "GetAddressDeposits"){
			t.Fatal("Failed to read decrypted GetAddressDeposits request: Invalid requestType: " + requestType_Received)
		}
		if (requestIdentifier_Received != requestIdentifier){
			t.Fatal("Failed to read decrypted GetAddressDeposits request: Mismatched requestIdentifier")
		}
		if (networkType_Received != networkType){
			t.Fatal("Failed to read decrypted GetAddressDeposits request: Mismatched networkType")
		}

		cryptocurrency_Received, cryptocurrencyAddressesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetAddressDeposits(decryptedRequestBytes)
		if (err != nil){
			t.Fatal("Failed to read GetAddressDeposits non-standard decrypted: " + err.Error())
		}
		
		if (cryptocurrency_Received != cryptocurrencyName){
			t.Fatal("Failed to read decrypted GetAddressDeposits request: Mismatched cryptocurrency")
		}

		areEqual := slices.Equal(cryptocurrencyAddressesList, cryptocurrencyAddressesList_Received)
		if (areEqual == false){
			t.Fatal("Failed to read decrypted GetAddressDeposits request: Mismatched identityHashesList")
		}
	}
}


func TestCreateAndReadRequest_GetViewableStatuses(t *testing.T){

	recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
	if (err != nil) {
		t.Fatal("Failed to create random host identity hash: " + err.Error())
	}

	connectionKey, err := getNewRandomConnectionKey()
	if (err != nil) {
		t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	identityHashesList := make([][16]byte, 0, 100)

	for i:=0; i < 100; i++{
		
		newIdentityHash, err := identity.GetNewRandomIdentityHash(false, "")
		if (err != nil) {
			t.Fatal("Failed to create random identity hash: " + err.Error())
		}

		identityHashesList = append(identityHashesList, newIdentityHash)
	}

	profileHashesList := make([][28]byte, 0, 50)

	for k:=0; k < 50; k++{

		newProfileHash, err := helpers.GetNewRandomProfileHash(false, "", true, false)
		if (err != nil) {
			t.Fatal("Failed to get random profile hash: " + err.Error())
		}

		profileHashesList = append(profileHashesList, newProfileHash)
	}

	requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_GetViewableStatuses(recipientHostIdentityHash, connectionKey, networkType, identityHashesList, profileHashesList)
	if (err != nil) {
		t.Fatal("Failed to create GetViewableStatuses server request: " + err.Error())
	}
	
	ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
	if (err != nil) {
		t.Fatal("Failed to decrypt GetViewableStatuses server request: invalid inputs: " + err.Error())
	}
	if (ableToDecrypt == false) {
		t.Fatal("Failed to decrypt GetViewableStatuses request.")
	}

	recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
	if (err != nil) {
		t.Fatal("Failed to read decrypted GetViewableStatuses request: " + err.Error())
	}

	if (recipientHost_Received != recipientHostIdentityHash){
		t.Fatal("Failed to read decrypted GetViewableStatuses request: Mismatched recipientHost")
	}
	if (requestType_Received != "GetViewableStatuses"){
		t.Fatal("Failed to read decrypted GetViewableStatuses request: Invalid requestType: " + requestType_Received)
	}
	if (requestIdentifier_Received != requestIdentifier){
		t.Fatal("Failed to read decrypted GetViewableStatuses request: Mismatched requestIdentifier")
	}
	if (networkType_Received != networkType){
		t.Fatal("Failed to read decrypted GetViewableStatuses request: Mismatched networkType")
	}

	identityHashesList_Received, profileHashesList_Received, err := serverRequest.ReadDecryptedServerRequest_GetViewableStatuses(decryptedRequestBytes)
	if (err != nil){
		t.Fatal("Failed to read GetViewableStatuses non-standard decrypted: " + err.Error())
	}

	areEqual := slices.Equal(identityHashesList, identityHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetViewableStatuses request: Mismatched identityHashesList")			
	}

	areEqual = slices.Equal(profileHashesList, profileHashesList_Received)
	if (areEqual == false){
		t.Fatal("Failed to read decrypted GetViewableStatuses request: Mismatched profileHashesList")			
	}
}


func TestCreateAndReadRequest_BroadcastContent(t *testing.T){

	// We initialize these variables so we can create fake profiles

	monogenicDiseases.InitializeMonogenicDiseaseVariables()

	err := polygenicDiseases.InitializePolygenicDiseaseVariables()	
	if (err != nil) {
		t.Fatal("InitializePolygenicDiseaseVariables failed: " + err.Error())
	}

	err = traits.InitializeTraitVariables()
	if (err != nil) {
		t.Fatal("InitializeTraitVariables failed: " + err.Error())
	}

	err = profileFormat.InitializeProfileFormatVariables()
	if (err != nil) {
		t.Fatal("Failed to initialize profile format variables: " + err.Error())
	}

	contentTypesToBroadcastList := []string{"Profile", "Message", "Review", "Report", "Parameters"}

	for _, contentTypeToBroadcast := range contentTypesToBroadcastList{

		recipientHostIdentityHash, err := identity.GetNewRandomIdentityHash(true, "Host")
		if (err != nil) {
			t.Fatal("Failed to create random host identity hash: " + err.Error())
		}

		connectionKey, err := getNewRandomConnectionKey()
		if (err != nil) {
			t.Fatal("getNewRandomConnectionKey failed: " + err.Error())
		}

		networkType, err := helpers.GetRandomByteWithinRange(1, 2)
		if (err != nil){
			t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
		}

		getRandomContentBytes := func()([]byte, error){

			if (contentTypeToBroadcast == "Profile"){

				//TODO: Add Host once we can create Host profiles
				profileType, err := helpers.GetRandomItemFromList([]string{"Mate", "Moderator"})
				if (err != nil) { return nil, err }

				profilePublicIdentityKey, profilePrivateIdentityKey, err := identity.GetNewRandomPublicPrivateIdentityKeys()
				if (err != nil) { return nil, err }

				fakeProfileBytes, err := generate.GetFakeProfile(profileType, profilePublicIdentityKey, profilePrivateIdentityKey, networkType)
				if (err != nil) {
					return nil, errors.New("Failed to create fake profile: " + err.Error())
				}

				return fakeProfileBytes, nil
			}
			if (contentTypeToBroadcast == "Review"){

				reviewType, err := helpers.GetRandomItemFromList([]string{"Profile", "Identity", "Message"})
				if (err != nil) { return nil, err }

				fakeReviewBytes, err := generate.GetFakeReview(reviewType, networkType)
				if (err != nil) {
					return nil, errors.New("Failed to create fake review: " + err.Error())
				}

				return fakeReviewBytes, nil
			}
			if (contentTypeToBroadcast == "Message"){

				textOrImage, err := helpers.GetRandomItemFromList([]string{"Text", "Image"})
				if (err != nil) { return nil, err }

				fakeMessageBytes, _, _, err := generate.GetFakeMessage(networkType, textOrImage)
				if (err != nil) {
					return nil, errors.New("Failed to create fake message: " + err.Error())
				}

				return fakeMessageBytes, nil
			}
			if (contentTypeToBroadcast == "Report"){

				reportType, err := helpers.GetRandomItemFromList([]string{"Profile", "Identity", "Message"})
				if (err != nil) { return nil, err }

				fakeReportBytes, err := generate.GetFakeReport(reportType, networkType)
				if (err != nil) {
					return nil, errors.New("Failed to create fake report: " + err.Error())
				}

				return fakeReportBytes, nil
			}
			// contentTypeToBroadcast = "Parameters"

			parametersTypesList := readParameters.GetAllParametersTypesList()

			randomParametersType, err := helpers.GetRandomItemFromList(parametersTypesList)
			if (err != nil) { return nil, err }

			fakeParametersBytes, err := generate.GetFakeParameters(randomParametersType, networkType)
			if (err != nil) {
				return nil, errors.New("Failed to get fake parameters: " + err.Error())
			}

			return fakeParametersBytes, nil
		}

		contentList := make([][]byte, 0, 20)

		for i:=0; i < 20; i++{

			randomContentBytes, err := getRandomContentBytes()
			if (err != nil) {
				t.Fatal("Failed to get random content: " + err.Error())
			}
			
			contentList = append(contentList, randomContentBytes)
		}

		requestBytes, requestIdentifier, err := serverRequest.CreateServerRequest_BroadcastContent(recipientHostIdentityHash, connectionKey, networkType, contentTypeToBroadcast, contentList)
		if (err != nil) {
			t.Fatal("Failed to create BroadcastContent server request: " + err.Error())
		}
		
		ableToDecrypt, decryptedRequestBytes, err := serverRequest.ReadEncryptedRequest(requestBytes, connectionKey)
		if (err != nil) {
			t.Fatal("Failed to decrypt BroadcastContent server request: invalid inputs: " + err.Error())
		}
		if (ableToDecrypt == false) {
			t.Fatal("Failed to decrypt BroadcastContent request.")
		}

		recipientHost_Received, requestType_Received, requestIdentifier_Received, networkType_Received, err := serverRequest.ReadDecryptedServerRequest_StandardData(decryptedRequestBytes)
		if (err != nil) {
			t.Fatal("Failed to read decrypted BroadcastContent request: " + err.Error())
		}

		if (recipientHost_Received != recipientHostIdentityHash){
			t.Fatal("Failed to read decrypted BroadcastContent request: Mismatched recipientHost")
		}
		if (requestType_Received != "BroadcastContent"){
			t.Fatal("Failed to read decrypted BroadcastContent request: Invalid requestType")
		}
		if (requestIdentifier_Received != requestIdentifier){
			t.Fatal("Failed to read decrypted BroadcastContent request: Mismatched requestIdentifier")
		}
		if (networkType_Received != networkType){
			t.Fatal("Failed to read decrypted BroadcastContent request: Mismatched networkType")
		}

		contentTypeToBroadcast_Received, contentList_Received, err := serverRequest.ReadDecryptedServerRequest_BroadcastContent(decryptedRequestBytes)
		if (err != nil){
			t.Fatal("Failed to read BroadcastContent non-standard decrypted: " + err.Error())
		}

		if (contentTypeToBroadcast_Received != contentTypeToBroadcast){
			t.Fatal("Failed to read decrypted BroadcastContent request: Mismatched contentTypeToBroadcast")
		}

		areEqual := reflect.DeepEqual(contentList, contentList_Received)
		if (areEqual == false){
			t.Fatal("Failed to read decrypted BroadcastContent request: Mismatched contentList")
		}
	}
}


