Skip to content

Commit

Permalink
protocols/horizon: Add missing strkey type names. (#4429)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jun 14, 2022
1 parent 5c7b70c commit b29a93b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
// KeyTypeNames maps from strkey version bytes into json string values to use in
// horizon responses.
var KeyTypeNames = map[strkey.VersionByte]string{
strkey.VersionByteAccountID: "ed25519_public_key",
strkey.VersionByteSeed: "ed25519_secret_seed",
strkey.VersionByteHashX: "sha256_hash",
strkey.VersionByteHashTx: "preauth_tx",
strkey.VersionByteAccountID: "ed25519_public_key",
strkey.VersionByteSeed: "ed25519_secret_seed",
strkey.VersionByteMuxedAccount: "muxed_account",
strkey.VersionByteHashTx: "preauth_tx",
strkey.VersionByteHashX: "sha256_hash",
strkey.VersionByteSignedPayload: "ed25519_signed_payload",
}

// Account is the summary of an account
Expand Down
18 changes: 18 additions & 0 deletions protocols/horizon/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,21 @@ func TestTradeAggregation_PagingToken(t *testing.T) {
ta := TradeAggregation{Timestamp: 64}
assert.Equal(t, "64", ta.PagingToken())
}

func TestMustKeyTypeFromAddress(t *testing.T) {
tests := []struct {
address string
keyType string
}{
{"GBUYDJH3AOPFFND3L54DUDWIHOMYKUONDV4RAHOHDBNN2D5N4BPPWDQ3", "ed25519_public_key"},
{"SBUYDJH3AOPFFND3L54DUDWIHOMYKUONDV4RAHOHDBNN2D5N4BPPXHDE", "ed25519_secret_seed"},
{"MBUYDJH3AOPFFND3L54DUDWIHOMYKUONDV4RAHOHDBNN2D5N4BPPWAAAAAAAAAPCIBYBE", "muxed_account"},
{"TBUYDJH3AOPFFND3L54DUDWIHOMYKUONDV4RAHOHDBNN2D5N4BPPX6CK", "preauth_tx"},
{"XBUYDJH3AOPFFND3L54DUDWIHOMYKUONDV4RAHOHDBNN2D5N4BPPW2HT", "sha256_hash"},
{"PBUYDJH3AOPFFND3L54DUDWIHOMYKUONDV4RAHOHDBNN2D5N4BPPWAAAAACWQZLMNRXQAAAA22YA", "ed25519_signed_payload"},
}

for _, test := range tests {
assert.Equal(t, MustKeyTypeFromAddress(test.address), test.keyType)
}
}

0 comments on commit b29a93b

Please sign in to comment.