Skip to content

Commit 818b3fd

Browse files
committed
[FAB-9685] Move IsDevMode to config and add tests
Change-Id: I28ecc354b4621dfee93ae37faf84956c9db5c3d7 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 28be67f commit 818b3fd

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

core/chaincode/chaincode_support.go

-10
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ import (
1818
"github.com/hyperledger/fabric/core/container/ccintf"
1919
pb "github.com/hyperledger/fabric/protos/peer"
2020
"github.com/pkg/errors"
21-
"github.com/spf13/viper"
2221
"golang.org/x/net/context"
2322
)
2423

2524
type key string
2625

2726
const (
28-
// DevModeUserRunsChaincode property allows user to run chaincode in development environment
29-
DevModeUserRunsChaincode string = "dev"
3027
chaincodeStartupTimeoutDefault int = 5000
3128
peerAddressDefault string = "0.0.0.0:7052"
3229

@@ -435,10 +432,3 @@ func (cs *ChaincodeSupport) Execute(ctxt context.Context, cccid *ccprovider.CCCo
435432

436433
return ccresp, err
437434
}
438-
439-
// IsDevMode returns true if the peer was configured with development-mode enabled
440-
func IsDevMode() bool {
441-
mode := viper.GetString("chaincode.mode")
442-
443-
return mode == DevModeUserRunsChaincode
444-
}

core/chaincode/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@ func getLogLevelFromViper(key string) string {
8484

8585
return levelString
8686
}
87+
88+
// DevModeUserRunsChaincode enables chaincode execution in a development
89+
// environment
90+
const DevModeUserRunsChaincode string = "dev"
91+
92+
// IsDevMode returns true if the peer was configured with development-mode
93+
// enabled.
94+
func IsDevMode() bool {
95+
mode := viper.GetString("chaincode.mode")
96+
97+
return mode == DevModeUserRunsChaincode
98+
}

core/chaincode/config_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ func TestGlobalConfigInvalidLogLevel(t *testing.T) {
8484
assert.Equal(t, "INFO", config.ShimLogLevel)
8585
}
8686

87+
func TestIsDevMode(t *testing.T) {
88+
cleanup := capture()
89+
defer cleanup()
90+
91+
viper.Set("chaincode.mode", chaincode.DevModeUserRunsChaincode)
92+
assert.True(t, chaincode.IsDevMode())
93+
94+
viper.Set("chaincode.mode", "empty")
95+
assert.False(t, chaincode.IsDevMode())
96+
viper.Set("chaincode.mode", "nonsense")
97+
assert.False(t, chaincode.IsDevMode())
98+
}
99+
87100
func capture() (restore func()) {
88101
viper.SetEnvPrefix("CORE")
89102
viper.AutomaticEnv()

0 commit comments

Comments
 (0)