Remove duplicated StartSlot (#7484)

* Remove duplicated StartSlot

* Update existing tests

* Gazelle

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terence tsao 2020-10-09 14:23:49 -07:00 committed by GitHub
parent a3a77ab5a8
commit e15a0b08aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 19 deletions

View File

@ -43,6 +43,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/testutil/assert:go_default_library",

View File

@ -6,6 +6,7 @@ import (
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
@ -358,11 +359,15 @@ func TestDetect_detectProposerSlashing(t *testing.T) {
incomingBlk *ethpb.SignedBeaconBlockHeader
slashing *ethpb.ProposerSlashing
}
sigBlk1slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
s0, err := helpers.StartSlot(0)
require.NoError(t, err)
sigBlk2slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
sigBlk1slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
sigBlk1epoch1, err := testDetect.SignedBlockHeader(testDetect.StartSlot(1), 0)
sigBlk2slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
s1, err := helpers.StartSlot(1)
require.NoError(t, err)
sigBlk1epoch1, err := testDetect.SignedBlockHeader(s1, 0)
require.NoError(t, err)
tests := []testStruct{
{
@ -421,18 +426,20 @@ func TestDetect_detectProposerSlashingNoUpdate(t *testing.T) {
noUpdtaeBlk *ethpb.BeaconBlockHeader
slashable bool
}
sigBlk1slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
s0, err := helpers.StartSlot(0)
require.NoError(t, err)
blk1slot0, err := testDetect.BlockHeader(testDetect.StartSlot(0), 0)
sigBlk1slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
blk2slot0, err := testDetect.BlockHeader(testDetect.StartSlot(0), 0)
blk1slot0, err := testDetect.BlockHeader(s0, 0)
require.NoError(t, err)
blk2slot0, err := testDetect.BlockHeader(s0, 0)
require.NoError(t, err)
diffRoot := [32]byte{1, 1, 1}
blk2slot0.ParentRoot = diffRoot[:]
blk3slot0, err := testDetect.BlockHeader(testDetect.StartSlot(0), 0)
blk3slot0, err := testDetect.BlockHeader(s0, 0)
require.NoError(t, err)
blk3slot0.StateRoot = diffRoot[:]
blk4slot0, err := testDetect.BlockHeader(testDetect.StartSlot(0), 0)
blk4slot0, err := testDetect.BlockHeader(s0, 0)
require.NoError(t, err)
blk4slot0.BodyRoot = diffRoot[:]
tests := []testStruct{

View File

@ -22,6 +22,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//shared/testutil/assert:go_default_library",
"//shared/testutil/require:go_default_library",
"//slasher/db/testing:go_default_library",

View File

@ -5,6 +5,7 @@ import (
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
testDB "github.com/prysmaticlabs/prysm/slasher/db/testing"
@ -21,13 +22,17 @@ func TestProposalsDetector_DetectSlashingsForBlockHeaders(t *testing.T) {
incomingBlk *ethpb.SignedBeaconBlockHeader
slashing *ethpb.ProposerSlashing
}
blk1slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
s0, err := helpers.StartSlot(0)
require.NoError(t, err)
blk2slot0, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0), 0)
blk1slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
blk1slot1, err := testDetect.SignedBlockHeader(testDetect.StartSlot(0)+1, 0)
blk2slot0, err := testDetect.SignedBlockHeader(s0, 0)
require.NoError(t, err)
blk1epoch1, err := testDetect.SignedBlockHeader(testDetect.StartSlot(1), 0)
blk1slot1, err := testDetect.SignedBlockHeader(s0+1, 0)
require.NoError(t, err)
s1, err := helpers.StartSlot(1)
require.NoError(t, err)
blk1epoch1, err := testDetect.SignedBlockHeader(s1, 0)
require.NoError(t, err)
tests := []testStruct{
{

View File

@ -6,7 +6,6 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/slasher/detection/testing",
visibility = ["//visibility:public"],
deps = [
"//shared/params:go_default_library",
"//shared/rand:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
],

View File

@ -4,7 +4,6 @@ package testing
import (
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/rand"
)
@ -46,8 +45,3 @@ func genRandomByteArray(length int) ([]byte, error) {
_, err := randGen.Read(blk)
return blk, err
}
// StartSlot returns the first slot of a given epoch.
func StartSlot(epoch uint64) uint64 {
return epoch * params.BeaconConfig().SlotsPerEpoch
}