mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package encoder
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestReadVarint(t *testing.T) {
|
|
data := []byte("foobar data")
|
|
prefixedData := append(proto.EncodeVarint(uint64(len(data))), data...)
|
|
|
|
vi, err := readVarint(bytes.NewBuffer(prefixedData))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, uint64(len(data)), vi, "Received wrong varint")
|
|
}
|
|
|
|
func TestReadVarint_ExceedsMaxLength(t *testing.T) {
|
|
fByte := byte(1 << 7)
|
|
// Terminating byte.
|
|
tByte := byte(1 << 6)
|
|
var header []byte
|
|
for i := 0; i < 9; i++ {
|
|
header = append(header, fByte)
|
|
}
|
|
header = append(header, tByte)
|
|
_, err := readVarint(bytes.NewBuffer(header))
|
|
require.NoError(t, err, "Expected no error from reading valid header")
|
|
length := len(header)
|
|
// Add an additional byte to make header invalid.
|
|
header = append(header[:length-1], []byte{fByte, tByte}...)
|
|
|
|
_, err = readVarint(bytes.NewBuffer(header))
|
|
assert.ErrorContains(t, errExcessMaxLength.Error(), err, "Expected error from reading invalid header")
|
|
}
|