mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
lnrpc: test witness type mapping
This commit is contained in:
parent
43660c2c31
commit
32b117b9df
1 changed files with 50 additions and 0 deletions
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",
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue