2020-02-11 16:59:21 +00:00
|
|
|
package waku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeRLP(t *testing.T) {
|
2020-02-21 14:48:53 +00:00
|
|
|
pow := math.Float64bits(6.02)
|
|
|
|
lightNodeEnabled := true
|
|
|
|
confirmationsEnabled := true
|
|
|
|
|
2020-02-11 16:59:21 +00:00
|
|
|
opts := statusOptions{
|
2020-02-21 14:48:53 +00:00
|
|
|
PoWRequirement: &pow,
|
2020-02-11 16:59:21 +00:00
|
|
|
BloomFilter: TopicToBloom(TopicType{0xaa, 0xbb, 0xcc, 0xdd}),
|
2020-02-21 14:48:53 +00:00
|
|
|
LightNodeEnabled: &lightNodeEnabled,
|
|
|
|
ConfirmationsEnabled: &confirmationsEnabled,
|
|
|
|
RateLimits: &RateLimits{
|
2020-02-11 16:59:21 +00:00
|
|
|
IPLimits: 10,
|
|
|
|
PeerIDLimits: 5,
|
|
|
|
TopicLimits: 1,
|
|
|
|
},
|
|
|
|
TopicInterest: []TopicType{{0x01}, {0x02}, {0x03}, {0x04}},
|
|
|
|
}
|
|
|
|
data, err := rlp.EncodeToBytes(opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var optsDecoded statusOptions
|
|
|
|
err = rlp.DecodeBytes(data, &optsDecoded)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, opts, optsDecoded)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackwardCompatibility(t *testing.T) {
|
|
|
|
alist := []interface{}{
|
|
|
|
[]interface{}{"0", math.Float64bits(2.05)},
|
|
|
|
}
|
|
|
|
data, err := rlp.EncodeToBytes(alist)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var optsDecoded statusOptions
|
|
|
|
err = rlp.DecodeBytes(data, &optsDecoded)
|
|
|
|
require.NoError(t, err)
|
2020-02-21 14:48:53 +00:00
|
|
|
pow := math.Float64bits(2.05)
|
|
|
|
require.EqualValues(t, statusOptions{PoWRequirement: &pow}, optsDecoded)
|
2020-02-11 16:59:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestForwardCompatibility(t *testing.T) {
|
2020-02-21 14:48:53 +00:00
|
|
|
pow := math.Float64bits(2.05)
|
2020-02-11 16:59:21 +00:00
|
|
|
alist := []interface{}{
|
2020-02-21 14:48:53 +00:00
|
|
|
[]interface{}{"0", pow},
|
2020-02-11 16:59:21 +00:00
|
|
|
[]interface{}{"99", uint(10)}, // some future option
|
|
|
|
}
|
|
|
|
data, err := rlp.EncodeToBytes(alist)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var optsDecoded statusOptions
|
|
|
|
err = rlp.DecodeBytes(data, &optsDecoded)
|
|
|
|
require.NoError(t, err)
|
2020-02-21 14:48:53 +00:00
|
|
|
require.EqualValues(t, statusOptions{PoWRequirement: &pow}, optsDecoded)
|
2020-02-11 16:59:21 +00:00
|
|
|
}
|