package cardanoAddress_test

import "testing"

import "seekia/internal/cryptocurrency/cardanoAddress"

import "seekia/internal/encoding"
import "seekia/internal/identity"


func TestCardanoAddressFunctions(t *testing.T) {

	{
		testIdentityHashString := "wgkxplfvju7yhpoadvxju4kmfdr"

		testIdentityHash, _, err := identity.ReadIdentityHashString(testIdentityHashString)
		if (err != nil){
			t.Fatal("Failed to read testIdentityHashString: " + err.Error())
		}

		identityAddress, err := cardanoAddress.GetIdentityScoreCardanoAddressFromIdentityHash(testIdentityHash)
		if (err != nil){
			t.Fatal("Failed to get Cardano identity score address: " + err.Error())
		}

		if (identityAddress != "addr1vxy7mhvmk0zthqryd0cyrqvw9xryv5ky235vqn5ektqyrzc4w9459"){
			t.Fatal("GetIdentityScoreCardanoAddressFromIdentityHash not producing expected identity address: " + identityAddress)
		}
	}

	{
		testMemoHash := "db61e89bb23f5c9964393eaa0510491c5ea5ac14b26bcc33cdfed1b6a45900b0"
		
		testMemoHashBytes, err := encoding.DecodeHexStringToBytes(testMemoHash)
		if (err != nil){
			t.Fatal("Failed to decode testPublicKey: Not Hex: " + testMemoHash)
		}

		if (len(testMemoHashBytes) != 32){
			t.Fatal("testMemoHashBytes is invalid: Invalid length.")
		}

		testMemoHashArray := [32]byte(testMemoHashBytes)

		memoAddress, err := cardanoAddress.GetMemoCardanoAddressFromMemoHash(testMemoHashArray)
		if (err != nil){
			t.Fatal("Failed to get Cardano account address: " + err.Error())
		}

		if (memoAddress != "addr1v90ldkkj5ga0wsgcj4pvndl2v24n05xv9k6wmzuwfrmk8eqz8kru9"){
			t.Fatal("Cardano memo address does not match expected value: " + memoAddress)
		}
	}

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

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

		isValid := cardanoAddress.VerifyCardanoSeekiaAddress(newAddress)
		if (isValid == false){
			t.Fatal("Randomly generated Cardano address is invalid.")
		}
	}
}



