Skip to content

Commit

Permalink
Fix handlers/validation UT failure on ppc64le
Browse files Browse the repository at this point in the history
FAB-12976 #done

Change-Id: I0afcdb62579b258a0e5fc983745e7d937c77f843
Signed-off-by: Will Lahti <[email protected]>
  • Loading branch information
wlahti authored and ale-linux committed Dec 5, 2018
1 parent f63c95d commit 42689db
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 110 deletions.
85 changes: 30 additions & 55 deletions core/handlers/validation/builtin/v12/validation_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"os"
"testing"

Expand All @@ -34,7 +35,7 @@ import (
"github.com/hyperledger/fabric/core/handlers/validation/api/capabilities"
"github.com/hyperledger/fabric/core/handlers/validation/builtin/v12/mocks"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
per "github.com/hyperledger/fabric/core/peer"
corepeer "github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/policy"
"github.com/hyperledger/fabric/core/scc/lscc"
"github.com/hyperledger/fabric/msp"
Expand Down Expand Up @@ -803,19 +804,15 @@ func TestAlreadyDeployed(t *testing.T) {
state["lscc"] = stublccc.State

ccname := "mycc"
ccver := "1"
ccver := "alreadydeployed"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
if err != nil {
fmt.Printf("%s\n", err)
t.FailNow()
}
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand Down Expand Up @@ -1185,19 +1182,15 @@ func TestValidateUpgradeOK(t *testing.T) {
state["lscc"] = stublccc.State

ccname := "mycc"
ccver := "1"
ccver := "upgradeok"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
if err != nil {
fmt.Printf("%s\n", err)
t.FailNow()
}
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand Down Expand Up @@ -1252,19 +1245,15 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
state["lscc"] = stublccc.State

ccname := "mycc"
ccver := "1"
ccver := "upgradebadversion"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
if err != nil {
fmt.Printf("%s\n", err)
t.FailNow()
}
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand Down Expand Up @@ -1301,7 +1290,7 @@ func TestInvalidateUpgradeBadVersion(t *testing.T) {
assert.Error(t, err)
}

func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
func validateUpgradeWithCollection(t *testing.T, ccver string, V1_2Validation bool) {
state := make(map[string]map[string][]byte)
mp := (&scc.MocksccProviderFactory{
Qe: lm.NewMockQueryExecutor(state),
Expand Down Expand Up @@ -1331,19 +1320,14 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
}

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, true)
if err != nil {
fmt.Printf("%s\n", err)
t.FailNow()
}
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand Down Expand Up @@ -1496,9 +1480,9 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {

func TestValidateUpgradeWithCollection(t *testing.T) {
// with V1_2Validation enabled
validateUpgradeWithCollection(t, true)
validateUpgradeWithCollection(t, "v12-validation-enabled", true)
// with V1_2Validation disabled
validateUpgradeWithCollection(t, false)
validateUpgradeWithCollection(t, "v12-validation-disabled", false)
}

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

ccname := "mycc"
ccver := "1"
ccver := "upgradewithpoliciesok"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, false)
if err != nil {
fmt.Printf("%s\n", err)
t.FailNow()
}
_, err = processSignedCDS(cds, cauthdsl.AcceptAllPolicy)
assert.NoError(t, err)
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand Down Expand Up @@ -1581,11 +1561,11 @@ func TestValidateUpgradeWithNewFailAllIP(t *testing.T) {
// We run this test twice, once with the V11 capability (and expect
// a failure) and once without (and we expect success).

validateUpgradeWithNewFailAllIP(t, true, true)
validateUpgradeWithNewFailAllIP(t, false, false)
validateUpgradeWithNewFailAllIP(t, "v11-capabilityenabled", true, true)
validateUpgradeWithNewFailAllIP(t, "v11-capabilitydisabled", false, false)
}

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

ccname := "mycc"
ccver := "1"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"
ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, false)
if err != nil {
Expand All @@ -1622,7 +1598,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool
}
_, err = processSignedCDS(cds, cauthdsl.AcceptAllPolicy)
assert.NoError(t, err)
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand All @@ -1639,7 +1615,7 @@ func validateUpgradeWithNewFailAllIP(t *testing.T, v11capability, expecterr bool

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

ccver = "2"
ccver = ccver + ".2"

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

ccname := "mycc"
ccver := "1"
ccver := "upgradewithpoliciesfail"
path := "github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd"

ppath := lccctestpath + "/" + ccname + "." + ccver

os.Remove(ppath)

cds, err := constructDeploymentSpec(ccname, path, ccver, [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}, false)
if err != nil {
fmt.Printf("%s\n", err)
t.FailNow()
}
cdbytes, err := processSignedCDS(cds, cauthdsl.RejectAllPolicy)
assert.NoError(t, err)
defer os.Remove(ppath)

var b []byte
if b, err = proto.Marshal(cds); err != nil || b == nil {
t.FailNow()
Expand Down Expand Up @@ -1996,8 +1968,6 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
assert.EqualError(t, err, "the BlockToLive in the following existing collections must not be modified: [mycollection2]")
}

var lccctestpath = "/tmp/lscc-validation-test"

func NewMockProvider() *scc.MocksccProviderImpl {
return (&scc.MocksccProviderFactory{
ApplicationConfigBool: true,
Expand All @@ -2008,16 +1978,21 @@ func NewMockProvider() *scc.MocksccProviderImpl {
}

func TestMain(m *testing.M) {
ccprovider.SetChaincodesPath(lccctestpath)
testDir, err := ioutil.TempDir("", "v1.2-validation")
if err != nil {
fmt.Printf("Could not create temp dir: %s", err)
os.Exit(-1)
}
defer os.RemoveAll(testDir)
ccprovider.SetChaincodesPath(testDir)

policy.RegisterPolicyCheckerFactory(&mockPolicyCheckerFactory{})

mspGetter := func(cid string) []string {
return []string{"SampleOrg"}
}

per.MockSetMSPIDGetter(mspGetter)

var err error
corepeer.MockSetMSPIDGetter(mspGetter)

// setup the MSP manager so that we can sign/verify
msptesttools.LoadMSPSetupForTesting()
Expand Down
Loading

0 comments on commit 42689db

Please sign in to comment.