Skip to content

Commit

Permalink
[FAB-9312] Resolve metalinter warnings
Browse files Browse the repository at this point in the history
- fix e2e,expiredorderer,expiredpeer,fab,msp package

Change-Id: I39654372f37db182219af1dcb4fa6eb82a287c8c
Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
  • Loading branch information
fqutishat committed Apr 16, 2018
1 parent 041e8e1 commit 7b5d38e
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 202 deletions.
4 changes: 3 additions & 1 deletion gometalinter.json
@@ -1,7 +1,9 @@
{
"Deadline": "5m",
"Exclude": [
".*seekInfo can be .*proto.Message.*"
".*seekInfo can be .*proto.Message.*",
"test/integration/msp/check_cert_attributes.go",
"test/integration/msp/check_cert_ser_attributes_prev.go"
],
"EnableGC": true,
"WarnUnmatchedDirective": true,
Expand Down
120 changes: 63 additions & 57 deletions test/integration/e2e/end_to_end.go
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)
Expand All @@ -35,13 +34,8 @@ const (
orgAdmin = "Admin"
ordererOrgName = "ordererorg"
ccID = "e2eExampleCC"
configPath = "../../fixtures/config/config_test.yaml"
)

func runWithConfigFixture(t *testing.T) {
Run(t, config.FromFile(configPath))
}

// Run enables testing an end-to-end scenario against the supplied SDK options
func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option) {

Expand Down Expand Up @@ -75,17 +69,7 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)

// Org admin user is signing user for creating channel

adminIdentity, err := integration.GetSigningIdentity(sdk, orgAdmin, orgName)
if err != nil {
t.Fatal(err)
}

req := resmgmt.SaveChannelRequest{ChannelID: channelID,
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []msp.SigningIdentity{adminIdentity}}
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")
createChannel(sdk, t, resMgmtClient)

//prepare context
adminContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(orgName))
Expand All @@ -102,29 +86,7 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
}

// Create chaincode package for example cc
ccPkg, err := packager.NewCCPackage("github.com/example_cc", "../../fixtures/testdata")
if err != nil {
t.Fatal(err)
}

// Install example cc to org peers
installCCReq := resmgmt.InstallCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Package: ccPkg}
_, err = orgResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
if err != nil {
t.Fatal(err)
}

// Set up chaincode policy
ccPolicy := cauthdsl.SignedByAnyMember([]string{"Org1MSP"})

// Org resource manager will instantiate 'example_cc' on channel
resp, err := orgResMgmt.InstantiateCC(
channelID,
resmgmt.InstantiateCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy},
resmgmt.WithRetry(retry.DefaultResMgmtOpts),
)
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, resp, "transaction response should be populated")
createCC(t, orgResMgmt)

// ************ Test setup complete ************** //

Expand All @@ -136,12 +98,7 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
t.Fatalf("Failed to create new channel client: %s", err)
}

response, err := client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
}
value := response.Payload
value := queryCC(client, t)

eventID := "test([a-zA-Z]+)"

Expand All @@ -153,11 +110,7 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
defer client.UnregisterChaincodeEvent(reg)

// Move funds
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
executeCC(client, t)

select {
case ccEvent := <-notifier:
Expand All @@ -167,15 +120,68 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
}

// Verify move funds transaction result
response, err = client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
if err != nil {
t.Fatalf("Failed to query funds after transaction: %s", err)
}
verifyFundsIsMoved(client, t, value)

}

func verifyFundsIsMoved(client *channel.Client, t *testing.T, value []byte) {
newValue := queryCC(client, t)
valueInt, _ := strconv.Atoi(string(value))
valueAfterInvokeInt, _ := strconv.Atoi(string(response.Payload))
valueAfterInvokeInt, _ := strconv.Atoi(string(newValue))
if valueInt+1 != valueAfterInvokeInt {
t.Fatalf("Execute failed. Before: %s, after: %s", value, response.Payload)
t.Fatalf("Execute failed. Before: %s, after: %s", value, newValue)
}
}

func executeCC(client *channel.Client, t *testing.T) {
_, err := client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}
}

func queryCC(client *channel.Client, t *testing.T) []byte {
response, err := client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
}
return response.Payload
}

func createCC(t *testing.T, orgResMgmt *resmgmt.Client) {
ccPkg, err := packager.NewCCPackage("github.com/example_cc", "../../fixtures/testdata")
if err != nil {
t.Fatal(err)
}
// Install example cc to org peers
installCCReq := resmgmt.InstallCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Package: ccPkg}
_, err = orgResMgmt.InstallCC(installCCReq, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
if err != nil {
t.Fatal(err)
}
// Set up chaincode policy
ccPolicy := cauthdsl.SignedByAnyMember([]string{"Org1MSP"})
// Org resource manager will instantiate 'example_cc' on channel
resp, err := orgResMgmt.InstantiateCC(
channelID,
resmgmt.InstantiateCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy},
resmgmt.WithRetry(retry.DefaultResMgmtOpts),
)
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, resp, "transaction response should be populated")
}

func createChannel(sdk *fabsdk.FabricSDK, t *testing.T, resMgmtClient *resmgmt.Client) {
adminIdentity, err := integration.GetSigningIdentity(sdk, orgAdmin, orgName)
if err != nil {
t.Fatal(err)
}
req := resmgmt.SaveChannelRequest{ChannelID: channelID,
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []msp.SigningIdentity{adminIdentity}}
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")
}
7 changes: 5 additions & 2 deletions test/integration/e2e/end_to_end_test.go
Expand Up @@ -8,13 +8,16 @@ package e2e

import (
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/test/integration"
)

func TestE2E(t *testing.T) {

//End to End testing
runWithConfigFixture(t)
Run(t, config.FromFile("../../fixtures/config/config_test.yaml"))

//Using setup done set above by end to end test, run below test with new config which has no orderer config inside
runWithNoOrdererConfigFixture(t)
RunWithNoOrdererConfig(t, integration.ConfigNoOrdererBackend)
}
15 changes: 6 additions & 9 deletions test/integration/e2e/no_orderer_config.go
Expand Up @@ -18,12 +18,8 @@ import (
"github.com/hyperledger/fabric-sdk-go/test/integration"
)

func runWithNoOrdererConfigFixture(t *testing.T) {
runWithNoOrdererConfig(t, integration.ConfigNoOrdererBackend)
}

// RunWithNoOrdererConfig enables chclient scenarios using config and sdk options provided
func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option) {
func RunWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option) {

sdk, err := fabsdk.New(configOpt, sdkOpts...)
if err != nil {
Expand Down Expand Up @@ -74,24 +70,25 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts
defer client.UnregisterChaincodeEvent(reg)

// Move funds
response, err = client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
moveFunds(response, client, t, notifier, eventID, value)
}

func moveFunds(response channel.Response, client *channel.Client, t *testing.T, notifier <-chan *fab.CCEvent, eventID string, value []byte) {
response, err := client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCTxArgs()})
if err != nil {
t.Fatalf("Failed to move funds: %s", err)
}

select {
case ccEvent := <-notifier:
t.Logf("Received CC event: %#v\n", ccEvent)
case <-time.After(time.Second * 20):
t.Fatalf("Did NOT receive CC event for eventId(%s)\n", eventID)
}

// Verify move funds transaction result
response, err = client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
if err != nil {
t.Fatalf("Failed to query funds after transaction: %s", err)
}

valueInt, _ := strconv.Atoi(string(value))
valueAfterInvokeInt, _ := strconv.Atoi(string(response.Payload))
if valueInt+1 != valueAfterInvokeInt {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/fab/channel_ledger_test.go
Expand Up @@ -84,6 +84,7 @@ func TestLedgerQueries(t *testing.T) {

// Get a ledger client.
ledgerClient, err := ledger.New(channelClientCtx)
require.Nil(t, err, "ledger new return error")

// Test Query Info - retrieve values before transaction
testTargets := targets[0:1]
Expand Down Expand Up @@ -125,6 +126,8 @@ func TestLedgerQueries(t *testing.T) {

resmgmtClient, err := resmgmt.New(clientCtx)

require.Nil(t, err, "resmgmt new return error")

testInstantiatedChaincodes(t, chaincodeID, channelID, resmgmtClient, targets)

testQueryConfigBlock(t, ledgerClient, targets)
Expand Down

0 comments on commit 7b5d38e

Please sign in to comment.