@@ -10,6 +10,7 @@ import (
10
10
"bytes"
11
11
"compress/gzip"
12
12
"fmt"
13
+ "io/ioutil"
13
14
"os"
14
15
"testing"
15
16
@@ -34,7 +35,7 @@ import (
34
35
"github.com/hyperledger/fabric/core/handlers/validation/api/capabilities"
35
36
"github.com/hyperledger/fabric/core/handlers/validation/builtin/v12/mocks"
36
37
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
37
- per "github.com/hyperledger/fabric/core/peer"
38
+ corepeer "github.com/hyperledger/fabric/core/peer"
38
39
"github.com/hyperledger/fabric/core/policy"
39
40
"github.com/hyperledger/fabric/core/scc/lscc"
40
41
"github.com/hyperledger/fabric/msp"
@@ -803,19 +804,15 @@ func TestAlreadyDeployed(t *testing.T) {
803
804
state ["lscc" ] = stublccc .State
804
805
805
806
ccname := "mycc"
806
- ccver := "1 "
807
+ ccver := "alreadydeployed "
807
808
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
808
809
809
- ppath := lccctestpath + "/" + ccname + "." + ccver
810
-
811
- os .Remove (ppath )
812
-
813
810
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
814
811
if err != nil {
815
812
fmt .Printf ("%s\n " , err )
816
813
t .FailNow ()
817
814
}
818
- defer os . Remove ( ppath )
815
+
819
816
var b []byte
820
817
if b , err = proto .Marshal (cds ); err != nil || b == nil {
821
818
t .FailNow ()
@@ -1185,19 +1182,15 @@ func TestValidateUpgradeOK(t *testing.T) {
1185
1182
state ["lscc" ] = stublccc .State
1186
1183
1187
1184
ccname := "mycc"
1188
- ccver := "1 "
1185
+ ccver := "upgradeok "
1189
1186
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1190
1187
1191
- ppath := lccctestpath + "/" + ccname + "." + ccver
1192
-
1193
- os .Remove (ppath )
1194
-
1195
1188
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
1196
1189
if err != nil {
1197
1190
fmt .Printf ("%s\n " , err )
1198
1191
t .FailNow ()
1199
1192
}
1200
- defer os . Remove ( ppath )
1193
+
1201
1194
var b []byte
1202
1195
if b , err = proto .Marshal (cds ); err != nil || b == nil {
1203
1196
t .FailNow ()
@@ -1252,19 +1245,15 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
1252
1245
state ["lscc" ] = stublccc .State
1253
1246
1254
1247
ccname := "mycc"
1255
- ccver := "1 "
1248
+ ccver := "upgradebadversion "
1256
1249
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1257
1250
1258
- ppath := lccctestpath + "/" + ccname + "." + ccver
1259
-
1260
- os .Remove (ppath )
1261
-
1262
1251
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
1263
1252
if err != nil {
1264
1253
fmt .Printf ("%s\n " , err )
1265
1254
t .FailNow ()
1266
1255
}
1267
- defer os . Remove ( ppath )
1256
+
1268
1257
var b []byte
1269
1258
if b , err = proto .Marshal (cds ); err != nil || b == nil {
1270
1259
t .FailNow ()
@@ -1301,7 +1290,7 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
1301
1290
assert .Error (t , err )
1302
1291
}
1303
1292
1304
- func validateUpgradeWithCollection (t * testing.T , V1_2Validation bool ) {
1293
+ func validateUpgradeWithCollection (t * testing.T , ccver string , V1_2Validation bool ) {
1305
1294
state := make (map [string ]map [string ][]byte )
1306
1295
mp := (& scc.MocksccProviderFactory {
1307
1296
Qe : lm .NewMockQueryExecutor (state ),
@@ -1331,19 +1320,14 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
1331
1320
}
1332
1321
1333
1322
ccname := "mycc"
1334
- ccver := "1"
1335
1323
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1336
1324
1337
- ppath := lccctestpath + "/" + ccname + "." + ccver
1338
-
1339
- os .Remove (ppath )
1340
-
1341
1325
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, true )
1342
1326
if err != nil {
1343
1327
fmt .Printf ("%s\n " , err )
1344
1328
t .FailNow ()
1345
1329
}
1346
- defer os . Remove ( ppath )
1330
+
1347
1331
var b []byte
1348
1332
if b , err = proto .Marshal (cds ); err != nil || b == nil {
1349
1333
t .FailNow ()
@@ -1496,9 +1480,9 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
1496
1480
1497
1481
func TestValidateUpgradeWithCollection (t * testing.T ) {
1498
1482
// with V1_2Validation enabled
1499
- validateUpgradeWithCollection (t , true )
1483
+ validateUpgradeWithCollection (t , "v12-validation-enabled" , true )
1500
1484
// with V1_2Validation disabled
1501
- validateUpgradeWithCollection (t , false )
1485
+ validateUpgradeWithCollection (t , "v12-validation-disabled" , false )
1502
1486
}
1503
1487
1504
1488
func TestValidateUpgradeWithPoliciesOK (t * testing.T ) {
@@ -1517,21 +1501,17 @@ func TestValidateUpgradeWithPoliciesOK(t *testing.T) {
1517
1501
state ["lscc" ] = stublccc .State
1518
1502
1519
1503
ccname := "mycc"
1520
- ccver := "1 "
1504
+ ccver := "upgradewithpoliciesok "
1521
1505
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1522
1506
1523
- ppath := lccctestpath + "/" + ccname + "." + ccver
1524
-
1525
- os .Remove (ppath )
1526
-
1527
1507
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, false )
1528
1508
if err != nil {
1529
1509
fmt .Printf ("%s\n " , err )
1530
1510
t .FailNow ()
1531
1511
}
1532
1512
_ , err = processSignedCDS (cds , cauthdsl .AcceptAllPolicy )
1533
1513
assert .NoError (t , err )
1534
- defer os . Remove ( ppath )
1514
+
1535
1515
var b []byte
1536
1516
if b , err = proto .Marshal (cds ); err != nil || b == nil {
1537
1517
t .FailNow ()
@@ -1581,11 +1561,11 @@ func TestValidateUpgradeWithNewFailAllIP(t *testing.T) {
1581
1561
// We run this test twice, once with the V11 capability (and expect
1582
1562
// a failure) and once without (and we expect success).
1583
1563
1584
- validateUpgradeWithNewFailAllIP (t , true , true )
1585
- validateUpgradeWithNewFailAllIP (t , false , false )
1564
+ validateUpgradeWithNewFailAllIP (t , "v11-capabilityenabled" , true , true )
1565
+ validateUpgradeWithNewFailAllIP (t , "v11-capabilitydisabled" , false , false )
1586
1566
}
1587
1567
1588
- func validateUpgradeWithNewFailAllIP (t * testing.T , v11capability , expecterr bool ) {
1568
+ func validateUpgradeWithNewFailAllIP (t * testing.T , ccver string , v11capability , expecterr bool ) {
1589
1569
state := make (map [string ]map [string ][]byte )
1590
1570
mp := (& scc.MocksccProviderFactory {
1591
1571
Qe : lm .NewMockQueryExecutor (state ),
@@ -1609,11 +1589,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
1609
1589
// deploy the chaincode with an accept all policy
1610
1590
1611
1591
ccname := "mycc"
1612
- ccver := "1"
1613
1592
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1614
- ppath := lccctestpath + "/" + ccname + "." + ccver
1615
-
1616
- os .Remove (ppath )
1617
1593
1618
1594
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, false )
1619
1595
if err != nil {
@@ -1622,7 +1598,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
1622
1598
}
1623
1599
_ , err = processSignedCDS (cds , cauthdsl .AcceptAllPolicy )
1624
1600
assert .NoError (t , err )
1625
- defer os . Remove ( ppath )
1601
+
1626
1602
var b []byte
1627
1603
if b , err = proto .Marshal (cds ); err != nil || b == nil {
1628
1604
t .FailNow ()
@@ -1639,7 +1615,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
1639
1615
1640
1616
// now we upgrade, with v 2 of the same cc, with the crucial difference that it has a reject all IP
1641
1617
1642
- ccver = " 2"
1618
+ ccver = ccver + ". 2"
1643
1619
1644
1620
simresres , err := createCCDataRWset (ccname , ccname , ccver ,
1645
1621
cauthdsl .MarshaledRejectAllPolicy , // here's where we specify the IP of the upgraded cc
@@ -1689,21 +1665,17 @@ func TestValidateUpgradeWithPoliciesFail(t *testing.T) {
1689
1665
state ["lscc" ] = stublccc .State
1690
1666
1691
1667
ccname := "mycc"
1692
- ccver := "1 "
1668
+ ccver := "upgradewithpoliciesfail "
1693
1669
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1694
1670
1695
- ppath := lccctestpath + "/" + ccname + "." + ccver
1696
-
1697
- os .Remove (ppath )
1698
-
1699
1671
cds , err := constructDeploymentSpec (ccname , path , ccver , [][]byte {[]byte ("init" ), []byte ("a" ), []byte ("100" ), []byte ("b" ), []byte ("200" )}, false )
1700
1672
if err != nil {
1701
1673
fmt .Printf ("%s\n " , err )
1702
1674
t .FailNow ()
1703
1675
}
1704
1676
cdbytes , err := processSignedCDS (cds , cauthdsl .RejectAllPolicy )
1705
1677
assert .NoError (t , err )
1706
- defer os . Remove ( ppath )
1678
+
1707
1679
var b []byte
1708
1680
if b , err = proto .Marshal (cds ); err != nil || b == nil {
1709
1681
t .FailNow ()
@@ -1996,8 +1968,6 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
1996
1968
assert .EqualError (t , err , "the BlockToLive in the following existing collections must not be modified: [mycollection2]" )
1997
1969
}
1998
1970
1999
- var lccctestpath = "/tmp/lscc-validation-test"
2000
-
2001
1971
func NewMockProvider () * scc.MocksccProviderImpl {
2002
1972
return (& scc.MocksccProviderFactory {
2003
1973
ApplicationConfigBool : true ,
@@ -2008,16 +1978,21 @@ func NewMockProvider() *scc.MocksccProviderImpl {
2008
1978
}
2009
1979
2010
1980
func TestMain (m * testing.M ) {
2011
- ccprovider .SetChaincodesPath (lccctestpath )
1981
+ testDir , err := ioutil .TempDir ("" , "v1.2-validation" )
1982
+ if err != nil {
1983
+ fmt .Printf ("Could not create temp dir: %s" , err )
1984
+ os .Exit (- 1 )
1985
+ }
1986
+ defer os .RemoveAll (testDir )
1987
+ ccprovider .SetChaincodesPath (testDir )
1988
+
2012
1989
policy .RegisterPolicyCheckerFactory (& mockPolicyCheckerFactory {})
2013
1990
2014
1991
mspGetter := func (cid string ) []string {
2015
1992
return []string {"SampleOrg" }
2016
1993
}
2017
1994
2018
- per .MockSetMSPIDGetter (mspGetter )
2019
-
2020
- var err error
1995
+ corepeer .MockSetMSPIDGetter (mspGetter )
2021
1996
2022
1997
// setup the MSP manager so that we can sign/verify
2023
1998
msptesttools .LoadMSPSetupForTesting ()
0 commit comments