package proofProviderKeys_test

import "seekia/internal/network/proofProviderKeys"

import "seekia/internal/encoding"

import "testing"
import "bytes"

func TestAccountKeys(t *testing.T){

	testSeedPhraseHashHex := "2a66776f76662444f2cadbdb408485db11e58ef1f262c9afcc11ab8d07c0e762"

	testSeedPhraseHashBytes, err := encoding.DecodeHexStringToBytes(testSeedPhraseHashHex)
	if (err != nil){
		t.Fatal("Invalid testSeedPhraseHash: Not Hex: " + err.Error())
	}

	if (len(testSeedPhraseHashBytes) != 32){
		t.Fatal("Invalid testSeedPhraseHash: Invalid length.")
	}

	testSeedPhraseHashArray := [32]byte(testSeedPhraseHashBytes)

	testProofProviderPublicKeyHex := "4819fbbac7d06bc21e3e55e7f0286465b72b5468814bf77b9feb38088de21f7c"

	testProofProviderPublicKeyBytes, err := encoding.DecodeHexStringToBytes(testProofProviderPublicKeyHex)
	if (err != nil){
		t.Fatal("testProofProviderPublicKeyHex is invalid: Not Hex: " + err.Error())
	}

	testProofProviderPublicKeyArray := [32]byte(testProofProviderPublicKeyBytes)

	{

		expectedPublicKeyHex := "6340ca6e0dcbe7e03f163a84c3d51873b6b86d353913a5dd5b30d3c60dec7a86"

		expectedPublicKeyBytes, err := encoding.DecodeHexStringToBytes(expectedPublicKeyHex)
		if (err != nil){
			t.Fatal("expectedPublicKeyHex is invalid: Not Hex: " + err.Error())
		}

		expectedPrivateKeyHex := "a029aac8db04440c9df2855ec8b16885fd324ad93d15b8a1a6ddfae8908625ab6340ca6e0dcbe7e03f163a84c3d51873b6b86d353913a5dd5b30d3c60dec7a86"

		expectedPrivateKeyBytes, err := encoding.DecodeHexStringToBytes(expectedPrivateKeyHex)
		if (err != nil){
			t.Fatal("expectedPrivateKeyBytes is invalid: Not Hex: " + err.Error())
		}

		publicKey, privateKey, err := proofProviderKeys.GetProofProviderAccountPublicPrivateKeys(testSeedPhraseHashArray, 1, testProofProviderPublicKeyArray, 1)
		if (err != nil){
			t.Fatal("Failed to derive proof provider account public/private keys: " + err.Error())
		}

		areEqual := bytes.Equal(publicKey[:], expectedPublicKeyBytes)
		if (areEqual == false){
			publicKeyHex := encoding.EncodeBytesToHexString(publicKey[:])
			t.Fatal("Account public key is not expected: " + publicKeyHex)
		}

		areEqual = bytes.Equal(privateKey[:], expectedPrivateKeyBytes)
		if (areEqual == false){
			privateKeyHex := encoding.EncodeBytesToHexString(privateKey[:])
			t.Fatal("Account private key is not expected: " + privateKeyHex)
		}
	}

	{
		expectedAccountPublicKeyHex := "4fb951d8385d23eff22d827a8e1405158aceae0b580b0469ae997588b64e6c36"

		expectedAccountPublicKeyBytes, err := encoding.DecodeHexStringToBytes(expectedAccountPublicKeyHex)
		if (err != nil){
			t.Fatal("expectedAccountPublicKeyHex is invalid: Not Hex: " + err.Error())
		}

		expectedAccountPrivateKeyHex := "13357b3bf1716305072a182daaabf522f870ab83d5daced467a0c58d51d717314fb951d8385d23eff22d827a8e1405158aceae0b580b0469ae997588b64e6c36"

		expectedAccountPrivateKeyBytes, err := encoding.DecodeHexStringToBytes(expectedAccountPrivateKeyHex)
		if (err != nil){
			t.Fatal("expectedAccountPrivateKeyHex is invalid: Not Hex: " + err.Error())
		}

		accountPublicKey, accountPrivateKey, err := proofProviderKeys.GetProofProviderAccountPublicPrivateKeys(testSeedPhraseHashArray, 2, testProofProviderPublicKeyArray, 1)
		if (err != nil){
			t.Fatal("Failed to derive proof provider account public/private keys: " + err.Error())
		}
		
		areEqual := bytes.Equal(accountPublicKey[:], expectedAccountPublicKeyBytes)
		if (areEqual == false){
			accountPublicKeyHex := encoding.EncodeBytesToHexString(accountPublicKey[:])
			t.Fatal("Account public key is not expected: " + accountPublicKeyHex)
		}
		
		areEqual = bytes.Equal(accountPrivateKey[:], expectedAccountPrivateKeyBytes)
		if (areEqual == false){
			accountPrivateKeyHex := encoding.EncodeBytesToHexString(accountPrivateKey[:])
			t.Fatal("Account private key is not expected: " + accountPrivateKeyHex)
		}
	}

	{

		expectedAccountPublicKeyHex := "13e035e97037eef6f94587f130c2fc07d3aeac3771be6a0257c2bb7958acb022"

		expectedAccountPublicKeyBytes, err := encoding.DecodeHexStringToBytes(expectedAccountPublicKeyHex)
		if (err != nil){
			t.Fatal("expectedAccountPublicKeyHex is invalid: Not Hex: " + err.Error())
		}

		expectedAccountPrivateKeyHex := "5b0c2c64028fb3f18f49e28a487df2d02cf6554df38b1e09a8bd229eccf1ea0f13e035e97037eef6f94587f130c2fc07d3aeac3771be6a0257c2bb7958acb022"

		expectedAccountPrivateKeyBytes, err := encoding.DecodeHexStringToBytes(expectedAccountPrivateKeyHex)
		if (err != nil){
			t.Fatal("expectedAccountPrivateKeyHex is invalid: Not Hex: " + err.Error())
		}

		accountPublicKey, accountPrivateKey, err := proofProviderKeys.GetProofProviderAccountPublicPrivateKeys(testSeedPhraseHashArray, 2, testProofProviderPublicKeyArray, 2)
		if (err != nil){
			t.Fatal("Failed to derive proof provider account public/private keys: " + err.Error())
		}
		
		areEqual := bytes.Equal(accountPublicKey[:], expectedAccountPublicKeyBytes)
		if (areEqual == false){
			accountPublicKeyHex := encoding.EncodeBytesToHexString(accountPublicKey[:])
			t.Fatal("Account public key is not expected: " + accountPublicKeyHex)
		}
		
		areEqual = bytes.Equal(accountPrivateKey[:], expectedAccountPrivateKeyBytes)
		if (areEqual == false){
			accountPrivateKeyHex := encoding.EncodeBytesToHexString(accountPrivateKey[:])
			t.Fatal("Account private key is not expected: " + accountPrivateKeyHex)
		}
	}
}



