mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
@@ -7,7 +7,7 @@ import (
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
|
||||
@@ -454,12 +454,12 @@ func (b *SignedBeaconBlock) UnmarshalSSZ(buf []byte) error {
|
||||
}
|
||||
|
||||
// Slot returns the respective slot of the block.
|
||||
func (b *BeaconBlock) Slot() types.Slot {
|
||||
func (b *BeaconBlock) Slot() primitives.Slot {
|
||||
return b.slot
|
||||
}
|
||||
|
||||
// ProposerIndex returns the proposer index of the beacon block.
|
||||
func (b *BeaconBlock) ProposerIndex() types.ValidatorIndex {
|
||||
func (b *BeaconBlock) ProposerIndex() primitives.ValidatorIndex {
|
||||
return b.proposerIndex
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
pb "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -142,13 +142,13 @@ func Test_SignedBeaconBlock_UnmarshalSSZ(t *testing.T) {
|
||||
func Test_BeaconBlock_Slot(t *testing.T) {
|
||||
b := &BeaconBlock{}
|
||||
b.SetSlot(128)
|
||||
assert.Equal(t, types.Slot(128), b.Slot())
|
||||
assert.Equal(t, primitives.Slot(128), b.Slot())
|
||||
}
|
||||
|
||||
func Test_BeaconBlock_ProposerIndex(t *testing.T) {
|
||||
b := &BeaconBlock{}
|
||||
b.SetProposerIndex(128)
|
||||
assert.Equal(t, types.ValidatorIndex(128), b.ProposerIndex())
|
||||
assert.Equal(t, primitives.ValidatorIndex(128), b.ProposerIndex())
|
||||
}
|
||||
|
||||
func Test_BeaconBlock_ParentRoot(t *testing.T) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package blocks
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
||||
)
|
||||
@@ -15,13 +15,13 @@ func (b *SignedBeaconBlock) SetSignature(sig []byte) {
|
||||
|
||||
// SetSlot sets the respective slot of the block.
|
||||
// This function is not thread safe, it is only used during block creation.
|
||||
func (b *BeaconBlock) SetSlot(slot types.Slot) {
|
||||
func (b *BeaconBlock) SetSlot(slot primitives.Slot) {
|
||||
b.slot = slot
|
||||
}
|
||||
|
||||
// SetProposerIndex sets the proposer index of the beacon block.
|
||||
// This function is not thread safe, it is only used during block creation.
|
||||
func (b *BeaconBlock) SetProposerIndex(proposerIndex types.ValidatorIndex) {
|
||||
func (b *BeaconBlock) SetProposerIndex(proposerIndex primitives.ValidatorIndex) {
|
||||
b.proposerIndex = proposerIndex
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package testing
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
||||
)
|
||||
@@ -71,7 +71,7 @@ func SetBlockParentRoot(b interfaces.SignedBeaconBlock, pr [32]byte) (interfaces
|
||||
}
|
||||
|
||||
// SetBlockSlot modifies the block's slot.
|
||||
func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) (interfaces.SignedBeaconBlock, error) {
|
||||
func SetBlockSlot(b interfaces.SignedBeaconBlock, s primitives.Slot) (interfaces.SignedBeaconBlock, error) {
|
||||
return blockMutator{
|
||||
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.Slot = s },
|
||||
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.Slot = s },
|
||||
@@ -81,7 +81,7 @@ func SetBlockSlot(b interfaces.SignedBeaconBlock, s types.Slot) (interfaces.Sign
|
||||
}
|
||||
|
||||
// SetProposerIndex modifies the block's proposer index.
|
||||
func SetProposerIndex(b interfaces.SignedBeaconBlock, idx types.ValidatorIndex) (interfaces.SignedBeaconBlock, error) {
|
||||
func SetProposerIndex(b interfaces.SignedBeaconBlock, idx primitives.ValidatorIndex) (interfaces.SignedBeaconBlock, error) {
|
||||
return blockMutator{
|
||||
Phase0: func(bb *eth.SignedBeaconBlock) { bb.Block.ProposerIndex = idx },
|
||||
Altair: func(bb *eth.SignedBeaconBlockAltair) { bb.Block.ProposerIndex = idx },
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
||||
)
|
||||
@@ -61,8 +61,8 @@ type BeaconBlockBody struct {
|
||||
// BeaconBlock is the main beacon block structure. It can represent any block type.
|
||||
type BeaconBlock struct {
|
||||
version int
|
||||
slot types.Slot
|
||||
proposerIndex types.ValidatorIndex
|
||||
slot primitives.Slot
|
||||
proposerIndex primitives.ValidatorIndex
|
||||
parentRoot [field_params.RootLength]byte
|
||||
stateRoot [field_params.RootLength]byte
|
||||
body *BeaconBlockBody
|
||||
|
||||
@@ -3,7 +3,7 @@ package interfaces
|
||||
import (
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
|
||||
@@ -37,10 +37,10 @@ type SignedBeaconBlock interface {
|
||||
// BeaconBlock describes an interface which states the methods
|
||||
// employed by an object that is a beacon block.
|
||||
type BeaconBlock interface {
|
||||
Slot() types.Slot
|
||||
SetSlot(slot types.Slot)
|
||||
ProposerIndex() types.ValidatorIndex
|
||||
SetProposerIndex(idx types.ValidatorIndex)
|
||||
Slot() primitives.Slot
|
||||
SetSlot(slot primitives.Slot)
|
||||
ProposerIndex() primitives.ValidatorIndex
|
||||
SetProposerIndex(idx primitives.ValidatorIndex)
|
||||
ParentRoot() [field_params.RootLength]byte
|
||||
SetParentRoot([]byte)
|
||||
StateRoot() [field_params.RootLength]byte
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
ssz "github.com/prysmaticlabs/fastssz"
|
||||
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -102,7 +102,7 @@ type BeaconBlock struct {
|
||||
Htr [field_params.RootLength]byte
|
||||
HtrErr error
|
||||
BeaconBlockBody interfaces.BeaconBlockBody
|
||||
BlockSlot types.Slot
|
||||
BlockSlot primitives.Slot
|
||||
}
|
||||
|
||||
func (BeaconBlock) AsSignRequestObject() (validatorpb.SignRequestObject, error) {
|
||||
@@ -113,11 +113,11 @@ func (m BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
|
||||
return m.Htr, m.HtrErr
|
||||
}
|
||||
|
||||
func (m BeaconBlock) Slot() types.Slot {
|
||||
func (m BeaconBlock) Slot() primitives.Slot {
|
||||
return m.BlockSlot
|
||||
}
|
||||
|
||||
func (BeaconBlock) ProposerIndex() types.ValidatorIndex {
|
||||
func (BeaconBlock) ProposerIndex() primitives.ValidatorIndex {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -173,11 +173,11 @@ func (BeaconBlock) ToBlinded() (interfaces.BeaconBlock, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (BeaconBlock) SetSlot(_ types.Slot) {
|
||||
func (BeaconBlock) SetSlot(_ primitives.Slot) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (BeaconBlock) SetProposerIndex(_ types.ValidatorIndex) {
|
||||
func (BeaconBlock) SetProposerIndex(_ primitives.ValidatorIndex) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package types_test
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
mathprysm "github.com/prysmaticlabs/prysm/v3/math"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestMaxEpoch(t *testing.T) {
|
||||
require.Equal(t, types.Epoch(0), types.MaxEpoch(0, 0))
|
||||
require.Equal(t, types.Epoch(1), types.MaxEpoch(1, 0))
|
||||
require.Equal(t, types.Epoch(1), types.MaxEpoch(0, 1))
|
||||
require.Equal(t, types.Epoch(1000), types.MaxEpoch(100, 1000))
|
||||
require.Equal(t, primitives.Epoch(0), primitives.MaxEpoch(0, 0))
|
||||
require.Equal(t, primitives.Epoch(1), primitives.MaxEpoch(1, 0))
|
||||
require.Equal(t, primitives.Epoch(1), primitives.MaxEpoch(0, 1))
|
||||
require.Equal(t, primitives.Epoch(1000), primitives.MaxEpoch(100, 1000))
|
||||
}
|
||||
|
||||
func TestEpoch_Mul(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Epoch
|
||||
res primitives.Epoch
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 0, b: 1, res: 0},
|
||||
@@ -36,13 +36,13 @@ func TestEpoch_Mul(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Epoch(%v).Mul(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Epoch
|
||||
var res primitives.Epoch
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Epoch(tt.a).Mul(tt.b)
|
||||
res = primitives.Epoch(tt.a).Mul(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Epoch(tt.a).Mul(tt.b)
|
||||
res = primitives.Epoch(tt.a).Mul(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Epoch.Mul() = %v, want %v", res, tt.res)
|
||||
@@ -54,7 +54,7 @@ func TestEpoch_Mul(t *testing.T) {
|
||||
func TestEpoch_Div(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Epoch
|
||||
res primitives.Epoch
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 0, b: 1, res: 0},
|
||||
@@ -69,13 +69,13 @@ func TestEpoch_Div(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Epoch(%v).Div(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Epoch
|
||||
var res primitives.Epoch
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Epoch(tt.a).Div(tt.b)
|
||||
res = primitives.Epoch(tt.a).Div(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Epoch(tt.a).Div(tt.b)
|
||||
res = primitives.Epoch(tt.a).Div(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Epoch.Div() = %v, want %v", res, tt.res)
|
||||
@@ -87,7 +87,7 @@ func TestEpoch_Div(t *testing.T) {
|
||||
func TestEpoch_Add(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Epoch
|
||||
res primitives.Epoch
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 0, b: 1, res: 1},
|
||||
@@ -103,26 +103,26 @@ func TestEpoch_Add(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Epoch(%v).Add(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Epoch
|
||||
var res primitives.Epoch
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Epoch(tt.a).Add(tt.b)
|
||||
res = primitives.Epoch(tt.a).Add(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Epoch(tt.a).Add(tt.b)
|
||||
res = primitives.Epoch(tt.a).Add(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Epoch.Add() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Epoch(%v).AddEpoch(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Epoch
|
||||
var res primitives.Epoch
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Epoch(tt.a).AddEpoch(types.Epoch(tt.b))
|
||||
res = primitives.Epoch(tt.a).AddEpoch(primitives.Epoch(tt.b))
|
||||
})
|
||||
} else {
|
||||
res = types.Epoch(tt.a).AddEpoch(types.Epoch(tt.b))
|
||||
res = primitives.Epoch(tt.a).AddEpoch(primitives.Epoch(tt.b))
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Epoch.AddEpoch() = %v, want %v", res, tt.res)
|
||||
@@ -134,7 +134,7 @@ func TestEpoch_Add(t *testing.T) {
|
||||
func TestEpoch_Sub(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Epoch
|
||||
res primitives.Epoch
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 1, b: 0, res: 1},
|
||||
@@ -152,13 +152,13 @@ func TestEpoch_Sub(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Epoch(%v).Sub(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Epoch
|
||||
var res primitives.Epoch
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Epoch(tt.a).Sub(tt.b)
|
||||
res = primitives.Epoch(tt.a).Sub(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Epoch(tt.a).Sub(tt.b)
|
||||
res = primitives.Epoch(tt.a).Sub(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Epoch.Sub() = %v, want %v", res, tt.res)
|
||||
@@ -170,7 +170,7 @@ func TestEpoch_Sub(t *testing.T) {
|
||||
func TestEpoch_Mod(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Epoch
|
||||
res primitives.Epoch
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 1, b: 0, res: 0, panicMsg: mathprysm.ErrDivByZero.Error()},
|
||||
@@ -190,13 +190,13 @@ func TestEpoch_Mod(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Epoch(%v).Mod(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Epoch
|
||||
var res primitives.Epoch
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Epoch(tt.a).Mod(tt.b)
|
||||
res = primitives.Epoch(tt.a).Mod(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Epoch(tt.a).Mod(tt.b)
|
||||
res = primitives.Epoch(tt.a).Mod(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Epoch.Mod() = %v, want %v", res, tt.res)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types_test
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
mathprysm "github.com/prysmaticlabs/prysm/v3/math"
|
||||
)
|
||||
|
||||
func TestSlot_Casting(t *testing.T) {
|
||||
slot := types.Slot(42)
|
||||
slot := primitives.Slot(42)
|
||||
|
||||
t.Run("time.Duration", func(t *testing.T) {
|
||||
if uint64(time.Duration(slot)) != uint64(slot) {
|
||||
@@ -21,20 +21,20 @@ func TestSlot_Casting(t *testing.T) {
|
||||
|
||||
t.Run("floats", func(t *testing.T) {
|
||||
var x1 float32 = 42.2
|
||||
if types.Slot(x1) != slot {
|
||||
t.Errorf("Unequal: %v = %v", types.Slot(x1), slot)
|
||||
if primitives.Slot(x1) != slot {
|
||||
t.Errorf("Unequal: %v = %v", primitives.Slot(x1), slot)
|
||||
}
|
||||
|
||||
var x2 = 42.2
|
||||
if types.Slot(x2) != slot {
|
||||
t.Errorf("Unequal: %v = %v", types.Slot(x2), slot)
|
||||
if primitives.Slot(x2) != slot {
|
||||
t.Errorf("Unequal: %v = %v", primitives.Slot(x2), slot)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("int", func(t *testing.T) {
|
||||
var x = 42
|
||||
if types.Slot(x) != slot {
|
||||
t.Errorf("Unequal: %v = %v", types.Slot(x), slot)
|
||||
if primitives.Slot(x) != slot {
|
||||
t.Errorf("Unequal: %v = %v", primitives.Slot(x), slot)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func TestSlot_Casting(t *testing.T) {
|
||||
func TestSlot_Mul(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Slot
|
||||
res primitives.Slot
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 0, b: 1, res: 0},
|
||||
@@ -58,33 +58,33 @@ func TestSlot_Mul(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Slot(%v).Mul(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).Mul(tt.b)
|
||||
res = primitives.Slot(tt.a).Mul(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).Mul(tt.b)
|
||||
res = primitives.Slot(tt.a).Mul(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.Mul() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).MulSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).MulSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).MulSlot(primitives.Slot(tt.b))
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).MulSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).MulSlot(primitives.Slot(tt.b))
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.MulSlot() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).SafeMulSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
res, err := types.Slot(tt.a).SafeMulSlot(types.Slot(tt.b))
|
||||
res, err := primitives.Slot(tt.a).SafeMulSlot(primitives.Slot(tt.b))
|
||||
if tt.panicMsg != "" && (err == nil || err.Error() != tt.panicMsg) {
|
||||
t.Errorf("Expected error not thrown, wanted: %v, got: %v", tt.panicMsg, err)
|
||||
return
|
||||
@@ -99,7 +99,7 @@ func TestSlot_Mul(t *testing.T) {
|
||||
func TestSlot_Div(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Slot
|
||||
res primitives.Slot
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 0, b: 1, res: 0},
|
||||
@@ -114,33 +114,33 @@ func TestSlot_Div(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Slot(%v).Div(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).Div(tt.b)
|
||||
res = primitives.Slot(tt.a).Div(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).Div(tt.b)
|
||||
res = primitives.Slot(tt.a).Div(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.Div() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).DivSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).DivSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).DivSlot(primitives.Slot(tt.b))
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).DivSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).DivSlot(primitives.Slot(tt.b))
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.DivSlot() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).SafeDivSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
res, err := types.Slot(tt.a).SafeDivSlot(types.Slot(tt.b))
|
||||
res, err := primitives.Slot(tt.a).SafeDivSlot(primitives.Slot(tt.b))
|
||||
if tt.panicMsg != "" && (err == nil || err.Error() != tt.panicMsg) {
|
||||
t.Errorf("Expected error not thrown, wanted: %v, got: %v", tt.panicMsg, err)
|
||||
return
|
||||
@@ -155,7 +155,7 @@ func TestSlot_Div(t *testing.T) {
|
||||
func TestSlot_Add(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Slot
|
||||
res primitives.Slot
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 0, b: 1, res: 1},
|
||||
@@ -171,33 +171,33 @@ func TestSlot_Add(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Slot(%v).Add(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).Add(tt.b)
|
||||
res = primitives.Slot(tt.a).Add(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).Add(tt.b)
|
||||
res = primitives.Slot(tt.a).Add(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.Add() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).AddSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).AddSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).AddSlot(primitives.Slot(tt.b))
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).AddSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).AddSlot(primitives.Slot(tt.b))
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.AddSlot() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).SafeAddSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
res, err := types.Slot(tt.a).SafeAddSlot(types.Slot(tt.b))
|
||||
res, err := primitives.Slot(tt.a).SafeAddSlot(primitives.Slot(tt.b))
|
||||
if tt.panicMsg != "" && (err == nil || err.Error() != tt.panicMsg) {
|
||||
t.Errorf("Expected error not thrown, wanted: %v, got: %v", tt.panicMsg, err)
|
||||
return
|
||||
@@ -212,7 +212,7 @@ func TestSlot_Add(t *testing.T) {
|
||||
func TestSlot_Sub(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Slot
|
||||
res primitives.Slot
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 1, b: 0, res: 1},
|
||||
@@ -230,33 +230,33 @@ func TestSlot_Sub(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Slot(%v).Sub(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).Sub(tt.b)
|
||||
res = primitives.Slot(tt.a).Sub(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).Sub(tt.b)
|
||||
res = primitives.Slot(tt.a).Sub(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.Sub() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).SubSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).SubSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).SubSlot(primitives.Slot(tt.b))
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).SubSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).SubSlot(primitives.Slot(tt.b))
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.SubSlot() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).SafeSubSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
res, err := types.Slot(tt.a).SafeSubSlot(types.Slot(tt.b))
|
||||
res, err := primitives.Slot(tt.a).SafeSubSlot(primitives.Slot(tt.b))
|
||||
if tt.panicMsg != "" && (err == nil || err.Error() != tt.panicMsg) {
|
||||
t.Errorf("Expected error not thrown, wanted: %v, got: %v", tt.panicMsg, err)
|
||||
return
|
||||
@@ -271,7 +271,7 @@ func TestSlot_Sub(t *testing.T) {
|
||||
func TestSlot_Mod(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b uint64
|
||||
res types.Slot
|
||||
res primitives.Slot
|
||||
panicMsg string
|
||||
}{
|
||||
{a: 1, b: 0, res: 0, panicMsg: mathprysm.ErrDivByZero.Error()},
|
||||
@@ -291,33 +291,33 @@ func TestSlot_Mod(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("Slot(%v).Mod(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).Mod(tt.b)
|
||||
res = primitives.Slot(tt.a).Mod(tt.b)
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).Mod(tt.b)
|
||||
res = primitives.Slot(tt.a).Mod(tt.b)
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.Mod() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).ModSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
var res types.Slot
|
||||
var res primitives.Slot
|
||||
if tt.panicMsg != "" {
|
||||
assertPanic(t, tt.panicMsg, func() {
|
||||
res = types.Slot(tt.a).ModSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).ModSlot(primitives.Slot(tt.b))
|
||||
})
|
||||
} else {
|
||||
res = types.Slot(tt.a).ModSlot(types.Slot(tt.b))
|
||||
res = primitives.Slot(tt.a).ModSlot(primitives.Slot(tt.b))
|
||||
}
|
||||
if tt.res != res {
|
||||
t.Errorf("Slot.Mod() = %v, want %v", res, tt.res)
|
||||
}
|
||||
})
|
||||
t.Run(fmt.Sprintf("Slot(%v).SafeModSlot(%v) = %v", tt.a, tt.b, tt.res), func(t *testing.T) {
|
||||
res, err := types.Slot(tt.a).SafeModSlot(types.Slot(tt.b))
|
||||
res, err := primitives.Slot(tt.a).SafeModSlot(primitives.Slot(tt.b))
|
||||
if tt.panicMsg != "" && (err == nil || err.Error() != tt.panicMsg) {
|
||||
t.Errorf("Expected error not thrown, wanted: %v, got: %v", tt.panicMsg, err)
|
||||
return
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
fssz "github.com/prysmaticlabs/fastssz"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package types_test
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
func TestSSZBytes_HashTreeRoot(t *testing.T) {
|
||||
@@ -36,7 +36,7 @@ func TestSSZBytes_HashTreeRoot(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := types.SSZBytes(tt.actualValue)
|
||||
s := primitives.SSZBytes(tt.actualValue)
|
||||
htr, err := s.HashTreeRoot()
|
||||
if err != nil {
|
||||
t.Errorf("SSZBytes.HashTreeRoot() unexpected error = %v", err)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package types_test
|
||||
package primitives_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
func TestSSZUint64_Limit(t *testing.T) {
|
||||
sszType := types.SSZUint64(0)
|
||||
sszType := primitives.SSZUint64(0)
|
||||
var serializedObj [7]byte
|
||||
err := sszType.UnmarshalSSZ(serializedObj[:])
|
||||
if err == nil || !strings.Contains(err.Error(), "expected buffer of length") {
|
||||
@@ -19,13 +19,13 @@ func TestSSZUint64_Limit(t *testing.T) {
|
||||
|
||||
func TestSSZUint64_RoundTrip(t *testing.T) {
|
||||
fixedVal := uint64(8)
|
||||
sszVal := types.SSZUint64(fixedVal)
|
||||
sszVal := primitives.SSZUint64(fixedVal)
|
||||
|
||||
marshalledObj, err := sszVal.MarshalSSZ()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
newVal := types.SSZUint64(0)
|
||||
newVal := primitives.SSZUint64(0)
|
||||
|
||||
err = newVal.UnmarshalSSZ(marshalledObj)
|
||||
if err != nil {
|
||||
@@ -68,7 +68,7 @@ func TestSSZUint64(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var s types.SSZUint64
|
||||
var s primitives.SSZUint64
|
||||
if err := s.UnmarshalSSZ(tt.serializedBytes); (err != nil) != tt.wantErr {
|
||||
t.Errorf("SSZUint64.UnmarshalSSZ() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package primitives
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
Reference in New Issue
Block a user