lnd/lnrpc/walletrpc/walletkit_server_test.go
2023-04-12 21:58:17 +02:00

51 lines
1.3 KiB
Go

//go:build walletrpc
// +build walletrpc
package walletrpc
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// TestWitnessTypeMapping tests that the two witness type enums in the `input`
// package and the `walletrpc` package remain equal.
func TestWitnessTypeMapping(t *testing.T) {
t.Parallel()
// Tests that both enum types have the same length except the
// UNKNOWN_WITNESS type which is only present in the walletrpc
// witness type enum.
require.Equal(
t, len(allWitnessTypes), len(WitnessType_name)-1,
"number of witness types should match proto definition",
)
// Tests that the string representations of both enum types are
// equivalent.
for witnessType, witnessTypeProto := range allWitnessTypes {
// Redeclare to avoid loop variables being captured
// by func literal.
witnessType := witnessType
witnessTypeProto := witnessTypeProto
t.Run(witnessType.String(), func(tt *testing.T) {
tt.Parallel()
witnessTypeName := witnessType.String()
witnessTypeName = strings.ToUpper(witnessTypeName)
witnessTypeProtoName := witnessTypeProto.String()
witnessTypeProtoName = strings.ReplaceAll(
witnessTypeProtoName, "_", "",
)
require.Equal(
t, witnessTypeName, witnessTypeProtoName,
"mapped witness types should be named the same",
)
})
}
}