@@ -17,6 +17,7 @@ limitations under the License.
17
17
package chaincode
18
18
19
19
import (
20
+ "flag"
20
21
"fmt"
21
22
"math/rand"
22
23
"net"
@@ -33,6 +34,7 @@ import (
33
34
34
35
"github.com/golang/protobuf/proto"
35
36
37
+ "github.com/hyperledger/fabric/bccsp/factory"
36
38
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
37
39
"github.com/hyperledger/fabric/common/policies"
38
40
"github.com/hyperledger/fabric/common/util"
@@ -45,6 +47,7 @@ import (
45
47
"github.com/hyperledger/fabric/core/peer"
46
48
"github.com/hyperledger/fabric/core/policy"
47
49
"github.com/hyperledger/fabric/core/scc"
50
+ "github.com/hyperledger/fabric/core/testutil"
48
51
pb "github.com/hyperledger/fabric/protos/peer"
49
52
putils "github.com/hyperledger/fabric/protos/utils"
50
53
@@ -1782,10 +1785,38 @@ func TestMain(m *testing.M) {
1782
1785
return
1783
1786
}
1784
1787
1785
- SetupTestConfig ()
1788
+ setupTestConfig ()
1786
1789
os .Exit (m .Run ())
1787
1790
}
1788
1791
1792
+ func setupTestConfig () {
1793
+ flag .Parse ()
1794
+
1795
+ // Now set the configuration file
1796
+ viper .SetEnvPrefix ("CORE" )
1797
+ viper .AutomaticEnv ()
1798
+ replacer := strings .NewReplacer ("." , "_" )
1799
+ viper .SetEnvKeyReplacer (replacer )
1800
+ viper .SetConfigName ("chaincodetest" ) // name of config file (without extension)
1801
+ viper .AddConfigPath ("./" ) // path to look for the config file in
1802
+ err := viper .ReadInConfig () // Find and read the config file
1803
+ if err != nil { // Handle errors reading the config file
1804
+ panic (fmt .Errorf ("Fatal error config file: %s \n " , err ))
1805
+ }
1806
+
1807
+ testutil .SetupTestLogging ()
1808
+
1809
+ // Set the number of maxprocs
1810
+ var numProcsDesired = viper .GetInt ("peer.gomaxprocs" )
1811
+ chaincodeLogger .Debugf ("setting Number of procs to %d, was %d\n " , numProcsDesired , runtime .GOMAXPROCS (2 ))
1812
+
1813
+ // Init the BCCSP
1814
+ err = factory .InitFactories (nil )
1815
+ if err != nil {
1816
+ panic (fmt .Errorf ("Could not initialize BCCSP Factories [%s]" , err ))
1817
+ }
1818
+ }
1819
+
1789
1820
func deployChaincode (ctx context.Context , name string , version string , chaincodeType pb.ChaincodeSpec_Type , path string , args [][]byte , creator []byte , channel string , nextBlockNumber uint64 ) ([]byte , * ccprovider.CCContext , error ) {
1790
1821
chaincodeSpec := & pb.ChaincodeSpec {
1791
1822
ChaincodeId : & pb.ChaincodeID {
0 commit comments