seekia/internal/cryptocurrency/ethereumAddress/ethereumAddress_test.go

93 lines
2.7 KiB
Go

package ethereumAddress_test
import "seekia/internal/cryptocurrency/ethereumAddress"
import "seekia/internal/encoding"
import "seekia/internal/identity"
import "testing"
func TestEthereumAddressFunctions(t *testing.T) {
{
testIdentityHashString := "wgkxplfvju7yhpoadvxju4kmfdr"
testIdentityHash, _, err := identity.ReadIdentityHashString(testIdentityHashString)
if (err != nil){
t.Fatalf("Failed to read testIdentityHashString: " + err.Error())
}
identityAddress, err := ethereumAddress.GetIdentityScoreEthereumAddressFromIdentityHash(testIdentityHash)
if (err != nil){
t.Fatalf("Failed to get ethereum identity score address: " + err.Error())
}
if (identityAddress != "0x74cFc329DBEe18c791f15869019b9B3954Db1869"){
t.Fatalf("GetIdentityScoreEthereumAddressFromIdentityHash 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 := ethereumAddress.GetCreditAccountEthereumAddressFromAccountPublicKey(testPublicKeyArray)
if (err != nil){
t.Fatalf("Failed to get ethereum account address: " + err.Error())
}
if (accountAddress != "0x37b477424E10BB84cef4D04C7F1E36AcB46b9efa"){
t.Fatalf("Ethereum 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 := ethereumAddress.GetMemoEthereumAddressFromMemoHash(testMemoHashArray)
if (err != nil){
t.Fatalf("Failed to get ethereum account address: " + err.Error())
}
if (memoAddress != "0x666b01036557dF68866E7Ab852897A4D6499ea07"){
t.Fatalf("Ethereum memo address does not match expected value: " + memoAddress)
}
}
for i:=0; i < 1000; i++{
newAddress, err := ethereumAddress.GetNewRandomEthereumAddress()
if (err != nil){
t.Fatalf("Failed to get random Ethereum address: " + err.Error())
}
isValid := ethereumAddress.VerifyEthereumAddress(newAddress)
if (isValid == false){
t.Fatalf("Randomly generated Ethereum address is invalid.")
}
}
}