Skip to content

Commit

Permalink
stellar#4909: follow xdr Asset for String serialization of loader Ass…
Browse files Browse the repository at this point in the history
…etKey
  • Loading branch information
sreuland committed Oct 24, 2023
1 parent 80cfc01 commit 208f48c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions services/horizon/internal/db2/history/asset_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type AssetKey struct {
}

func (key AssetKey) String() string {
if key.Type == xdr.AssetTypeToString[xdr.AssetTypeAssetTypeNative] {
return key.Type
}
return key.Type + "/" + key.Code + "/" + key.Issuer
}

Expand Down
22 changes: 22 additions & 0 deletions services/horizon/internal/db2/history/asset_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ import (
"github.com/stellar/go/xdr"
)

func TestAssetKeyToString(t *testing.T) {
num4key := AssetKey{
Type: "credit_alphanum4",
Code: "USD",
Issuer: "A1B2C3",
}

num12key := AssetKey{
Type: "credit_alphanum12",
Code: "USDABC",
Issuer: "A1B2C3",
}

nativekey := AssetKey{
Type: "native",
}

assert.Equal(t, num4key.String(), "credit_alphanum4/USD/A1B2C3")
assert.Equal(t, num12key.String(), "credit_alphanum12/USDABC/A1B2C3")
assert.Equal(t, nativekey.String(), "native")
}

func TestAssetLoader(t *testing.T) {
tt := test.Start(t)
defer tt.Finish()
Expand Down

0 comments on commit 208f48c

Please sign in to comment.