Skip to content

Commit

Permalink
Small refactors to sync tests
Browse files Browse the repository at this point in the history
- Use an underscore for unused function parameters.
- Use a tagged switch instead of if statement where appropriate.
  • Loading branch information
joshklop committed May 1, 2023
1 parent 3c82a62 commit 6baadd0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestSyncBlocks(t *testing.T) {

syncingHeight := uint64(0)

mockSNData.EXPECT().BlockByNumber(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, height uint64) (*core.Block, error) {
mockSNData.EXPECT().BlockByNumber(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, height uint64) (*core.Block, error) {
curHeight := atomic.LoadUint64(&syncingHeight)
// reject any other requests
if height != curHeight {
Expand All @@ -104,7 +104,7 @@ func TestSyncBlocks(t *testing.T) {
}).AnyTimes()

reqCount := 0
mockSNData.EXPECT().StateUpdate(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, height uint64) (*core.StateUpdate, error) {
mockSNData.EXPECT().StateUpdate(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, height uint64) (*core.StateUpdate, error) {
curHeight := atomic.LoadUint64(&syncingHeight)
// reject any other requests
if height != curHeight {
Expand All @@ -115,13 +115,14 @@ func TestSyncBlocks(t *testing.T) {
ret, err := gw.StateUpdate(context.Background(), curHeight)
require.NoError(t, err)

if reqCount == 1 {
switch reqCount {
case 1:
return nil, errors.New("try again")
} else if reqCount == 2 {
case 2:
ret.BlockHash = new(felt.Felt) // fail sanity checks
} else if reqCount == 3 {
case 3:
ret.OldRoot = new(felt.Felt).SetUint64(1) // fail store
} else {
default:
reqCount = 0
atomic.AddUint64(&syncingHeight, 1)
}
Expand Down

0 comments on commit 6baadd0

Please sign in to comment.