package readMemos_test import "seekia/internal/memos/readMemos" import "seekia/internal/identity" import "seekia/internal/encoding" import "bytes" import "testing" func TestReadMemo(t *testing.T){ testMemo := `| «« Seekia Memo »» | |- Signature: | OBaIeYgbN6AqrlKRGo2K9v2y8L4_jk | hRahKqgYvGbS3zv0cWDbmdZd4h4GMA | _aZC2rX67dkBHoGOgzvrVguiDA== | |- Identity Key: | 019f50f450efec14d5314e36685e6ccd | 2a11026d206108a7e46ad1aa5778a36c | |- Author: | ajcn6vesxwejdvwgj57bdo3m3dm | |- Memo: | | Cure racial loneliness. | | Beautify the human species. | | Seekia: Be race aware. | | «« End Of Memo »»` memoIsValid, memoHash, authorIdentityHash, unarmoredMemoContent, err := readMemos.ReadMemo(testMemo) if (err != nil){ t.Fatalf("Failed to read memo: " + err.Error()) } if (memoIsValid == false){ t.Fatalf("Memo is not valid.") } expectedAuthorIdentityHashString := "ajcn6vesxwejdvwgj57bdo3m3dm" expectedAuthorIdentityHash, _, err := identity.ReadIdentityHashString(expectedAuthorIdentityHashString) if (err != nil){ t.Fatalf("Failed to read expectedAuthorIdentityHashString: " + err.Error()) } if (authorIdentityHash != expectedAuthorIdentityHash){ authorIdentityHashHex := encoding.EncodeBytesToHexString(authorIdentityHash[:]) t.Fatalf("Received author identity hash does not match: " + authorIdentityHashHex) } memoHashExpected := "1cc8b5f73ec83b24db18814292ffd3139b6571be0d0a4ce7002de458525b0ea3" memoHashBytes, err := encoding.DecodeHexStringToBytes(memoHashExpected) if (err != nil){ t.Fatalf("Unable to read memoHashExpected: " + err.Error()) } areEqual := bytes.Equal(memoHash[:], memoHashBytes) if (areEqual == false){ memoHashHex := encoding.EncodeBytesToHexString(memoHash[:]) t.Fatalf("Received unexpected memo hash: " + memoHashHex) } ethereumAddress, err := readMemos.GetBlockchainAddressFromMemoHash("Ethereum", memoHash) if (err != nil){ t.Fatalf("GetBlockchainAddressFromMemoHash failed: " + err.Error()) } if (ethereumAddress != "0xc514B072e60F03568F0e136d30de210579ffA1F0"){ t.Fatalf("GetBlockchainAddressFromMemoHash returning unexpected Ethereum address: " + ethereumAddress) } cardanoAddress, err := readMemos.GetBlockchainAddressFromMemoHash("Cardano", memoHash) if (err != nil){ t.Fatalf("GetBlockchainAddressFromMemoHash failed: " + err.Error()) } if (cardanoAddress != "addr1vy0gfzl8muw3cstqhlage0nm5y9tyay3ueez4whya9qulpgpvytyu"){ t.Fatalf("GetBlockchainAddressFromMemoHash returning unexpected Cardano address: " + cardanoAddress) } expectedUnarmoredMemoContent := `Cure racial loneliness. Beautify the human species. Seekia: Be race aware.` if (unarmoredMemoContent != expectedUnarmoredMemoContent){ t.Fatalf("Unexpected unarmoredMemoContent: " + unarmoredMemoContent) } } // We use this to verify a legacy memo, where lines with no content were preceded with a pipe and 4 whitespace characters // Now memos do not contain the 4 whitespace characters for these lines. They only contain a single pipe. func TestReadMemo_Legacy(t *testing.T){ testMemo := `| «« Seekia Memo »» | |- Signature: | ND8PfLLNZn7CJlQMokl7jvmd8yL5ee | OGuJ6Jql_dN2BgANO8n9vYo9h5qPZL | AUAmWM2D_PXJUwzOTxs6bUV1Bw== | |- Identity Key: | b26327a3e00e97a2759ac0a08a39c84f | 8edb833eec43669a81e27509f4ff6636 | |- Author: | p2qsphq4m72wr6trbyibwggsfem | |- Memo: | | Cure racial loneliness. | | Facilitate eugenic breeding. | | Seekia: Be race aware. | | «« End Of Memo »»` memoIsValid, memoHash, authorIdentityHash, unarmoredMemoContent, err := readMemos.ReadMemo(testMemo) if (err != nil){ t.Fatalf("Failed to read memo: " + err.Error()) } if (memoIsValid == false){ t.Fatalf("Memo is not valid.") } expectedAuthorIdentityHashString := "p2qsphq4m72wr6trbyibwggsfem" expectedAuthorIdentityHash, _, err := identity.ReadIdentityHashString(expectedAuthorIdentityHashString) if (err != nil){ t.Fatalf("Failed to read expectedAuthorIdentityHashString: " + err.Error()) } if (authorIdentityHash != expectedAuthorIdentityHash){ authorIdentityHashHex := encoding.EncodeBytesToHexString(authorIdentityHash[:]) t.Fatalf("Received author identity hash does not match: " + authorIdentityHashHex) } memoHashExpected := "c624a587458564a272a357c8bda79e51dfe4cbc1a995b612887ceafe54ad3b4f" memoHashBytes, err := encoding.DecodeHexStringToBytes(memoHashExpected) if (err != nil){ t.Fatalf("Unable to read memoHashExpected: " + err.Error()) } areEqual := bytes.Equal(memoHash[:], memoHashBytes) if (areEqual == false){ memoHashHex := encoding.EncodeBytesToHexString(memoHash[:]) t.Fatalf("Received unexpected memo hash: " + memoHashHex) } ethereumAddress, err := readMemos.GetBlockchainAddressFromMemoHash("Ethereum", memoHash) if (err != nil){ t.Fatalf("GetBlockchainAddressFromMemoHash failed: " + err.Error()) } if (ethereumAddress != "0xb56159Dbe37A255915A113a12588447182eDDD06"){ t.Fatalf("GetBlockchainAddressFromMemoHash returning unexpected Ethereum address: " + ethereumAddress) } cardanoAddress, err := readMemos.GetBlockchainAddressFromMemoHash("Cardano", memoHash) if (err != nil){ t.Fatalf("GetBlockchainAddressFromMemoHash failed: " + err.Error()) } if (cardanoAddress != "addr1vxerdvvcwxgvcwf23tjxp8kl9kg0rpe4dsvpsjfcguusk6sfn9c6h"){ t.Fatalf("GetBlockchainAddressFromMemoHash returning unexpected Cardano address: " + cardanoAddress) } expectedUnarmoredMemoContent := `Cure racial loneliness. Facilitate eugenic breeding. Seekia: Be race aware.` if (unarmoredMemoContent != expectedUnarmoredMemoContent){ t.Fatalf("Unexpected unarmoredMemoContent: " + unarmoredMemoContent) } }