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

Feat/remove code leaf #280

Draft
wants to merge 32 commits into
base: rc/v1.6.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cdcbd93
updated enableEpochsHandler interface
sstanculeanu Jul 13, 2023
e993142
Merge pull request #250 from multiversx/merge_rc160_into_feat_refacto…
sstanculeanu Aug 16, 2023
e29902f
Merge branch 'feat/refactor_enable_epochs_handler' of https://github.…
sstanculeanu Aug 16, 2023
86d4ed5
new approach for enable epochs handler
sstanculeanu Aug 16, 2023
1ef94e0
removed logger from CheckHandlerCompatibility
sstanculeanu Aug 16, 2023
51aa948
Merge branch 'rc/v1.6.0' of https://github.com/multiversx/mx-chain-co…
sstanculeanu Aug 17, 2023
72cce04
Merge pull request #254 from multiversx/merge_rc160_into_refactor_ena…
sstanculeanu Aug 17, 2023
1775112
Merge branch 'feat/refactor_enable_epochs_handler' of https://github.…
sstanculeanu Aug 17, 2023
32932af
fixes after review
sstanculeanu Aug 18, 2023
b5c46f8
Merge pull request #243 from multiversx/update_enable_epochs_handler
sstanculeanu Aug 21, 2023
2cc1b40
fixes after review + removed all constants + fixed linter issue as pe…
sstanculeanu Aug 21, 2023
9a2b555
removed no lint lines
sstanculeanu Aug 21, 2023
0a38610
Merge pull request #256 from multiversx/remove_constants
sstanculeanu Aug 25, 2023
1d1190b
Merge branch 'rc/v1.6.0' of https://github.com/multiversx/mx-chain-co…
sstanculeanu Aug 28, 2023
e3ca86b
Merge pull request #257 from multiversx/merge_rc160_into_feat_refacto…
sstanculeanu Aug 28, 2023
8728c8a
Merge branch 'rc/v1.6.0' of https://github.com/multiversx/mx-chain-co…
sstanculeanu Sep 18, 2023
ea59ee0
Merge pull request #261 from multiversx/merge_rc160_into_feat_refacto…
sstanculeanu Sep 18, 2023
e910504
- removed caches from core
iulianpascalau Sep 19, 2023
2af2ec1
- go mod tidy
iulianpascalau Sep 19, 2023
566f55d
- added KeyValuePair data type
iulianpascalau Sep 19, 2023
059ccae
Merge pull request #255 from multiversx/feat/refactor_enable_epochs_h…
sstanculeanu Oct 2, 2023
19ac702
- removed unused, wrongly placed, stubs & mocks
iulianpascalau Oct 25, 2023
f3530bc
Merge branch 'rc/v1.6.0' into remove-caches
iulianpascalau Oct 25, 2023
158315d
Merge remote-tracking branch 'origin/rc/v1.6.0' into merge-rc/v1.6.0-…
BeniaminDrasovean Nov 23, 2023
6962388
Merge pull request #274 from multiversx/merge-rc/v1.6.0-in-rc/v1.7.0
BeniaminDrasovean Nov 24, 2023
ed36c88
added ValidatorStatus structure
sstanculeanu Nov 27, 2023
47f8001
renamed
sstanculeanu Nov 27, 2023
356aa23
Merge branch 'rc/v1.7.0' into remove-caches
iulianpascalau Nov 29, 2023
be7692c
removed omitempty field from ValidatorStatus as on mx-chain-proxy-go
sstanculeanu Dec 4, 2023
d059d58
Merge pull request #262 from multiversx/remove-caches
iulianpascalau Dec 6, 2023
cdde726
Merge branch 'rc/v1.7.0' into move_validatorAPIResponse
sstanculeanu Dec 8, 2023
bb0e5f8
Merge pull request #275 from multiversx/move_validatorAPIResponse
sstanculeanu Dec 12, 2023
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
25 changes: 25 additions & 0 deletions core/epochFlags.go
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
}
45 changes: 45 additions & 0 deletions core/epochFlags_test.go
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)))
}
5 changes: 4 additions & 1 deletion core/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var ErrInvalidValue = errors.New("invalid value provided")
// ErrNilInputData signals that a nil data has been provided
var ErrNilInputData = errors.New("nil input data")

//ErrNilUrl signals that the provided url is empty
// ErrNilUrl signals that the provided url is empty
var ErrNilUrl = errors.New("url is empty")

// ErrPemFileIsInvalid signals that a pem file is invalid
Expand Down Expand Up @@ -118,3 +118,6 @@ var ErrDBIsClosed = errors.New("DB is closed")

// ErrNilEnableEpochsHandler signals that a nil enable epochs handler has been provided
var ErrNilEnableEpochsHandler = errors.New("nil enable epochs handler")

// ErrInvalidEnableEpochsHandler signals that an invalid enable epochs handler has been provided
var ErrInvalidEnableEpochsHandler = errors.New("invalid enable epochs handler")
32 changes: 32 additions & 0 deletions core/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,42 @@ package core

import "time"

// GetContainingDuration -
func (sw *StopWatch) GetContainingDuration() (map[string]time.Duration, []string) {
return sw.getContainingDuration()
}

// GetIdentifiers -
func (sw *StopWatch) GetIdentifiers() []string {
return sw.identifiers
}

// SetIdentifiers -
func (sw *StopWatch) SetIdentifiers(identifiers []string) {
sw.identifiers = identifiers
}

// GetStarted -
func (sw *StopWatch) GetStarted(identifier string) (time.Time, bool) {
s, has := sw.started[identifier]
return s, has
}

// GetElapsed -
func (sw *StopWatch) GetElapsed(identifier string) (time.Duration, bool) {
e, has := sw.elapsed[identifier]
return e, has
}

// SetElapsed -
func (sw *StopWatch) SetElapsed(identifier string, duration time.Duration) {
sw.elapsed[identifier] = duration
}

// SplitExponentFraction -
func SplitExponentFraction(val string) (string, string) {
return splitExponentFraction(val)
}

// TestAutoBalanceDataTriesFlag -
const TestAutoBalanceDataTriesFlag = autoBalanceDataTriesFlag
6 changes: 3 additions & 3 deletions core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -152,7 +152,7 @@ func LoadSkPkFromPemFile(relativePath string, skIndex int) ([]byte, string, erro
_ = file.Close()
}()

buff, err := ioutil.ReadAll(file)
buff, err := io.ReadAll(file)
if err != nil {
return nil, "", fmt.Errorf("%w while reading %s file", err, relativePath)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func LoadAllKeysFromPemFile(relativePath string) ([][]byte, []string, error) {
_ = file.Close()
}()

buff, err := ioutil.ReadAll(file)
buff, err := io.ReadAll(file)
if err != nil {
return nil, nil, fmt.Errorf("%w while reading %s file", err, relativePath)
}
Expand Down
3 changes: 1 addition & 2 deletions core/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package core_test
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -146,7 +145,7 @@ func TestLoadJSonFile_FileExitsShouldPass(t *testing.T) {

data, _ := json.MarshalIndent(TestStruct{A: 0, B: 0}, "", " ")

_ = ioutil.WriteFile(fileName, data, 0644)
_ = os.WriteFile(fileName, data, 0644)

err = file.Close()
assert.Nil(t, err)
Expand Down
5 changes: 4 additions & 1 deletion core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type TrieNodeVersionVerifier interface {

// EnableEpochsHandler defines the behavior of a component that can return if a feature is enabled or not
type EnableEpochsHandler interface {
IsAutoBalanceDataTriesEnabled() bool
IsFlagDefined(flag EnableEpochFlag) bool
IsFlagEnabled(flag EnableEpochFlag) bool
IsFlagEnabledInEpoch(flag EnableEpochFlag, epoch uint32) bool
GetActivationEpoch(flag EnableEpochFlag) uint32
IsInterfaceNil() bool
}
7 changes: 4 additions & 3 deletions core/loggingFunctions_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package core
package core_test

import (
"fmt"
"testing"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/mock"
"github.com/stretchr/testify/require"
)
Expand All @@ -18,12 +19,12 @@ func TestDumpGoRoutinesToLogShouldNotPanic(t *testing.T) {
}
}()

DumpGoRoutinesToLog(0, &mock.LoggerMock{})
core.DumpGoRoutinesToLog(0, &mock.LoggerMock{})
}

func TestGetRunningGoRoutines(t *testing.T) {
t.Parallel()

res := GetRunningGoRoutines(&mock.LoggerMock{})
res := core.GetRunningGoRoutines(&mock.LoggerMock{})
require.NotNil(t, res)
}
20 changes: 0 additions & 20 deletions core/mock/enableEpochsHandlerMock.go

This file was deleted.

48 changes: 48 additions & 0 deletions core/mock/enableEpochsHandlerStub.go
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
}
Loading