mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-09 18:13:59 +02:00
lnrpc: test witness type mapping
This commit is contained in:
50
lnrpc/walletrpc/walletkit_server_test.go
Normal file
50
lnrpc/walletrpc/walletkit_server_test.go
Normal file
@@ -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",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user