mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07: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>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package apimiddleware
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestUnmarshalEpochParticipation(t *testing.T) {
|
|
t.Run("ok", func(t *testing.T) {
|
|
b := []byte{3, 3, 0}
|
|
b64 := []byte("\"" + base64.StdEncoding.EncodeToString(b) + "\"")
|
|
ep := EpochParticipation{}
|
|
require.NoError(t, ep.UnmarshalJSON(b64))
|
|
require.Equal(t, 3, len(ep))
|
|
assert.Equal(t, "3", ep[0])
|
|
assert.Equal(t, "3", ep[1])
|
|
assert.Equal(t, "0", ep[2])
|
|
})
|
|
t.Run("incorrect value", func(t *testing.T) {
|
|
ep := EpochParticipation{}
|
|
err := ep.UnmarshalJSON([]byte(":illegal:"))
|
|
require.NotNil(t, err)
|
|
assert.ErrorContains(t, "could not decode epoch participation base64 value", err)
|
|
})
|
|
t.Run("length too small", func(t *testing.T) {
|
|
ep := EpochParticipation{}
|
|
err := ep.UnmarshalJSON([]byte("x"))
|
|
require.NotNil(t, err)
|
|
assert.ErrorContains(t, "epoch participation length must be at least 2", err)
|
|
})
|
|
t.Run("null value", func(t *testing.T) {
|
|
ep := EpochParticipation{}
|
|
require.NoError(t, ep.UnmarshalJSON([]byte("null")))
|
|
assert.DeepEqual(t, EpochParticipation([]string{}), ep)
|
|
})
|
|
}
|