Skip to content

Commit 42689db

Browse files
wlahtiale-linux
authored andcommitted
Fix handlers/validation UT failure on ppc64le
FAB-12976 #done Change-Id: I0afcdb62579b258a0e5fc983745e7d937c77f843 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent f63c95d commit 42689db

File tree

2 files changed

+60
-110
lines changed

2 files changed

+60
-110
lines changed

core/handlers/validation/builtin/v12/validation_logic_test.go

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"compress/gzip"
1212
"fmt"
13+
"io/ioutil"
1314
"os"
1415
"testing"
1516

@@ -34,7 +35,7 @@ import (
3435
"github.com/hyperledger/fabric/core/handlers/validation/api/capabilities"
3536
"github.com/hyperledger/fabric/core/handlers/validation/builtin/v12/mocks"
3637
"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"
3839
"github.com/hyperledger/fabric/core/policy"
3940
"github.com/hyperledger/fabric/core/scc/lscc"
4041
"github.com/hyperledger/fabric/msp"
@@ -803,19 +804,15 @@ func TestAlreadyDeployed(t *testing.T) {
803804
state["lscc"] = stublccc.State
804805

805806
ccname := "mycc"
806-
ccver := "1"
807+
ccver := "alreadydeployed"
807808
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
808809

809-
ppath := lccctestpath + "/" + ccname + "." + ccver
810-
811-
os.Remove(ppath)
812-
813810
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
814811
if err != nil {
815812
fmt.Printf("%s\n", err)
816813
t.FailNow()
817814
}
818-
defer os.Remove(ppath)
815+
819816
var b []byte
820817
if b, err = proto.Marshal(cds); err != nil || b == nil {
821818
t.FailNow()
@@ -1185,19 +1182,15 @@ func TestValidateUpgradeOK(t *testing.T) {
11851182
state["lscc"] = stublccc.State
11861183

11871184
ccname := "mycc"
1188-
ccver := "1"
1185+
ccver := "upgradeok"
11891186
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
11901187

1191-
ppath := lccctestpath + "/" + ccname + "." + ccver
1192-
1193-
os.Remove(ppath)
1194-
11951188
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
11961189
if err != nil {
11971190
fmt.Printf("%s\n", err)
11981191
t.FailNow()
11991192
}
1200-
defer os.Remove(ppath)
1193+
12011194
var b []byte
12021195
if b, err = proto.Marshal(cds); err != nil || b == nil {
12031196
t.FailNow()
@@ -1252,19 +1245,15 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
12521245
state["lscc"] = stublccc.State
12531246

12541247
ccname := "mycc"
1255-
ccver := "1"
1248+
ccver := "upgradebadversion"
12561249
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
12571250

1258-
ppath := lccctestpath + "/" + ccname + "." + ccver
1259-
1260-
os.Remove(ppath)
1261-
12621251
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
12631252
if err != nil {
12641253
fmt.Printf("%s\n", err)
12651254
t.FailNow()
12661255
}
1267-
defer os.Remove(ppath)
1256+
12681257
var b []byte
12691258
if b, err = proto.Marshal(cds); err != nil || b == nil {
12701259
t.FailNow()
@@ -1301,7 +1290,7 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
13011290
assert.Error(t, err)
13021291
}
13031292

1304-
func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
1293+
func validateUpgradeWithCollection(t *testing.T, ccver string, V1_2Validation bool) {
13051294
state := make(map[string]map[string][]byte)
13061295
mp := (&scc.MocksccProviderFactory{
13071296
Qe: lm.NewMockQueryExecutor(state),
@@ -1331,19 +1320,14 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
13311320
}
13321321

13331322
ccname := "mycc"
1334-
ccver := "1"
13351323
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
13361324

1337-
ppath := lccctestpath + "/" + ccname + "." + ccver
1338-
1339-
os.Remove(ppath)
1340-
13411325
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
13421326
if err != nil {
13431327
fmt.Printf("%s\n", err)
13441328
t.FailNow()
13451329
}
1346-
defer os.Remove(ppath)
1330+
13471331
var b []byte
13481332
if b, err = proto.Marshal(cds); err != nil || b == nil {
13491333
t.FailNow()
@@ -1496,9 +1480,9 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
14961480

14971481
func TestValidateUpgradeWithCollection(t *testing.T) {
14981482
// with V1_2Validation enabled
1499-
validateUpgradeWithCollection(t, true)
1483+
validateUpgradeWithCollection(t, "v12-validation-enabled", true)
15001484
// with V1_2Validation disabled
1501-
validateUpgradeWithCollection(t, false)
1485+
validateUpgradeWithCollection(t, "v12-validation-disabled", false)
15021486
}
15031487

15041488
func TestValidateUpgradeWithPoliciesOK(t *testing.T) {
@@ -1517,21 +1501,17 @@ func TestValidateUpgradeWithPoliciesOK(t *testing.T) {
15171501
state["lscc"] = stublccc.State
15181502

15191503
ccname := "mycc"
1520-
ccver := "1"
1504+
ccver := "upgradewithpoliciesok"
15211505
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
15221506

1523-
ppath := lccctestpath + "/" + ccname + "." + ccver
1524-
1525-
os.Remove(ppath)
1526-
15271507
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, false)
15281508
if err != nil {
15291509
fmt.Printf("%s\n", err)
15301510
t.FailNow()
15311511
}
15321512
_, err = processSignedCDS(cds, cauthdsl.AcceptAllPolicy)
15331513
assert.NoError(t, err)
1534-
defer os.Remove(ppath)
1514+
15351515
var b []byte
15361516
if b, err = proto.Marshal(cds); err != nil || b == nil {
15371517
t.FailNow()
@@ -1581,11 +1561,11 @@ func TestValidateUpgradeWithNewFailAllIP(t *testing.T) {
15811561
// We run this test twice, once with the V11 capability (and expect
15821562
// a failure) and once without (and we expect success).
15831563

1584-
validateUpgradeWithNewFailAllIP(t, true, true)
1585-
validateUpgradeWithNewFailAllIP(t, false, false)
1564+
validateUpgradeWithNewFailAllIP(t, "v11-capabilityenabled", true, true)
1565+
validateUpgradeWithNewFailAllIP(t, "v11-capabilitydisabled", false, false)
15861566
}
15871567

1588-
func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool) {
1568+
func validateUpgradeWithNewFailAllIP(t *testing.T, ccver string, v11capability, expecterr bool) {
15891569
state := make(map[string]map[string][]byte)
15901570
mp := (&scc.MocksccProviderFactory{
15911571
Qe: lm.NewMockQueryExecutor(state),
@@ -1609,11 +1589,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
16091589
// deploy the chaincode with an accept all policy
16101590

16111591
ccname := "mycc"
1612-
ccver := "1"
16131592
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
1614-
ppath := lccctestpath + "/" + ccname + "." + ccver
1615-
1616-
os.Remove(ppath)
16171593

16181594
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, false)
16191595
if err != nil {
@@ -1622,7 +1598,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
16221598
}
16231599
_, err = processSignedCDS(cds, cauthdsl.AcceptAllPolicy)
16241600
assert.NoError(t, err)
1625-
defer os.Remove(ppath)
1601+
16261602
var b []byte
16271603
if b, err = proto.Marshal(cds); err != nil || b == nil {
16281604
t.FailNow()
@@ -1639,7 +1615,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
16391615

16401616
// now we upgrade, with v 2 of the same cc, with the crucial difference that it has a reject all IP
16411617

1642-
ccver = "2"
1618+
ccver = ccver + ".2"
16431619

16441620
simresres, err := createCCDataRWset(ccname, ccname, ccver,
16451621
cauthdsl.MarshaledRejectAllPolicy, // here's where we specify the IP of the upgraded cc
@@ -1689,21 +1665,17 @@ func TestValidateUpgradeWithPoliciesFail(t *testing.T) {
16891665
state["lscc"] = stublccc.State
16901666

16911667
ccname := "mycc"
1692-
ccver := "1"
1668+
ccver := "upgradewithpoliciesfail"
16931669
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
16941670

1695-
ppath := lccctestpath + "/" + ccname + "." + ccver
1696-
1697-
os.Remove(ppath)
1698-
16991671
cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, false)
17001672
if err != nil {
17011673
fmt.Printf("%s\n", err)
17021674
t.FailNow()
17031675
}
17041676
cdbytes, err := processSignedCDS(cds, cauthdsl.RejectAllPolicy)
17051677
assert.NoError(t, err)
1706-
defer os.Remove(ppath)
1678+
17071679
var b []byte
17081680
if b, err = proto.Marshal(cds); err != nil || b == nil {
17091681
t.FailNow()
@@ -1996,8 +1968,6 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
19961968
assert.EqualError(t, err, "the BlockToLive in the following existing collections must not be modified: [mycollection2]")
19971969
}
19981970

1999-
var lccctestpath = "/tmp/lscc-validation-test"
2000-
20011971
func NewMockProvider() *scc.MocksccProviderImpl {
20021972
return (&scc.MocksccProviderFactory{
20031973
ApplicationConfigBool: true,
@@ -2008,16 +1978,21 @@ func NewMockProvider() *scc.MocksccProviderImpl {
20081978
}
20091979

20101980
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+
20121989
policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})
20131990

20141991
mspGetter := func(cid string) []string {
20151992
return []string{"SampleOrg"}
20161993
}
20171994

2018-
per.MockSetMSPIDGetter(mspGetter)
2019-
2020-
var err error
1995+
corepeer.MockSetMSPIDGetter(mspGetter)
20211996

20221997
// setup the MSP manager so that we can sign/verify
20231998
msptesttools.LoadMSPSetupForTesting()

0 commit comments

Comments
 (0)