2020-07-23 15:28:36 +00:00
|
|
|
package loopdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-12-13 13:23:36 +00:00
|
|
|
looprpc "github.com/lightninglabs/loop/swapserverrpc"
|
2020-07-23 15:28:36 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestProtocolVersionSanity tests that protocol versions are sane, meaning
|
|
|
|
// we always keep our stored protocol version in sync with the RPC protocol
|
|
|
|
// version except for the unrecorded version.
|
|
|
|
func TestProtocolVersionSanity(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
versions := [...]ProtocolVersion{
|
|
|
|
ProtocolVersionLegacy,
|
|
|
|
ProtocolVersionMultiLoopOut,
|
|
|
|
ProtocolVersionSegwitLoopIn,
|
|
|
|
ProtocolVersionPreimagePush,
|
|
|
|
ProtocolVersionUserExpiryLoopOut,
|
2020-07-23 15:30:53 +00:00
|
|
|
ProtocolVersionHtlcV2,
|
2020-05-29 09:27:47 +00:00
|
|
|
ProtocolVersionMultiLoopIn,
|
2021-05-24 06:40:12 +00:00
|
|
|
ProtocolVersionLoopOutCancel,
|
2021-05-10 14:55:53 +00:00
|
|
|
ProtocolVersionProbe,
|
2021-11-28 18:49:59 +00:00
|
|
|
ProtocolVersionRoutingPlugin,
|
2022-04-24 20:29:13 +00:00
|
|
|
ProtocolVersionHtlcV3,
|
2020-07-23 15:28:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 13:23:36 +00:00
|
|
|
rpcVersions := [...]looprpc.ProtocolVersion{
|
|
|
|
looprpc.ProtocolVersion_LEGACY,
|
|
|
|
looprpc.ProtocolVersion_MULTI_LOOP_OUT,
|
|
|
|
looprpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN,
|
|
|
|
looprpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT,
|
|
|
|
looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT,
|
|
|
|
looprpc.ProtocolVersion_HTLC_V2,
|
|
|
|
looprpc.ProtocolVersion_MULTI_LOOP_IN,
|
|
|
|
looprpc.ProtocolVersion_LOOP_OUT_CANCEL,
|
|
|
|
looprpc.ProtocolVersion_PROBE,
|
2021-11-28 18:49:59 +00:00
|
|
|
looprpc.ProtocolVersion_ROUTING_PLUGIN,
|
2022-04-24 20:29:13 +00:00
|
|
|
looprpc.ProtocolVersion_HTLC_V3,
|
2020-07-23 15:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, len(versions), len(rpcVersions))
|
|
|
|
for i, version := range versions {
|
|
|
|
require.Equal(t, uint32(version), uint32(rpcVersions[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally test that the current version contants are up to date
|
|
|
|
require.Equal(t,
|
|
|
|
CurrentInternalProtocolVersion,
|
|
|
|
versions[len(versions)-1],
|
|
|
|
)
|
|
|
|
|
|
|
|
require.Equal(t,
|
|
|
|
uint32(CurrentInternalProtocolVersion),
|
|
|
|
uint32(CurrentRPCProtocolVersion),
|
|
|
|
)
|
|
|
|
}
|