2022-10-17 17:13:23 +00:00
|
|
|
package utils_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-10-29 19:51:32 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/cltypes"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/utils"
|
2022-10-17 17:13:23 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSSZSnappy(t *testing.T) {
|
2023-01-07 11:25:28 +00:00
|
|
|
verySussyMessage := &cltypes.Metadata{
|
2022-10-17 17:13:23 +00:00
|
|
|
SeqNumber: 69, // :D
|
|
|
|
Attnets: 96, // :(
|
|
|
|
}
|
|
|
|
sussyEncoded, err := utils.EncodeSSZSnappy(verySussyMessage)
|
|
|
|
require.NoError(t, err)
|
2023-01-07 11:25:28 +00:00
|
|
|
sussyDecoded := &cltypes.Metadata{}
|
2022-10-17 17:13:23 +00:00
|
|
|
require.NoError(t, utils.DecodeSSZSnappy(sussyDecoded, sussyEncoded))
|
|
|
|
require.Equal(t, verySussyMessage.SeqNumber, sussyDecoded.SeqNumber)
|
|
|
|
require.Equal(t, verySussyMessage.Attnets, sussyDecoded.Attnets)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPlainSnappy(t *testing.T) {
|
|
|
|
msg := common.Hex2Bytes("10103849358111387348383738784374783811111754097864786873478675489485765483936576486387645456876772090909090ff")
|
|
|
|
sussyEncoded := utils.CompressSnappy(msg)
|
|
|
|
sussyDecoded, err := utils.DecompressSnappy(sussyEncoded)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, msg, sussyDecoded)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiteralConverters(t *testing.T) {
|
|
|
|
require.Equal(t, utils.Uint32ToBytes4(600), [4]byte{0x0, 0x0, 0x2, 0x58})
|
|
|
|
require.Equal(t, utils.BytesToBytes4([]byte{10, 23, 56, 7, 8, 5}), [4]byte{10, 23, 56, 7})
|
|
|
|
require.Equal(t, utils.Uint64ToLE(600), []byte{0x58, 0x2, 0x0, 0x0, 0x0, 0x0, 0x00, 0x00})
|
|
|
|
}
|