-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
890 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
package common | ||
|
||
import "github.com/multiversx/mx-chain-core-go/core" | ||
|
||
// GetClosedUnbufferedChannel returns an instance of a 'chan struct{}' that is already closed | ||
func GetClosedUnbufferedChannel() chan struct{} { | ||
ch := make(chan struct{}) | ||
close(ch) | ||
|
||
return ch | ||
} | ||
|
||
// CloseKeyValueHolderChan will close the channel if not nil | ||
func CloseKeyValueHolderChan(ch chan core.KeyValueHolder) { | ||
if ch != nil { | ||
close(ch) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package syncer_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/multiversx/mx-chain-go/state" | ||
"github.com/multiversx/mx-chain-go/state/syncer" | ||
"github.com/multiversx/mx-chain-go/testscommon" | ||
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" | ||
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks" | ||
"github.com/multiversx/mx-chain-go/testscommon/marshallerMock" | ||
"github.com/multiversx/mx-chain-go/testscommon/statusHandler" | ||
"github.com/multiversx/mx-chain-go/testscommon/storageManager" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func getDefaultBaseAccSyncerArgs() syncer.ArgsNewBaseAccountsSyncer { | ||
return syncer.ArgsNewBaseAccountsSyncer{ | ||
Hasher: &hashingMocks.HasherMock{}, | ||
Marshalizer: marshallerMock.MarshalizerMock{}, | ||
TrieStorageManager: &storageManager.StorageManagerStub{}, | ||
RequestHandler: &testscommon.RequestHandlerStub{}, | ||
Timeout: time.Second, | ||
Cacher: testscommon.NewCacherMock(), | ||
UserAccountsSyncStatisticsHandler: &testscommon.SizeSyncStatisticsHandlerStub{}, | ||
AppStatusHandler: &statusHandler.AppStatusHandlerStub{}, | ||
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, | ||
MaxTrieLevelInMemory: 5, | ||
MaxHardCapForMissingNodes: 100, | ||
TrieSyncerVersion: 3, | ||
CheckNodesOnDisk: false, | ||
} | ||
} | ||
|
||
func TestBaseAccountsSyncer_CheckArgs(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("nil hasher", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.Hasher = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilHasher, err) | ||
}) | ||
|
||
t.Run("nil marshaller", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.Marshalizer = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilMarshalizer, err) | ||
}) | ||
|
||
t.Run("nil trie storage manager", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.TrieStorageManager = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilStorageManager, err) | ||
}) | ||
|
||
t.Run("nil requests handler", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.RequestHandler = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilRequestHandler, err) | ||
}) | ||
|
||
t.Run("nil cacher", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.Cacher = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilCacher, err) | ||
}) | ||
|
||
t.Run("nil user accounts sync statistics handler", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.UserAccountsSyncStatisticsHandler = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilSyncStatisticsHandler, err) | ||
}) | ||
|
||
t.Run("nil app status handler", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.AppStatusHandler = nil | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrNilAppStatusHandler, err) | ||
}) | ||
|
||
t.Run("invalid max hard capacity for missing nodes", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
args := getDefaultBaseAccSyncerArgs() | ||
args.MaxHardCapForMissingNodes = 0 | ||
err := syncer.CheckBaseAccountsSyncerArgs(args) | ||
require.Equal(t, state.ErrInvalidMaxHardCapForMissingNodes, err) | ||
}) | ||
|
||
t.Run("should work", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
require.Nil(t, syncer.CheckBaseAccountsSyncerArgs(getDefaultBaseAccSyncerArgs())) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.