diff --git a/test/integration/base_test_setup.go b/test/integration/base_test_setup.go index e3fd700e18..8b340d9c0d 100644 --- a/test/integration/base_test_setup.go +++ b/test/integration/base_test_setup.go @@ -442,7 +442,11 @@ func GetKeyName(t *testing.T) string { } //ResetKeys resets given set of keys in example cc to given value -func ResetKeys(t *testing.T, chClient *channel.Client, chaincodeID, value string, keys ...string) { +func ResetKeys(t *testing.T, ctx contextAPI.ChannelProvider, chaincodeID, value string, keys ...string) { + chClient, err := channel.New(ctx) + if err != nil { + t.Fatalf("Failed to create new channel client for reseting keys: %s", err) + } for _, key := range keys { // Synchronous transaction _, err := chClient.Execute( diff --git a/test/integration/pkg/client/channel/channel_client_test.go b/test/integration/pkg/client/channel/channel_client_test.go index 48ce19f983..1782cf5805 100644 --- a/test/integration/pkg/client/channel/channel_client_test.go +++ b/test/integration/pkg/client/channel/channel_client_test.go @@ -43,14 +43,15 @@ func TestChannelClient(t *testing.T) { //prepare context org1ChannelClientContext := sdk.ChannelContext(testSetup.ChannelID, fabsdk.WithUser(org1User), fabsdk.WithOrg(org1Name)) + //Reset example cc keys + integration.ResetKeys(t, org1ChannelClientContext, chaincodeID, "200", aKey, bKey) + //get channel client chClient, err := channel.New(org1ChannelClientContext) if err != nil { t.Fatalf("Failed to create new channel client: %s", err) } - integration.ResetKeys(t, chClient, chaincodeID, "200", aKey, bKey) - // Synchronous query testQuery(t, chClient, "200", chaincodeID, bKey) diff --git a/test/integration/pkg/client/ledger/channel_ledger_test.go b/test/integration/pkg/client/ledger/channel_ledger_test.go index 60597d3455..d8a2aa94fe 100644 --- a/test/integration/pkg/client/ledger/channel_ledger_test.go +++ b/test/integration/pkg/client/ledger/channel_ledger_test.go @@ -68,6 +68,11 @@ func initializeLedgerTests(t *testing.T) (*fabsdk.FabricSDK, []string) { func TestLedgerQueries(t *testing.T) { testSetup := mainTestSetup + aKey := integration.GetKeyName(t) + bKey := integration.GetKeyName(t) + moveTxArg := integration.ExampleCCTxArgs(aKey, bKey, "1") + queryArg := integration.ExampleCCQueryArgs(bKey) + // Setup tests with a random chaincode ID. sdk, targets := initializeLedgerTests(t) @@ -79,9 +84,11 @@ func TestLedgerQueries(t *testing.T) { require.Nil(t, err, "InstallAndInstantiateExampleCC return error") //prepare required contexts - channelClientCtx := sdk.ChannelContext(channelID, fabsdk.WithUser("Admin"), fabsdk.WithOrg(orgName)) + //Reset example cc keys + integration.ResetKeys(t, channelClientCtx, chaincodeID, "200", aKey, bKey) + // Get a ledger client. ledgerClient, err := ledger.New(channelClientCtx) require.Nil(t, err, "ledger new return error") @@ -99,12 +106,12 @@ func TestLedgerQueries(t *testing.T) { t.Fatalf("creating channel failed: %s", err) } - txID, expectedQueryValue, err := changeBlockState(t, channelClient, chaincodeID) + txID, expectedQueryValue, err := changeBlockState(t, channelClient, queryArg, moveTxArg, chaincodeID) if err != nil { t.Fatalf("Failed to change block state (invoke transaction). Return error: %s", err) } - verifyTargetsChangedBlockState(t, channelClient, chaincodeID, targets, expectedQueryValue) + verifyTargetsChangedBlockState(t, channelClient, chaincodeID, targets, queryArg, expectedQueryValue) // Test Query Info - retrieve values after transaction bciAfterTx, err := ledgerClient.QueryInfo(ledger.WithTargetEndpoints(testTargets...)) @@ -135,12 +142,12 @@ func TestLedgerQueries(t *testing.T) { testQueryConfigBlock(t, ledgerClient, targets) } -func changeBlockState(t *testing.T, client *channel.Client, chaincodeID string) (fab.TransactionID, int, error) { +func changeBlockState(t *testing.T, client *channel.Client, queryArg [][]byte, moveArg [][]byte, chaincodeID string) (fab.TransactionID, int, error) { req := channel.Request{ ChaincodeID: chaincodeID, Fcn: "invoke", - Args: integration.ExampleCCDefaultQueryArgs(), + Args: queryArg, } resp, err := client.Query(req, channel.WithRetry(retry.DefaultChannelOpts)) if err != nil { @@ -149,7 +156,7 @@ func changeBlockState(t *testing.T, client *channel.Client, chaincodeID string) value := resp.Payload // Start transaction that will change block state - txID, err := moveFundsAndGetTxID(t, client, chaincodeID) + txID, err := moveFundsAndGetTxID(t, client, moveArg, chaincodeID) if err != nil { return "", 0, errors.WithMessage(err, "move funds failed") } @@ -160,17 +167,17 @@ func changeBlockState(t *testing.T, client *channel.Client, chaincodeID string) return txID, valueInt, nil } -func verifyTargetsChangedBlockState(t *testing.T, client *channel.Client, chaincodeID string, targets []string, expectedValue int) { +func verifyTargetsChangedBlockState(t *testing.T, client *channel.Client, chaincodeID string, targets []string, queryArg [][]byte, expectedValue int) { for _, target := range targets { - verifyTargetChangedBlockState(t, client, chaincodeID, target, expectedValue) + verifyTargetChangedBlockState(t, client, chaincodeID, target, queryArg, expectedValue) } } -func verifyTargetChangedBlockState(t *testing.T, client *channel.Client, chaincodeID string, target string, expectedValue int) { +func verifyTargetChangedBlockState(t *testing.T, client *channel.Client, chaincodeID string, target string, queryArg [][]byte, expectedValue int) { req := channel.Request{ ChaincodeID: chaincodeID, Fcn: "invoke", - Args: integration.ExampleCCDefaultQueryArgs(), + Args: queryArg, } _, err := retry.NewInvoker(retry.New(retry.TestRetryOpts)).Invoke( @@ -290,7 +297,7 @@ func testInstantiatedChaincodes(t *testing.T, ccID string, channelID string, res } // MoveFundsAndGetTxID ... -func moveFundsAndGetTxID(t *testing.T, client *channel.Client, chaincodeID string) (fab.TransactionID, error) { +func moveFundsAndGetTxID(t *testing.T, client *channel.Client, moveArg [][]byte, chaincodeID string) (fab.TransactionID, error) { transientDataMap := make(map[string][]byte) transientDataMap["result"] = []byte("Transient data in move funds...") @@ -298,7 +305,7 @@ func moveFundsAndGetTxID(t *testing.T, client *channel.Client, chaincodeID strin req := channel.Request{ ChaincodeID: chaincodeID, Fcn: "invoke", - Args: integration.ExampleCCDefaultTxArgs(), + Args: moveArg, TransientMap: transientDataMap, } resp, err := client.Execute(req, channel.WithRetry(retry.DefaultChannelOpts)) diff --git a/test/integration/pkg/fabsdk/provider/sdk_provider_test.go b/test/integration/pkg/fabsdk/provider/sdk_provider_test.go index a24cb9ebd3..3af9d529cd 100644 --- a/test/integration/pkg/fabsdk/provider/sdk_provider_test.go +++ b/test/integration/pkg/fabsdk/provider/sdk_provider_test.go @@ -30,6 +30,10 @@ func TestDynamicSelection(t *testing.T) { // Using shared SDK instance to increase test speed. testSetup := mainTestSetup + aKey := integration.GetKeyName(t) + bKey := integration.GetKeyName(t) + moveTxArg := integration.ExampleCCTxArgs(aKey, bKey, "1") + queryArg := integration.ExampleCCQueryArgs(bKey) // Create SDK setup for channel client with dynamic selection sdk, err := fabsdk.New(integration.ConfigBackend, @@ -51,12 +55,15 @@ func TestDynamicSelection(t *testing.T) { //prepare contexts org1ChannelClientContext := sdk.ChannelContext(testSetup.ChannelID, fabsdk.WithUser(org1User), fabsdk.WithOrg(org1Name)) + //Reset example cc keys + integration.ResetKeys(t, org1ChannelClientContext, chaincodeID, "200", aKey, bKey) + chClient, err := channel.New(org1ChannelClientContext) if err != nil { t.Fatalf("Failed to create new channel client: %s", err) } - response, err := chClient.Query(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: integration.ExampleCCDefaultQueryArgs()}, + response, err := chClient.Query(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: queryArg}, channel.WithRetry(retry.DefaultChannelOpts)) if err != nil { t.Fatalf("Failed to query funds: %s", err) @@ -64,21 +71,21 @@ func TestDynamicSelection(t *testing.T) { value := response.Payload // Move funds - response, err = chClient.Execute(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: integration.ExampleCCDefaultTxArgs()}, + response, err = chClient.Execute(channel.Request{ChaincodeID: chaincodeID, Fcn: "invoke", Args: moveTxArg}, channel.WithRetry(retry.DefaultChannelOpts)) if err != nil { t.Fatalf("Failed to move funds: %s", err) } valueInt, _ := strconv.Atoi(string(value)) - verifyValue(t, chClient, valueInt+1, chaincodeID) + verifyValue(t, chClient, queryArg, valueInt+1, chaincodeID) } -func verifyValue(t *testing.T, chClient *channel.Client, expectedValue int, ccID string) { +func verifyValue(t *testing.T, chClient *channel.Client, queryArg [][]byte, expectedValue int, ccID string) { req := channel.Request{ ChaincodeID: ccID, Fcn: "invoke", - Args: integration.ExampleCCDefaultQueryArgs(), + Args: queryArg, } _, err := retry.NewInvoker(retry.New(retry.TestRetryOpts)).Invoke(