Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaidashenko committed Jul 20, 2024
1 parent 412ccc4 commit 3b0d090
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/chains/evm/client/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func newMockRpc(t *testing.T) *mocks.RPCClient {
mockRpc.On("Close").Return(nil).Once()
mockRpc.On("ChainID", mock.Anything).Return(testutils.FixtureChainID, nil).Once()
// node does not always manage to fully setup aliveLoop, so we have to make calls optional to avoid flakes
mockRpc.On("SubscribeNewHead", mock.Anything, mock.Anything).Return(client.NewMockSubscription(), nil).Maybe()
mockRpc.On("SubscribeToHeads", mock.Anything).Return(nil, client.NewMockSubscription(), nil).Maybe()
mockRpc.On("SetAliveLoopSub", mock.Anything).Return().Maybe()
return mockRpc
}
Expand Down
30 changes: 17 additions & 13 deletions core/chains/evm/client/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,35 @@ func NewClientConfigs(
finalizedBlockOffset *uint32,
enforceRepeatableRead *bool,
deathDeclarationDelay time.Duration,
noNewFinalizedHeadsThreshold time.Duration,
finalizedBlockPollInterval time.Duration,

) (commonclient.ChainConfig, evmconfig.NodePool, []*toml.Node, error) {
nodes, err := parseNodeConfigs(nodeCfgs)
if err != nil {
return nil, nil, nil, err
}
nodePool := toml.NodePool{
SelectionMode: selectionMode,
LeaseDuration: commonconfig.MustNewDuration(leaseDuration),
PollFailureThreshold: pollFailureThreshold,
PollInterval: commonconfig.MustNewDuration(pollInterval),
SyncThreshold: syncThreshold,
NodeIsSyncingEnabled: nodeIsSyncingEnabled,
EnforceRepeatableRead: enforceRepeatableRead,
DeathDeclarationDelay: commonconfig.MustNewDuration(deathDeclarationDelay),
SelectionMode: selectionMode,
LeaseDuration: commonconfig.MustNewDuration(leaseDuration),
PollFailureThreshold: pollFailureThreshold,
PollInterval: commonconfig.MustNewDuration(pollInterval),
SyncThreshold: syncThreshold,
NodeIsSyncingEnabled: nodeIsSyncingEnabled,
EnforceRepeatableRead: enforceRepeatableRead,
DeathDeclarationDelay: commonconfig.MustNewDuration(deathDeclarationDelay),
FinalizedBlockPollInterval: commonconfig.MustNewDuration(finalizedBlockPollInterval),
}
nodePoolCfg := &evmconfig.NodePoolConfig{C: nodePool}
chainConfig := &evmconfig.EVMConfig{
C: &toml.EVMConfig{
Chain: toml.Chain{
ChainType: chaintype.NewChainTypeConfig(chainType),
FinalityDepth: finalityDepth,
FinalityTagEnabled: finalityTagEnabled,
NoNewHeadsThreshold: commonconfig.MustNewDuration(noNewHeadsThreshold),
FinalizedBlockOffset: finalizedBlockOffset,
ChainType: chaintype.NewChainTypeConfig(chainType),
FinalityDepth: finalityDepth,
FinalityTagEnabled: finalityTagEnabled,
NoNewHeadsThreshold: commonconfig.MustNewDuration(noNewHeadsThreshold),
FinalizedBlockOffset: finalizedBlockOffset,
NoNewFinalizedHeadsThreshold: commonconfig.MustNewDuration(noNewFinalizedHeadsThreshold),
},
},
}
Expand Down
5 changes: 4 additions & 1 deletion core/chains/evm/client/config_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestClientConfigBuilder(t *testing.T) {
finalizedBlockOffset := ptr[uint32](16)
enforceRepeatableRead := ptr(true)
deathDeclarationDelay := time.Second * 3
noNewFinalizedBlocksThreshold := time.Second
nodeConfigs := []client.NodeConfig{
{
Name: ptr("foo"),
Expand All @@ -38,7 +39,7 @@ func TestClientConfigBuilder(t *testing.T) {
noNewHeadsThreshold := time.Second
chainCfg, nodePool, nodes, err := client.NewClientConfigs(selectionMode, leaseDuration, chainTypeStr, nodeConfigs,
pollFailureThreshold, pollInterval, syncThreshold, nodeIsSyncingEnabled, noNewHeadsThreshold, finalityDepth,
finalityTagEnabled, finalizedBlockOffset, enforceRepeatableRead, deathDeclarationDelay)
finalityTagEnabled, finalizedBlockOffset, enforceRepeatableRead, deathDeclarationDelay, noNewFinalizedBlocksThreshold, pollInterval)
require.NoError(t, err)

// Validate node pool configs
Expand All @@ -50,6 +51,7 @@ func TestClientConfigBuilder(t *testing.T) {
require.Equal(t, *nodeIsSyncingEnabled, nodePool.NodeIsSyncingEnabled())
require.Equal(t, *enforceRepeatableRead, nodePool.EnforceRepeatableRead())
require.Equal(t, deathDeclarationDelay, nodePool.DeathDeclarationDelay())
require.Equal(t, pollInterval, nodePool.FinalizedBlockPollInterval())

// Validate node configs
require.Equal(t, *nodeConfigs[0].Name, *nodes[0].Name)
Expand All @@ -61,6 +63,7 @@ func TestClientConfigBuilder(t *testing.T) {
require.Equal(t, *finalityDepth, chainCfg.FinalityDepth())
require.Equal(t, *finalityTagEnabled, chainCfg.FinalityTagEnabled())
require.Equal(t, *finalizedBlockOffset, chainCfg.FinalizedBlockOffset())
require.Equal(t, noNewFinalizedBlocksThreshold, chainCfg.NoNewFinalizedHeadsThreshold())

// let combiler tell us, when we do not have sufficient data to create evm client
_ = client.NewEvmClient(nodePool, chainCfg, nil, logger.Test(t), big.NewInt(10), nodes, chaintype.ChainType(chainTypeStr))
Expand Down
4 changes: 3 additions & 1 deletion core/chains/evm/client/evm_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestNewEvmClient(t *testing.T) {
finalizedBlockOffset := ptr[uint32](16)
enforceRepeatableRead := ptr(true)
deathDeclarationDelay := time.Second * 3
noNewFinalizedBlocksThreshold := time.Second * 5
finalizedBlockPollInterval := time.Second * 4
nodeConfigs := []client.NodeConfig{
{
Name: ptr("foo"),
Expand All @@ -38,7 +40,7 @@ func TestNewEvmClient(t *testing.T) {
finalityTagEnabled := ptr(true)
chainCfg, nodePool, nodes, err := client.NewClientConfigs(selectionMode, leaseDuration, chainTypeStr, nodeConfigs,
pollFailureThreshold, pollInterval, syncThreshold, nodeIsSyncingEnabled, noNewHeadsThreshold, finalityDepth,
finalityTagEnabled, finalizedBlockOffset, enforceRepeatableRead, deathDeclarationDelay)
finalityTagEnabled, finalizedBlockOffset, enforceRepeatableRead, deathDeclarationDelay, noNewFinalizedBlocksThreshold, finalizedBlockPollInterval)
require.NoError(t, err)

client := client.NewEvmClient(nodePool, chainCfg, nil, logger.Test(t), testutils.FixtureChainID, nodes, chaintype.ChainType(chainTypeStr))
Expand Down

0 comments on commit 3b0d090

Please sign in to comment.