diff --git a/lnrpc/walletrpc/walletkit_server_test.go b/lnrpc/walletrpc/walletkit_server_test.go new file mode 100644 index 000000000..82603fdb5 --- /dev/null +++ b/lnrpc/walletrpc/walletkit_server_test.go @@ -0,0 +1,50 @@ +//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", + ) + }) + } +}