-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-4637] Add multi-org integration test
Change-Id: I03fd1fd0dc95c7ebb1222e812ff2cf59fe978615 Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
- Loading branch information
Showing
11 changed files
with
359 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package orgs | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/api" | ||
fabrictxn "github.com/hyperledger/fabric-sdk-go/fabric-txn" | ||
) | ||
|
||
// TestOrgsEndToEnd creates a channel with two organisations, installs chaincode | ||
// on each of them, and finally invokes a transaction on an org2 peer and queries | ||
// the result from an org1 peer | ||
func TestOrgsEndToEnd(t *testing.T) { | ||
// Bootstrap network | ||
initializeFabricClient(t) | ||
loadOrgUsers(t) | ||
loadOrgPeers(t) | ||
loadOrderer(t) | ||
createTestChannel(t) | ||
joinTestChannel(t) | ||
installAndInstantiate(t) | ||
|
||
fmt.Printf("peer0 is %+v, peer1 is %+v\n", orgTestPeer0, orgTestPeer1) | ||
|
||
// Query initial value on org1 peer | ||
orgTestClient.SetUserContext(org1User) | ||
orgTestChannel.SetPrimaryPeer(orgTestPeer0) | ||
result, err := fabrictxn.QueryChaincode(orgTestClient, orgTestChannel, | ||
"exampleCC", generateQueryArgs()) | ||
failTestIfError(err, t) | ||
initialValue, err := strconv.Atoi(result) | ||
failTestIfError(err, t) | ||
|
||
// Change value on org2 peer | ||
orgTestClient.SetUserContext(org2User) | ||
orgTestChannel.SetPrimaryPeer(orgTestPeer1) | ||
err = fabrictxn.InvokeChaincode(orgTestClient, orgTestChannel, []api.Peer{orgTestPeer1}, | ||
peer0EventHub, "exampleCC", generateInvokeArgs(), nil) | ||
failTestIfError(err, t) | ||
|
||
// Assert changed value on org1 peer | ||
orgTestClient.SetUserContext(org1User) | ||
orgTestChannel.SetPrimaryPeer(orgTestPeer0) | ||
result, err = fabrictxn.QueryChaincode(orgTestClient, orgTestChannel, | ||
"exampleCC", generateQueryArgs()) | ||
failTestIfError(err, t) | ||
finalValue, err := strconv.Atoi(result) | ||
failTestIfError(err, t) | ||
|
||
if initialValue+1 != finalValue { | ||
t.Fatalf("Org1 invoke result was not propagated to org2. Expected %d, got: %d", | ||
(initialValue + 1), finalValue) | ||
} | ||
} | ||
|
||
func generateQueryArgs() []string { | ||
var args []string | ||
args = append(args, "invoke") | ||
args = append(args, "query") | ||
args = append(args, "b") | ||
|
||
return args | ||
} | ||
|
||
func generateInvokeArgs() []string { | ||
var args []string | ||
args = append(args, "invoke") | ||
args = append(args, "move") | ||
args = append(args, "a") | ||
args = append(args, "b") | ||
args = append(args, "1") | ||
|
||
return args | ||
} |
Oops, something went wrong.