Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l402/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
type TokenID [TokenIDSize]byte

// String returns the hex encoded representation of the token ID as a string.
func (t *TokenID) String() string {
func (t TokenID) String() string {
return hex.EncodeToString(t[:])
}

Expand Down
35 changes: 35 additions & 0 deletions l402/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package l402
import (
"bytes"
"errors"
"fmt"
"testing"

"github.com/lightningnetwork/lnd/lntypes"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -67,3 +69,36 @@ func TestIdentifierSerialization(t *testing.T) {
}
}
}

// TestTokenIDString makes sure that TokenID is logged properly in Printf
// function family.
func TestTokenIDString(t *testing.T) {
cases := []struct {
token TokenID
formatString string
wantText string
}{
{
token: TokenID{1, 2, 3},
formatString: "client %v paid",
wantText: "client 01020300000000000000000000000000000" +
"00000000000000000000000000000 paid",
},
{
token: TokenID{1, 2, 3},
formatString: "client %s paid",
wantText: "client 01020300000000000000000000000000000" +
"00000000000000000000000000000 paid",
},
}

for _, tc := range cases {
t.Run(tc.formatString, func(t *testing.T) {
got := fmt.Sprintf(tc.formatString, tc.token)
require.Equal(t, tc.wantText, got)

got = fmt.Sprintf(tc.formatString, &tc.token)
require.Equal(t, tc.wantText, got)
})
}
}
Loading