-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from multiversx/rc/v1.7.0
Rc/v1.7.0
- Loading branch information
Showing
44 changed files
with
1,339 additions
and
2,272 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
) | ||
|
||
// EnableEpochFlag defines a flag specific to the enableEpochs.toml | ||
type EnableEpochFlag string | ||
|
||
// CheckHandlerCompatibility checks if the provided handler is compatible with this mx-chain-core-go version | ||
func CheckHandlerCompatibility(handler EnableEpochsHandler, requiredFlags []EnableEpochFlag) error { | ||
if check.IfNil(handler) { | ||
return ErrNilEnableEpochsHandler | ||
} | ||
|
||
for _, flag := range requiredFlags { | ||
if !handler.IsFlagDefined(flag) { | ||
return fmt.Errorf("%w for flag %s", ErrInvalidEnableEpochsHandler, flag) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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,45 @@ | ||
package core_test | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/core/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCheckHandlerCompatibility(t *testing.T) { | ||
t.Parallel() | ||
|
||
err := core.CheckHandlerCompatibility(nil, []core.EnableEpochFlag{}) | ||
require.Equal(t, core.ErrNilEnableEpochsHandler, err) | ||
|
||
testFlags := []core.EnableEpochFlag{"f0", "f1", "f2"} | ||
allFlagsDefinedHandler := &mock.EnableEpochsHandlerStub{ | ||
IsFlagDefinedCalled: func(flag core.EnableEpochFlag) bool { | ||
return true | ||
}, | ||
} | ||
err = core.CheckHandlerCompatibility(allFlagsDefinedHandler, testFlags) | ||
require.Nil(t, err) | ||
|
||
allFlagsUndefinedHandler := &mock.EnableEpochsHandlerStub{ | ||
IsFlagDefinedCalled: func(flag core.EnableEpochFlag) bool { | ||
return false | ||
}, | ||
} | ||
err = core.CheckHandlerCompatibility(allFlagsUndefinedHandler, testFlags) | ||
require.True(t, errors.Is(err, core.ErrInvalidEnableEpochsHandler)) | ||
|
||
missingFlag := testFlags[1] | ||
oneFlagUndefinedHandler := &mock.EnableEpochsHandlerStub{ | ||
IsFlagDefinedCalled: func(flag core.EnableEpochFlag) bool { | ||
return flag != missingFlag | ||
}, | ||
} | ||
err = core.CheckHandlerCompatibility(oneFlagUndefinedHandler, testFlags) | ||
require.True(t, errors.Is(err, core.ErrInvalidEnableEpochsHandler)) | ||
require.True(t, strings.Contains(err.Error(), string(missingFlag))) | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
package mock | ||
|
||
import "github.com/multiversx/mx-chain-core-go/core" | ||
|
||
// EnableEpochsHandlerStub - | ||
type EnableEpochsHandlerStub struct { | ||
IsFlagDefinedCalled func(flag core.EnableEpochFlag) bool | ||
IsFlagEnabledCalled func(flag core.EnableEpochFlag) bool | ||
IsFlagEnabledInEpochCalled func(flag core.EnableEpochFlag, epoch uint32) bool | ||
GetActivationEpochCalled func(flag core.EnableEpochFlag) uint32 | ||
} | ||
|
||
// IsFlagDefined - | ||
func (stub *EnableEpochsHandlerStub) IsFlagDefined(flag core.EnableEpochFlag) bool { | ||
if stub.IsFlagDefinedCalled != nil { | ||
return stub.IsFlagDefinedCalled(flag) | ||
} | ||
return false | ||
} | ||
|
||
// IsFlagEnabled - | ||
func (stub *EnableEpochsHandlerStub) IsFlagEnabled(flag core.EnableEpochFlag) bool { | ||
if stub.IsFlagEnabledCalled != nil { | ||
return stub.IsFlagEnabledCalled(flag) | ||
} | ||
return false | ||
} | ||
|
||
// IsFlagEnabledInEpoch - | ||
func (stub *EnableEpochsHandlerStub) IsFlagEnabledInEpoch(flag core.EnableEpochFlag, epoch uint32) bool { | ||
if stub.IsFlagEnabledInEpochCalled != nil { | ||
return stub.IsFlagEnabledInEpochCalled(flag, epoch) | ||
} | ||
return false | ||
} | ||
|
||
// GetActivationEpoch - | ||
func (stub *EnableEpochsHandlerStub) GetActivationEpoch(flag core.EnableEpochFlag) uint32 { | ||
if stub.GetActivationEpochCalled != nil { | ||
return stub.GetActivationEpochCalled(flag) | ||
} | ||
return 0 | ||
} | ||
|
||
// IsInterfaceNil - | ||
func (stub *EnableEpochsHandlerStub) IsInterfaceNil() bool { | ||
return stub == nil | ||
} |
Oops, something went wrong.