2022-05-20 17:05:39 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
2022-05-20 17:05:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsInvalidBlock(t *testing.T) {
|
2022-07-09 20:51:03 +00:00
|
|
|
require.Equal(t, true, IsInvalidBlock(ErrInvalidPayload)) // Already wrapped.
|
|
|
|
err := invalidBlock{error: ErrInvalidPayload}
|
2022-05-20 17:05:39 +00:00
|
|
|
require.Equal(t, true, IsInvalidBlock(err))
|
|
|
|
|
|
|
|
newErr := errors.Wrap(err, "wrap me")
|
|
|
|
require.Equal(t, true, IsInvalidBlock(newErr))
|
2022-07-25 13:45:03 +00:00
|
|
|
require.DeepEqual(t, [][32]byte(nil), InvalidAncestorRoots(err))
|
2022-05-20 17:05:39 +00:00
|
|
|
}
|
2022-07-09 20:51:03 +00:00
|
|
|
|
|
|
|
func TestInvalidBlockRoot(t *testing.T) {
|
|
|
|
require.Equal(t, [32]byte{}, InvalidBlockRoot(ErrUndefinedExecutionEngineError))
|
|
|
|
require.Equal(t, [32]byte{}, InvalidBlockRoot(ErrInvalidPayload))
|
|
|
|
|
|
|
|
err := invalidBlock{error: ErrInvalidPayload, root: [32]byte{'a'}}
|
|
|
|
require.Equal(t, [32]byte{'a'}, InvalidBlockRoot(err))
|
2022-07-25 13:45:03 +00:00
|
|
|
require.DeepEqual(t, [][32]byte(nil), InvalidAncestorRoots(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidRoots(t *testing.T) {
|
|
|
|
roots := [][32]byte{{'d'}, {'b'}, {'c'}}
|
|
|
|
err := invalidBlock{error: ErrInvalidPayload, root: [32]byte{'a'}, invalidAncestorRoots: roots}
|
|
|
|
|
|
|
|
require.Equal(t, true, IsInvalidBlock(err))
|
|
|
|
require.Equal(t, [32]byte{'a'}, InvalidBlockRoot(err))
|
|
|
|
require.DeepEqual(t, roots, InvalidAncestorRoots(err))
|
2022-07-09 20:51:03 +00:00
|
|
|
}
|