Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Shared/Testutil into Testing #9659

Merged
merged 6 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
util pkg
  • Loading branch information
rauljordan committed Sep 23, 2021
commit a84efcc833d99d726355f1b8dcdf7adc3902f9d6
2 changes: 1 addition & 1 deletion async/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//testing:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"//testing/util:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
Expand Down
6 changes: 3 additions & 3 deletions async/debounce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"time"

"github.com/prysmaticlabs/prysm/async"
testing2 "github.com/prysmaticlabs/prysm/testing"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
)

func TestDebounce_NoEvents(t *testing.T) {
Expand All @@ -30,7 +30,7 @@ func TestDebounce_NoEvents(t *testing.T) {
})
wg.Done()
}()
if testing2.WaitTimeout(wg, interval*2) {
if util.WaitTimeout(wg, interval*2) {
t.Fatalf("Test should have exited by now, timed out")
}
assert.Equal(t, 0, timesHandled, "Wrong number of handled calls")
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestDebounce_CtxClosing(t *testing.T) {
})
wg.Done()
}()
if testing2.WaitTimeout(wg, interval*2) {
if util.WaitTimeout(wg, interval*2) {
t.Fatalf("Test should have exited by now, timed out")
}
assert.Equal(t, 0, timesHandled, "Wrong number of handled calls")
Expand Down
18 changes: 9 additions & 9 deletions beacon-chain/blockchain/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
testing2 "github.com/prysmaticlabs/prysm/testing"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -122,7 +122,7 @@ func TestHeadRoot_UseDB(t *testing.T) {
beaconDB := testDB.SetupDB(t)
c := &Service{cfg: &Config{BeaconDB: beaconDB}}
c.head = &head{root: params.BeaconConfig().ZeroHash}
b := testing2.NewBeaconBlock()
b := util.NewBeaconBlock()
br, err := b.Block.HashTreeRoot()
require.NoError(t, err)
require.NoError(t, beaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(b)))
Expand All @@ -134,7 +134,7 @@ func TestHeadRoot_UseDB(t *testing.T) {
}

func TestHeadBlock_CanRetrieve(t *testing.T) {
b := testing2.NewBeaconBlock()
b := util.NewBeaconBlock()
b.Block.Slot = 1
s, err := v1.InitializeFromProto(&ethpb.BeaconState{})
require.NoError(t, err)
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestIsCanonical_Ok(t *testing.T) {
beaconDB := testDB.SetupDB(t)
c := setupBeaconChain(t, beaconDB)

blk := testing2.NewBeaconBlock()
blk := util.NewBeaconBlock()
blk.Block.Slot = 0
root, err := blk.Block.HashTreeRoot()
require.NoError(t, err)
Expand All @@ -233,7 +233,7 @@ func TestIsCanonical_Ok(t *testing.T) {
}

func TestService_HeadValidatorsIndices(t *testing.T) {
s, _ := testing2.DeterministicGenesisState(t, 10)
s, _ := util.DeterministicGenesisState(t, 10)
c := &Service{}

c.head = &head{}
Expand All @@ -248,7 +248,7 @@ func TestService_HeadValidatorsIndices(t *testing.T) {
}

func TestService_HeadSeed(t *testing.T) {
s, _ := testing2.DeterministicGenesisState(t, 1)
s, _ := util.DeterministicGenesisState(t, 1)
c := &Service{}
seed, err := helpers.Seed(s, 0, params.BeaconConfig().DomainBeaconAttester)
require.NoError(t, err)
Expand All @@ -265,7 +265,7 @@ func TestService_HeadSeed(t *testing.T) {
}

func TestService_HeadGenesisValidatorRoot(t *testing.T) {
s, _ := testing2.DeterministicGenesisState(t, 1)
s, _ := util.DeterministicGenesisState(t, 1)
c := &Service{}

c.head = &head{}
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestService_ChainHeads(t *testing.T) {
}

func TestService_HeadPublicKeyToValidatorIndex(t *testing.T) {
s, _ := testing2.DeterministicGenesisState(t, 10)
s, _ := util.DeterministicGenesisState(t, 10)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -314,7 +314,7 @@ func TestService_HeadPublicKeyToValidatorIndex(t *testing.T) {
}

func TestService_HeadValidatorIndexToPublicKey(t *testing.T) {
s, _ := testing2.DeterministicGenesisState(t, 10)
s, _ := util.DeterministicGenesisState(t, 10)
c := &Service{}
c.head = &head{state: s}

Expand Down
18 changes: 9 additions & 9 deletions beacon-chain/blockchain/head_sync_committee_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/config/params"
testing2 "github.com/prysmaticlabs/prysm/testing"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
)

func TestService_headSyncCommitteeFetcher_Errors(t *testing.T) {
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestService_HeadDomainFetcher_Errors(t *testing.T) {
}

func TestService_HeadSyncCommitteeIndices(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -75,7 +75,7 @@ func TestService_HeadSyncCommitteeIndices(t *testing.T) {
}

func TestService_headCurrentSyncCommitteeIndices(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -89,7 +89,7 @@ func TestService_headCurrentSyncCommitteeIndices(t *testing.T) {
}

func TestService_headNextSyncCommitteeIndices(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -103,7 +103,7 @@ func TestService_headNextSyncCommitteeIndices(t *testing.T) {
}

func TestService_HeadSyncCommitteePubKeys(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -118,7 +118,7 @@ func TestService_HeadSyncCommitteePubKeys(t *testing.T) {
}

func TestService_HeadSyncCommitteeDomain(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -132,7 +132,7 @@ func TestService_HeadSyncCommitteeDomain(t *testing.T) {
}

func TestService_HeadSyncContributionProofDomain(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -146,7 +146,7 @@ func TestService_HeadSyncContributionProofDomain(t *testing.T) {
}

func TestService_HeadSyncSelectionProofDomain(t *testing.T) {
s, _ := testing2.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
s, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().TargetCommitteeSize)
c := &Service{}
c.head = &head{state: s}

Expand All @@ -164,7 +164,7 @@ func TestSyncCommitteeHeadStateCache_RoundTrip(t *testing.T) {
t.Cleanup(func() {
syncCommitteeHeadStateCache = cache.NewSyncCommitteeHeadState()
})
beaconState, _ := testing2.DeterministicGenesisStateAltair(t, 100)
beaconState, _ := util.DeterministicGenesisStateAltair(t, 100)
require.NoError(t, beaconState.SetSlot(100))
cachedState, err := c.Get(101)
require.ErrorContains(t, cache.ErrNotFound.Error(), err)
Expand Down
32 changes: 16 additions & 16 deletions beacon-chain/blockchain/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
testing2 "github.com/prysmaticlabs/prysm/testing"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
logTest "github.com/sirupsen/logrus/hooks/test"
)

Expand All @@ -38,9 +38,9 @@ func TestSaveHead_Different(t *testing.T) {
beaconDB := testDB.SetupDB(t)
service := setupBeaconChain(t, beaconDB)

testing2.NewBeaconBlock()
util.NewBeaconBlock()
oldBlock := wrapper.WrappedPhase0SignedBeaconBlock(
testing2.NewBeaconBlock(),
util.NewBeaconBlock(),
)
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), oldBlock))
oldRoot, err := oldBlock.Block().HashTreeRoot()
Expand All @@ -51,14 +51,14 @@ func TestSaveHead_Different(t *testing.T) {
block: oldBlock,
}

newHeadSignedBlock := testing2.NewBeaconBlock()
newHeadSignedBlock := util.NewBeaconBlock()
newHeadSignedBlock.Block.Slot = 1
newHeadBlock := newHeadSignedBlock.Block

require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(newHeadSignedBlock)))
newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err)
headState, err := testing2.NewBeaconState()
headState, err := util.NewBeaconState()
require.NoError(t, err)
require.NoError(t, headState.SetSlot(1))
require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(context.Background(), &ethpb.StateSummary{Slot: 1, Root: newRoot[:]}))
Expand All @@ -81,7 +81,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
service := setupBeaconChain(t, beaconDB)

oldBlock := wrapper.WrappedPhase0SignedBeaconBlock(
testing2.NewBeaconBlock(),
util.NewBeaconBlock(),
)
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), oldBlock))
oldRoot, err := oldBlock.Block().HashTreeRoot()
Expand All @@ -93,15 +93,15 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
}

reorgChainParent := [32]byte{'B'}
newHeadSignedBlock := testing2.NewBeaconBlock()
newHeadSignedBlock := util.NewBeaconBlock()
newHeadSignedBlock.Block.Slot = 1
newHeadSignedBlock.Block.ParentRoot = reorgChainParent[:]
newHeadBlock := newHeadSignedBlock.Block

require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(newHeadSignedBlock)))
newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err)
headState, err := testing2.NewBeaconState()
headState, err := util.NewBeaconState()
require.NoError(t, err)
require.NoError(t, headState.SetSlot(1))
require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(context.Background(), &ethpb.StateSummary{Slot: 1, Root: newRoot[:]}))
Expand All @@ -124,7 +124,7 @@ func TestCacheJustifiedStateBalances_CanCache(t *testing.T) {
beaconDB := testDB.SetupDB(t)
service := setupBeaconChain(t, beaconDB)

state, _ := testing2.DeterministicGenesisState(t, 100)
state, _ := util.DeterministicGenesisState(t, 100)
r := [32]byte{'a'}
require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(context.Background(), &ethpb.StateSummary{Root: r[:]}))
require.NoError(t, service.cfg.BeaconDB.SaveState(context.Background(), state, r))
Expand All @@ -136,7 +136,7 @@ func TestUpdateHead_MissingJustifiedRoot(t *testing.T) {
beaconDB := testDB.SetupDB(t)
service := setupBeaconChain(t, beaconDB)

b := testing2.NewBeaconBlock()
b := util.NewBeaconBlock()
require.NoError(t, service.cfg.BeaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(b)))
r, err := b.Block.HashTreeRoot()
require.NoError(t, err)
Expand All @@ -150,7 +150,7 @@ func TestUpdateHead_MissingJustifiedRoot(t *testing.T) {

func Test_notifyNewHeadEvent(t *testing.T) {
t.Run("genesis_state_root", func(t *testing.T) {
bState, _ := testing2.DeterministicGenesisState(t, 10)
bState, _ := util.DeterministicGenesisState(t, 10)
notifier := &mock.MockStateNotifier{RecordEvents: true}
srv := &Service{
cfg: &Config{
Expand Down Expand Up @@ -178,7 +178,7 @@ func Test_notifyNewHeadEvent(t *testing.T) {
require.DeepSSZEqual(t, wanted, eventHead)
})
t.Run("non_genesis_values", func(t *testing.T) {
bState, _ := testing2.DeterministicGenesisState(t, 10)
bState, _ := util.DeterministicGenesisState(t, 10)
notifier := &mock.MockStateNotifier{RecordEvents: true}
genesisRoot := [32]byte{1}
srv := &Service{
Expand Down Expand Up @@ -220,8 +220,8 @@ func TestSaveOrphanedAtts(t *testing.T) {
})
defer resetCfg()

genesis, keys := testing2.DeterministicGenesisState(t, 64)
b, err := testing2.GenerateFullBlock(genesis, keys, testing2.DefaultBlockGenConfig(), 1)
genesis, keys := util.DeterministicGenesisState(t, 64)
b, err := util.GenerateFullBlock(genesis, keys, util.DefaultBlockGenConfig(), 1)
assert.NoError(t, err)
r, err := b.Block.HashTreeRoot()
require.NoError(t, err)
Expand All @@ -246,8 +246,8 @@ func TestSaveOrphanedAtts_CanFilter(t *testing.T) {
})
defer resetCfg()

genesis, keys := testing2.DeterministicGenesisState(t, 64)
b, err := testing2.GenerateFullBlock(genesis, keys, testing2.DefaultBlockGenConfig(), 1)
genesis, keys := util.DeterministicGenesisState(t, 64)
b, err := util.GenerateFullBlock(genesis, keys, util.DefaultBlockGenConfig(), 1)
assert.NoError(t, err)
r, err := b.Block.HashTreeRoot()
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/blockchain/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
testing2 "github.com/prysmaticlabs/prysm/testing"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
)

func TestService_TreeHandler(t *testing.T) {
Expand All @@ -22,7 +22,7 @@ func TestService_TreeHandler(t *testing.T) {

ctx := context.Background()
beaconDB := testDB.SetupDB(t)
headState, err := testing2.NewBeaconState()
headState, err := util.NewBeaconState()
require.NoError(t, err)
require.NoError(t, headState.SetBalances([]uint64{params.BeaconConfig().GweiPerEth}))
cfg := &Config{
Expand All @@ -38,7 +38,7 @@ func TestService_TreeHandler(t *testing.T) {
require.NoError(t, err)
require.NoError(t, s.cfg.ForkChoiceStore.ProcessBlock(ctx, 0, [32]byte{'a'}, [32]byte{'g'}, [32]byte{'c'}, 0, 0))
require.NoError(t, s.cfg.ForkChoiceStore.ProcessBlock(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'c'}, 0, 0))
s.setHead([32]byte{'a'}, wrapper.WrappedPhase0SignedBeaconBlock(testing2.NewBeaconBlock()), headState)
s.setHead([32]byte{'a'}, wrapper.WrappedPhase0SignedBeaconBlock(util.NewBeaconBlock()), headState)

rr := httptest.NewRecorder()
handler := http.HandlerFunc(s.TreeHandler)
Expand Down
Loading