95 lines
2.8 KiB
Go
95 lines
2.8 KiB
Go
|
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.Fatalf("Failed to read testIdentityHashString: " + err.Error())
|
||
|
}
|
||
|
|
||
|
identityAddress, err := cardanoAddress.GetIdentityScoreCardanoAddressFromIdentityHash(testIdentityHash)
|
||
|
if (err != nil){
|
||
|
t.Fatalf("Failed to get Cardano identity score address: " + err.Error())
|
||
|
}
|
||
|
|
||
|
if (identityAddress != "addr1vxy7mhvmk0zthqryd0cyrqvw9xryv5ky235vqn5ektqyrzc4w9459"){
|
||
|
t.Fatalf("GetIdentityScoreCardanoAddressFromIdentityHash not producing expected identity address: " + identityAddress)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
{
|
||
|
testPublicKey := "667ff88775bec9dbe163b1a8d3f60a69334fa594ce17c008249f59efb6607cff"
|
||
|
|
||
|
testPublicKeyBytes, err := encoding.DecodeHexStringToBytes(testPublicKey)
|
||
|
if (err != nil){
|
||
|
t.Fatalf("Failed to decode testPublicKey: Not Hex: " + testPublicKey)
|
||
|
}
|
||
|
|
||
|
if (len(testPublicKeyBytes) != 32){
|
||
|
t.Fatalf("testPublicKey is invalid: Invalid length.")
|
||
|
}
|
||
|
|
||
|
testPublicKeyArray := [32]byte(testPublicKeyBytes)
|
||
|
|
||
|
accountAddress, err := cardanoAddress.GetCreditAccountCardanoAddressFromAccountPublicKey(testPublicKeyArray)
|
||
|
if (err != nil){
|
||
|
t.Fatalf("Failed to get Cardano account address: " + err.Error())
|
||
|
}
|
||
|
|
||
|
if (accountAddress != "addr1v9cc856hgzqpl63dgjd7cd2nqrna02wdfdeel0zh65ary0cyfeu9k"){
|
||
|
t.Fatalf("Cardano credit account address does not match expected value: " + accountAddress)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
{
|
||
|
testMemoHash := "db61e89bb23f5c9964393eaa0510491c5ea5ac14b26bcc33cdfed1b6a45900b0"
|
||
|
|
||
|
testMemoHashBytes, err := encoding.DecodeHexStringToBytes(testMemoHash)
|
||
|
if (err != nil){
|
||
|
t.Fatalf("Failed to decode testPublicKey: Not Hex: " + testMemoHash)
|
||
|
}
|
||
|
|
||
|
if (len(testMemoHashBytes) != 32){
|
||
|
t.Fatalf("testMemoHashBytes is invalid: Invalid length.")
|
||
|
}
|
||
|
|
||
|
testMemoHashArray := [32]byte(testMemoHashBytes)
|
||
|
|
||
|
memoAddress, err := cardanoAddress.GetMemoCardanoAddressFromMemoHash(testMemoHashArray)
|
||
|
if (err != nil){
|
||
|
t.Fatalf("Failed to get Cardano account address: " + err.Error())
|
||
|
}
|
||
|
|
||
|
if (memoAddress != "addr1v90ldkkj5ga0wsgcj4pvndl2v24n05xv9k6wmzuwfrmk8eqz8kru9"){
|
||
|
t.Fatalf("Cardano memo address does not match expected value: " + memoAddress)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for i:=0; i < 1000; i++{
|
||
|
|
||
|
newAddress, err := cardanoAddress.GetNewRandomCardanoAddress()
|
||
|
if (err != nil){
|
||
|
t.Fatalf("Failed to get random Cardano address: " + err.Error())
|
||
|
}
|
||
|
|
||
|
isValid := cardanoAddress.VerifyCardanoSeekiaAddress(newAddress)
|
||
|
if (isValid == false){
|
||
|
t.Fatalf("Randomly generated Cardano address is invalid.")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|