diff --git a/.github/workflows/test_weaver-go.yaml b/.github/workflows/test_weaver-go.yaml index 570dd838072..3537d799015 100644 --- a/.github/workflows/test_weaver-go.yaml +++ b/.github/workflows/test_weaver-go.yaml @@ -311,3 +311,33 @@ jobs: - name: Test run: go test -v ./... working-directory: weaver/samples/fabric/simpleassettransfer + + unit_test_sdk_membership: + needs: check_code_changed + if: ${{ needs.check_code_changed.outputs.interopcc_changed == 'true' || needs.check_code_changed.outputs.gosdk_changed == 'true' }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4.1.1 + + - name: Set up Go + uses: actions/setup-go@v4.0.0 + with: + go-version: '1.20.2' + + # FABRIC NETWORK + - name: Start Fabric Network + run: make start-interop-local + working-directory: weaver/tests/network-setups/fabric/dev + + - name: Vendor + run: make run-vendor + working-directory: weaver/sdks/fabric/go-sdk + + - name: Build + run: make build + working-directory: weaver/sdks/fabric/go-sdk + + # Test the MembershipManager + - name: Test + run: GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn CACTI_ROOT=$GITHUB_WORKSPACE go test -v . + working-directory: weaver/sdks/fabric/go-sdk/membershipmanager diff --git a/.github/workflows/weaver_deploy_go-pkgs.yml b/.github/workflows/weaver_deploy_go-pkgs.yml index 47f094a7740..1f23e6a0773 100644 --- a/.github/workflows/weaver_deploy_go-pkgs.yml +++ b/.github/workflows/weaver_deploy_go-pkgs.yml @@ -371,7 +371,7 @@ jobs: working-directory: weaver/sdks/fabric/go-sdk - name: Build test - run: go build -v ./... + run: make build working-directory: weaver/sdks/fabric/go-sdk - name: Check if release already exists diff --git a/tools/go-gen-checksum.sh b/tools/go-gen-checksum.sh index 513a5afd049..9edc10e265e 100755 --- a/tools/go-gen-checksum.sh +++ b/tools/go-gen-checksum.sh @@ -7,7 +7,9 @@ ROOT_DIR=${2:-'..'} REPO='github.com/hyperledger/cacti' # install go-checksum +echo "Installing go-checksum..." go install github.com/vikyd/go-checksum@latest +echo "Installed." GOMODULE_PATHS=("weaver/core/network/fabric-interop-cc/libs/utils" "weaver/core/network/fabric-interop-cc/libs/assetexchange" @@ -63,6 +65,8 @@ for GOMODULE in ${GOMODULE_PATHS[@]}; do echo "------------ END --------------" continue fi + + (cat VERSION | grep "$VERSION") || echo $VERSION > VERSION GOMOD_VERSION=v$(cat VERSION) GOMOD_SUM=$(go-checksum . $GOMOD_NAME@$GOMOD_VERSION | grep "GoCheckSum" | cut -d ' ' -f 2 | cut -d '"' -f 2) GOMOD_DOTMOD_SUM=$(go-checksum go.mod | grep "GoCheckSum" | cut -d ' ' -f 2 | cut -d '"' -f 2) @@ -74,17 +78,17 @@ for GOMODULE in ${GOMODULE_PATHS[@]}; do rm $ROOT_DIR/$GOMOD_PATH/LICENSE pushd $ROOT_DIR/$GOMODULE > /dev/null - UPDATE=false - (cat go.mod | grep -q "$GOMOD_NAME $GOMOD_VERSION") || UPDATE=True - if $UPDATE; then + UPDATE="false" + (cat go.mod | grep -q "$GOMOD_NAME $GOMOD_VERSION") || UPDATE="true" + if [ "$UPDATE" = "true" ]; then go mod edit -require $GOMOD_NAME@$GOMOD_VERSION else echo "ERROR: Version $GOMOD_VERSION already there in go.mod, skipping $GOMOD_PATH in $GOMODULE" fi - UPDATE=false - (cat go.sum | grep -q "$GOMOD_SUM_ENTRY") || UPDATE=True - (cat go.sum | grep -q "$GOMOD_DOTMOD_SUM_ENTRY") || UPDATE=True - if $UPDATE; then + UPDATE="false" + (cat go.sum | grep -q "$GOMOD_SUM_ENTRY") || UPDATE="true" + (cat go.sum | grep -q "$GOMOD_DOTMOD_SUM_ENTRY") || UPDATE="true" + if [ "$UPDATE" = "true" ]; then # mv go.sum go.sum.old # grep -v "$GOMOD_NAME $GOMOD_VERSION" go.sum.old > go.sum echo $GOMOD_SUM_ENTRY >> go.sum @@ -96,4 +100,4 @@ for GOMODULE in ${GOMODULE_PATHS[@]}; do echo "------------ END --------------" done echo "############# END $GOMODULE ################\n" -done \ No newline at end of file +done diff --git a/tools/weaver-update-version.sh b/tools/weaver-update-version.sh index fa033f16212..7fe213f7edf 100755 --- a/tools/weaver-update-version.sh +++ b/tools/weaver-update-version.sh @@ -16,8 +16,8 @@ echo "VERSION: $VERSION" ## Node - Lerna handles it ## GO and Docker -VERSION_FILES=("weaver/common/protos-go -weaver/core/network/fabric-interop-cc/libs/utils" +VERSION_FILES=("weaver/common/protos-go" +"weaver/core/network/fabric-interop-cc/libs/utils" "weaver/core/network/fabric-interop-cc/libs/assetexchange" "weaver/core/network/fabric-interop-cc/interfaces/asset-mgmt" "weaver/core/network/fabric-interop-cc/contracts/interop" diff --git a/weaver/sdks/fabric/go-sdk/Makefile b/weaver/sdks/fabric/go-sdk/Makefile index c05aa47b7fb..1c949f3b46f 100644 --- a/weaver/sdks/fabric/go-sdk/Makefile +++ b/weaver/sdks/fabric/go-sdk/Makefile @@ -9,9 +9,7 @@ undo-vendor: build-local: run-vendor build undo-vendor build: - cd helpers && go build -v . - cd asset-manager && go build -v . - cd interoperablehelper && go build -v . + go build -v ./... test-local: run-vendor test undo-vendor diff --git a/weaver/sdks/fabric/go-sdk/asset-manager/assetManager_test.go b/weaver/sdks/fabric/go-sdk/asset-manager/assetManager_test.go index 34afad05488..62786ac346b 100644 --- a/weaver/sdks/fabric/go-sdk/asset-manager/assetManager_test.go +++ b/weaver/sdks/fabric/go-sdk/asset-manager/assetManager_test.go @@ -4,7 +4,7 @@ Copyright 2020 IBM All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package assetmanager +package assetmanager_test import ( "errors" @@ -12,6 +12,7 @@ import ( "time" "github.com/stretchr/testify/require" + assetmanager "github.com/hyperledger/cacti/weaver/sdks/fabric/go-sdk/v2/asset-manager" ) var submitTransactionMock func() ([]byte, error) @@ -37,53 +38,53 @@ func TestCreateHTLC(t *testing.T) { assetType := "asset-type" assetId := "asset-id" recipientECertBase64 := "recipientECertBase64" - hashBase64 := GenerateSHA256HashInBase64Form("hashPreimage") + hashBase64 := assetmanager.GenerateSHA256HashInBase64Form("hashPreimage") expiryTimeSecs := uint64(time.Now().Unix()) - 10 expectedError := "contract handle not supplied" - _, err := CreateHTLC(nil, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err := assetmanager.CreateHTLC(nil, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset type not supplied" - _, err = CreateHTLC(contract, "", assetId, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateHTLC(contract, "", assetId, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset id not supplied" - _, err = CreateHTLC(contract, assetType, "", recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateHTLC(contract, assetType, "", recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "recipientECertBase64 id not supplied" - _, err = CreateHTLC(contract, assetType, assetId, "", hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateHTLC(contract, assetType, assetId, "", hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "hashBase64 is not supplied" - _, err = CreateHTLC(contract, assetType, assetId, recipientECertBase64, "", expiryTimeSecs) + _, err = assetmanager.CreateHTLC(contract, assetType, assetId, recipientECertBase64, "", expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "supplied expirty time in the past" - _, err = CreateHTLC(contract, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateHTLC(contract, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expiryTimeSecs = uint64(time.Now().Unix()) + 10 - contractId, err := CreateHTLC(contract, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) + contractId, err := assetmanager.CreateHTLC(contract, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -93,7 +94,7 @@ func TestCreateHTLC(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction LockAsset: failed submission" - _, err = CreateHTLC(contract, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateHTLC(contract, assetType, assetId, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -114,49 +115,49 @@ func TestCreateFungibleHTLC(t *testing.T) { expiryTimeSecs := uint64(time.Now().Unix()) - 10 expectedError := "contract handle not supplied" - _, err := CreateFungibleHTLC(nil, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err := assetmanager.CreateFungibleHTLC(nil, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset type not supplied" - _, err = CreateFungibleHTLC(contract, "", numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateFungibleHTLC(contract, "", numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset count must be a positive number" - _, err = CreateFungibleHTLC(contract, assetType, 0, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateFungibleHTLC(contract, assetType, 0, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "recipientECertBase64 id not supplied" - _, err = CreateFungibleHTLC(contract, assetType, numUnits, "", hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateFungibleHTLC(contract, assetType, numUnits, "", hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "hashBase64 is not supplied" - _, err = CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, "", expiryTimeSecs) + _, err = assetmanager.CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, "", expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "supplied expirty time in the past" - _, err = CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expiryTimeSecs = uint64(time.Now().Unix()) + 10 - contractId, err := CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) + contractId, err := assetmanager.CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -166,7 +167,7 @@ func TestCreateFungibleHTLC(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction LockFungibleAsset: failed submission" - _, err = CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) + _, err = assetmanager.CreateFungibleHTLC(contract, assetType, numUnits, recipientECertBase64, hashBase64, expiryTimeSecs) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -186,41 +187,41 @@ func TestIsAssetLockedInHTLC(t *testing.T) { lockerECertBase64 := "lockerECertBase64" expectedError := "contract handle not supplied" - _, err := IsAssetLockedInHTLC(nil, assetType, assetId, recipientECertBase64, lockerECertBase64) + _, err := assetmanager.IsAssetLockedInHTLC(nil, assetType, assetId, recipientECertBase64, lockerECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset type not supplied" - _, err = IsAssetLockedInHTLC(contract, "", assetId, recipientECertBase64, lockerECertBase64) + _, err = assetmanager.IsAssetLockedInHTLC(contract, "", assetId, recipientECertBase64, lockerECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset id not supplied" - _, err = IsAssetLockedInHTLC(contract, assetType, "", recipientECertBase64, lockerECertBase64) + _, err = assetmanager.IsAssetLockedInHTLC(contract, assetType, "", recipientECertBase64, lockerECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "recipientECertBase64 id not supplied" - _, err = IsAssetLockedInHTLC(contract, assetType, assetId, "", lockerECertBase64) + _, err = assetmanager.IsAssetLockedInHTLC(contract, assetType, assetId, "", lockerECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "lockerECertBase64 id not supplied" - _, err = IsAssetLockedInHTLC(contract, assetType, assetId, recipientECertBase64, "") + _, err = assetmanager.IsAssetLockedInHTLC(contract, assetType, assetId, recipientECertBase64, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isLocked, err := IsAssetLockedInHTLC(contract, assetType, assetId, recipientECertBase64, lockerECertBase64) + isLocked, err := assetmanager.IsAssetLockedInHTLC(contract, assetType, assetId, recipientECertBase64, lockerECertBase64) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -230,7 +231,7 @@ func TestIsAssetLockedInHTLC(t *testing.T) { return []byte(""), errors.New("failed evaluation") } expectedError = "error in contract.EvaluateTransaction IsAssetLocked: failed evaluation" - _, err = IsAssetLockedInHTLC(contract, assetType, assetId, recipientECertBase64, lockerECertBase64) + _, err = assetmanager.IsAssetLockedInHTLC(contract, assetType, assetId, recipientECertBase64, lockerECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -247,20 +248,20 @@ func TestIsFungibleAssetLockedInHTLC(t *testing.T) { contractId := "contract-id" expectedError := "contract handle not supplied" - _, err := IsFungibleAssetLockedInHTLC(nil, contractId) + _, err := assetmanager.IsFungibleAssetLockedInHTLC(nil, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "contractId not supplied" - _, err = IsFungibleAssetLockedInHTLC(contract, "") + _, err = assetmanager.IsFungibleAssetLockedInHTLC(contract, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isLocked, err := IsFungibleAssetLockedInHTLC(contract, contractId) + isLocked, err := assetmanager.IsFungibleAssetLockedInHTLC(contract, contractId) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -270,7 +271,7 @@ func TestIsFungibleAssetLockedInHTLC(t *testing.T) { return []byte(""), errors.New("failed evaluation") } expectedError = "error in contract.EvaluateTransaction IsFungibleAssetLocked: failed evaluation" - _, err = IsFungibleAssetLockedInHTLC(contract, contractId) + _, err = assetmanager.IsFungibleAssetLockedInHTLC(contract, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -287,20 +288,20 @@ func TestIsAssetLockedInHTLCqueryUsingContractId(t *testing.T) { contractId := "contract-id" expectedError := "contract handle not supplied" - _, err := IsAssetLockedInHTLCqueryUsingContractId(nil, contractId) + _, err := assetmanager.IsAssetLockedInHTLCqueryUsingContractId(nil, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "contractId not supplied" - _, err = IsAssetLockedInHTLCqueryUsingContractId(contract, "") + _, err = assetmanager.IsAssetLockedInHTLCqueryUsingContractId(contract, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isLocked, err := IsAssetLockedInHTLCqueryUsingContractId(contract, contractId) + isLocked, err := assetmanager.IsAssetLockedInHTLCqueryUsingContractId(contract, contractId) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -310,7 +311,7 @@ func TestIsAssetLockedInHTLCqueryUsingContractId(t *testing.T) { return []byte(""), errors.New("failed evaluation") } expectedError = "error in contract.EvaluateTransaction IsAssetLockedQueryUsingContractId: failed evaluation" - _, err = IsAssetLockedInHTLCqueryUsingContractId(contract, contractId) + _, err = assetmanager.IsAssetLockedInHTLCqueryUsingContractId(contract, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -330,41 +331,41 @@ func TestClaimAssetInHTLC(t *testing.T) { hashPreimageBase64 := "hashPreimageBase64" expectedError := "contract handle not supplied" - _, err := ClaimAssetInHTLC(nil, assetType, assetId, lockerECertBase64, hashPreimageBase64) + _, err := assetmanager.ClaimAssetInHTLC(nil, assetType, assetId, lockerECertBase64, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset type not supplied" - _, err = ClaimAssetInHTLC(contract, "", assetId, lockerECertBase64, hashPreimageBase64) + _, err = assetmanager.ClaimAssetInHTLC(contract, "", assetId, lockerECertBase64, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset id not supplied" - _, err = ClaimAssetInHTLC(contract, assetType, "", lockerECertBase64, hashPreimageBase64) + _, err = assetmanager.ClaimAssetInHTLC(contract, assetType, "", lockerECertBase64, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "lockerECertBase64 id not supplied" - _, err = ClaimAssetInHTLC(contract, assetType, assetId, "", hashPreimageBase64) + _, err = assetmanager.ClaimAssetInHTLC(contract, assetType, assetId, "", hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "hashPreimageBase64 is not supplied" - _, err = ClaimAssetInHTLC(contract, assetType, assetId, lockerECertBase64, "") + _, err = assetmanager.ClaimAssetInHTLC(contract, assetType, assetId, lockerECertBase64, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isClaimed, err := ClaimAssetInHTLC(contract, assetType, assetId, lockerECertBase64, hashPreimageBase64) + isClaimed, err := assetmanager.ClaimAssetInHTLC(contract, assetType, assetId, lockerECertBase64, hashPreimageBase64) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -374,7 +375,7 @@ func TestClaimAssetInHTLC(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction ClaimAsset: failed submission" - _, err = ClaimAssetInHTLC(contract, assetType, assetId, lockerECertBase64, hashPreimageBase64) + _, err = assetmanager.ClaimAssetInHTLC(contract, assetType, assetId, lockerECertBase64, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -392,27 +393,27 @@ func TestClaimFungibleAssetInHTLC(t *testing.T) { hashPreimageBase64 := "hashPreimageBase64" expectedError := "contract handle not supplied" - _, err := ClaimFungibleAssetInHTLC(nil, contractId, hashPreimageBase64) + _, err := assetmanager.ClaimFungibleAssetInHTLC(nil, contractId, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "contractId not supplied" - _, err = ClaimFungibleAssetInHTLC(contract, "", hashPreimageBase64) + _, err = assetmanager.ClaimFungibleAssetInHTLC(contract, "", hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "hashPreimageBase64 is not supplied" - _, err = ClaimFungibleAssetInHTLC(contract, contractId, "") + _, err = assetmanager.ClaimFungibleAssetInHTLC(contract, contractId, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isClaimed, err := ClaimFungibleAssetInHTLC(contract, contractId, hashPreimageBase64) + isClaimed, err := assetmanager.ClaimFungibleAssetInHTLC(contract, contractId, hashPreimageBase64) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -422,7 +423,7 @@ func TestClaimFungibleAssetInHTLC(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction ClaimFungibleAsset: failed submission" - _, err = ClaimFungibleAssetInHTLC(contract, contractId, hashPreimageBase64) + _, err = assetmanager.ClaimFungibleAssetInHTLC(contract, contractId, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -440,27 +441,27 @@ func TestClaimAssetInHTLCusingContractId(t *testing.T) { hashPreimageBase64 := "hashPreimageBase64" expectedError := "contract handle not supplied" - _, err := ClaimAssetInHTLCusingContractId(nil, contractId, hashPreimageBase64) + _, err := assetmanager.ClaimAssetInHTLCusingContractId(nil, contractId, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "contractId not supplied" - _, err = ClaimAssetInHTLCusingContractId(contract, "", hashPreimageBase64) + _, err = assetmanager.ClaimAssetInHTLCusingContractId(contract, "", hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "hashPreimageBase64 is not supplied" - _, err = ClaimAssetInHTLCusingContractId(contract, contractId, "") + _, err = assetmanager.ClaimAssetInHTLCusingContractId(contract, contractId, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isClaimed, err := ClaimAssetInHTLCusingContractId(contract, contractId, hashPreimageBase64) + isClaimed, err := assetmanager.ClaimAssetInHTLCusingContractId(contract, contractId, hashPreimageBase64) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -470,7 +471,7 @@ func TestClaimAssetInHTLCusingContractId(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction ClaimAssetUsingContractId: failed submission" - _, err = ClaimAssetInHTLCusingContractId(contract, contractId, hashPreimageBase64) + _, err = assetmanager.ClaimAssetInHTLCusingContractId(contract, contractId, hashPreimageBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -489,34 +490,34 @@ func TestReclaimAssetInHTLC(t *testing.T) { recipientECertBase64 := "recipientECertBase64" expectedError := "contract handle not supplied" - _, err := ReclaimAssetInHTLC(nil, assetType, assetId, recipientECertBase64) + _, err := assetmanager.ReclaimAssetInHTLC(nil, assetType, assetId, recipientECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset type not supplied" - _, err = ReclaimAssetInHTLC(contract, "", assetId, recipientECertBase64) + _, err = assetmanager.ReclaimAssetInHTLC(contract, "", assetId, recipientECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "asset id not supplied" - _, err = ReclaimAssetInHTLC(contract, assetType, "", recipientECertBase64) + _, err = assetmanager.ReclaimAssetInHTLC(contract, assetType, "", recipientECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "recipientECertBase64 id not supplied" - _, err = ReclaimAssetInHTLC(contract, assetType, assetId, "") + _, err = assetmanager.ReclaimAssetInHTLC(contract, assetType, assetId, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isClaimed, err := ReclaimAssetInHTLC(contract, assetType, assetId, recipientECertBase64) + isClaimed, err := assetmanager.ReclaimAssetInHTLC(contract, assetType, assetId, recipientECertBase64) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -526,7 +527,7 @@ func TestReclaimAssetInHTLC(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction UnlockAsset: failed submission" - _, err = ReclaimAssetInHTLC(contract, assetType, assetId, recipientECertBase64) + _, err = assetmanager.ReclaimAssetInHTLC(contract, assetType, assetId, recipientECertBase64) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -543,20 +544,20 @@ func TestReclaimFungibleAssetInHTLC(t *testing.T) { contractId := "contract-id" expectedError := "contract handle not supplied" - _, err := ReclaimFungibleAssetInHTLC(nil, contractId) + _, err := assetmanager.ReclaimFungibleAssetInHTLC(nil, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "contractId not supplied" - _, err = ReclaimFungibleAssetInHTLC(contract, "") + _, err = assetmanager.ReclaimFungibleAssetInHTLC(contract, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isClaimed, err := ReclaimFungibleAssetInHTLC(contract, contractId) + isClaimed, err := assetmanager.ReclaimFungibleAssetInHTLC(contract, contractId) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -566,7 +567,7 @@ func TestReclaimFungibleAssetInHTLC(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction UnlockFungibleAsset: failed submission" - _, err = ReclaimFungibleAssetInHTLC(contract, contractId) + _, err = assetmanager.ReclaimFungibleAssetInHTLC(contract, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } @@ -583,20 +584,20 @@ func TestReclaimAssetInHTLCusingContractId(t *testing.T) { contractId := "contract-id" expectedError := "contract handle not supplied" - _, err := ReclaimAssetInHTLCusingContractId(nil, contractId) + _, err := assetmanager.ReclaimAssetInHTLCusingContractId(nil, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) expectedError = "contractId not supplied" - _, err = ReclaimAssetInHTLCusingContractId(contract, "") + _, err = assetmanager.ReclaimAssetInHTLCusingContractId(contract, "") if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } require.EqualError(t, err, expectedError) - isClaimed, err := ReclaimAssetInHTLCusingContractId(contract, contractId) + isClaimed, err := assetmanager.ReclaimAssetInHTLCusingContractId(contract, contractId) if err != nil { t.Error("failed with error: ", err.Error()) } @@ -606,7 +607,7 @@ func TestReclaimAssetInHTLCusingContractId(t *testing.T) { return []byte(""), errors.New("failed submission") } expectedError = "error in contract.SubmitTransaction UnlockAssetUsingContractId: failed submission" - _, err = ReclaimAssetInHTLCusingContractId(contract, contractId) + _, err = assetmanager.ReclaimAssetInHTLCusingContractId(contract, contractId) if err == nil { t.Error("expected to fail with error " + expectedError + " but didn't") } diff --git a/weaver/sdks/fabric/go-sdk/helpers/helpers_test.go b/weaver/sdks/fabric/go-sdk/helpers/helpers_test.go index d292be9548f..fac6587132c 100644 --- a/weaver/sdks/fabric/go-sdk/helpers/helpers_test.go +++ b/weaver/sdks/fabric/go-sdk/helpers/helpers_test.go @@ -4,13 +4,14 @@ Copyright 2020 IBM All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package helpers +package helpers_test import ( "fmt" "testing" "github.com/stretchr/testify/require" + helpers "github.com/hyperledger/cacti/weaver/sdks/fabric/go-sdk/v2/helpers" ) func TestParseAddress(t *testing.T) { @@ -18,7 +19,7 @@ func TestParseAddress(t *testing.T) { // Test success with the address passed in the correct format address := "localhost:9080/network1/mychannel:simplestate:Read:Arcturus" addressParts := []string{"localhost:9080", "network1", "mychannel:simplestate:Read:Arcturus"} - retValue, err := ParseAddress(address) + retValue, err := helpers.ParseAddress(address) require.NoError(t, err) require.Equal(t, retValue.LocationSegment, addressParts[0]) require.Equal(t, retValue.NetworkSegment, addressParts[1]) @@ -28,7 +29,7 @@ func TestParseAddress(t *testing.T) { // Test failure with address not passed in the correct format address = "localhost:9080//network1/mychannel:simplestate:Read:Arcturus" expectedErr := "invalid address string " + address - retValue, err = ParseAddress(address) + retValue, err = helpers.ParseAddress(address) require.Error(t, err) require.EqualError(t, err, expectedErr) fmt.Printf("Test failed as expected with error: %s\n", err) diff --git a/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper.go b/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper.go index 30041e69cd7..a33addcd0e4 100644 --- a/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper.go +++ b/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper.go @@ -173,7 +173,7 @@ func getPolicyCriteriaForAddress(contract GatewayContract, address string) ([]st matchingIdentifier = item break } - if validPatternString(item.Pattern) && isPatternAndAddressMatch(item.Pattern, parsedAddress.ViewSegment) && + if ValidPatternString(item.Pattern) && isPatternAndAddressMatch(item.Pattern, parsedAddress.ViewSegment) && (matchingIdentifier.Pattern == "") || (len(item.Pattern) > len(matchingIdentifier.Pattern)) { matchingIdentifier = item break @@ -183,7 +183,7 @@ func getPolicyCriteriaForAddress(contract GatewayContract, address string) ([]st return matchingIdentifier.Policy.Criteria, nil } -func validPatternString(pattern string) bool { +func ValidPatternString(pattern string) bool { // count number of stars in pattern numStars := strings.Count(pattern, "*") @@ -198,7 +198,7 @@ func validPatternString(pattern string) bool { func isPatternAndAddressMatch(pattern string, address string) bool { // make sure the pattern is valid - if !validPatternString(pattern) { + if !ValidPatternString(pattern) { return false } diff --git a/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper_test.go b/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper_test.go index 972821d5408..97e231a5033 100644 --- a/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper_test.go +++ b/weaver/sdks/fabric/go-sdk/interoperablehelper/interoperable-helper_test.go @@ -4,38 +4,39 @@ Copyright 2020 IBM All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package interoperablehelper +package interoperablehelper_test import ( "fmt" "testing" "github.com/stretchr/testify/require" + interoperablehelper "github.com/hyperledger/cacti/weaver/sdks/fabric/go-sdk/v2/interoperablehelper" ) func TestValidPatternString(t *testing.T) { // Test success with the pattern passed in the correct format with just one "*" at the end pattern := "abcd*" - retValue := validPatternString(pattern) + retValue := interoperablehelper.ValidPatternString(pattern) require.Equal(t, retValue, true) fmt.Printf("Test success as the pattern passed correctly with just one star at the end\n") // Test success with the pattern passed in the correct format with no starts pattern = "abcd" - retValue = validPatternString(pattern) + retValue = interoperablehelper.ValidPatternString(pattern) require.Equal(t, retValue, true) fmt.Printf("Test success as with the pattern passed in the correct format with no stars\n") // Test failure with the pattern containing more then one "*" character pattern = "ab*cd*" - retValue = validPatternString(pattern) + retValue = interoperablehelper.ValidPatternString(pattern) require.Equal(t, retValue, false) fmt.Printf("Test failed as expected with pattern containing more than one star\n") // Test failure with the pattern containing one "*" character NOT at the end pattern = "ab*cd" - retValue = validPatternString(pattern) + retValue = interoperablehelper.ValidPatternString(pattern) require.Equal(t, retValue, false) fmt.Printf("Test failed as expected with pattern containing one star but NOT at the end\n") } diff --git a/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager.go b/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager.go index 618aca995b8..09c1522063e 100644 --- a/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager.go +++ b/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager.go @@ -22,6 +22,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "github.com/golang/protobuf/proto" protoV2 "google.golang.org/protobuf/proto" "github.com/hyperledger/fabric-protos-go/common" @@ -149,36 +150,40 @@ func GetConfigBlockFromChannel(walletPath, userName, connectionProfilePath, chan ctx, cancel := context.WithTimeout(context.Background(), seconds*time.Second) defer cancel() - configBlock, err := channel.GetConfigBlock(ctx, connection, clientId, channelId) + configBlockV2, err := channel.GetConfigBlock(ctx, connection, clientId, channelId) if err != nil { return nil, err } + + configBlockBytes, err := protoV2.Marshal(configBlockV2) + var configBlock common.Block + err = proto.Unmarshal(configBlockBytes, &configBlock) - return configBlock, err + return &configBlock, err } func GetMembershipForMspIdFromBlock(block *common.Block, mspId string) (*cactiprotos.Member, error) { var envelope common.Envelope - err := protoV2.Unmarshal((block.GetData().GetData())[0], &envelope) + err := proto.Unmarshal((block.GetData().GetData())[0], &envelope) if err != nil { return nil, err } var payload common.Payload - err = protoV2.Unmarshal(envelope.GetPayload(), &payload) + err = proto.Unmarshal(envelope.GetPayload(), &payload) if err != nil { return nil, err } var channelHeader common.ChannelHeader - err = protoV2.Unmarshal(payload.GetHeader().GetChannelHeader(), &channelHeader) + err = proto.Unmarshal(payload.GetHeader().GetChannelHeader(), &channelHeader) if err != nil { return nil, err } if common.HeaderType(channelHeader.GetType()) == common.HeaderType_CONFIG { var configEnvelope common.ConfigEnvelope - err = protoV2.Unmarshal(payload.GetData(), &configEnvelope) + err = proto.Unmarshal(payload.GetData(), &configEnvelope) if err != nil { return nil, err } @@ -190,7 +195,7 @@ func GetMembershipForMspIdFromBlock(block *common.Block, mspId string) (*cactipr fmt.Println("Warning: Channel Application group has no 'MSP' key") continue } - err = protoV2.Unmarshal(groupValMsp.GetValue(), &mspConfig) + err = proto.Unmarshal(groupValMsp.GetValue(), &mspConfig) if err != nil { return nil, err } @@ -202,7 +207,7 @@ func GetMembershipForMspIdFromBlock(block *common.Block, mspId string) (*cactipr // which is imported by this module. if mspConfig.GetType() == 0 { var fabricMspConfig mspprotos.FabricMSPConfig - err = protoV2.Unmarshal(mspConfig.GetConfig(), &fabricMspConfig) + err = proto.Unmarshal(mspConfig.GetConfig(), &fabricMspConfig) if err != nil { return nil, err } @@ -235,19 +240,19 @@ func GetMembershipForMspIdsFromBlock(block *common.Block, mspIds []string) (*cac } var envelope common.Envelope - err := protoV2.Unmarshal((block.GetData().GetData())[0], &envelope) + err := proto.Unmarshal((block.GetData().GetData())[0], &envelope) if err != nil { return nil, err } var payload common.Payload - err = protoV2.Unmarshal(envelope.GetPayload(), &payload) + err = proto.Unmarshal(envelope.GetPayload(), &payload) if err != nil { return nil, err } var channelHeader common.ChannelHeader - err = protoV2.Unmarshal(payload.GetHeader().GetChannelHeader(), &channelHeader) + err = proto.Unmarshal(payload.GetHeader().GetChannelHeader(), &channelHeader) if err != nil { return nil, err } @@ -257,7 +262,7 @@ func GetMembershipForMspIdsFromBlock(block *common.Block, mspIds []string) (*cac if common.HeaderType(channelHeader.GetType()) == common.HeaderType_CONFIG { var configEnvelope common.ConfigEnvelope - err = protoV2.Unmarshal(payload.GetData(), &configEnvelope) + err = proto.Unmarshal(payload.GetData(), &configEnvelope) if err != nil { return nil, err } @@ -269,7 +274,7 @@ func GetMembershipForMspIdsFromBlock(block *common.Block, mspIds []string) (*cac fmt.Println("Warning: Channel Application group has no 'MSP' key") continue } - err = protoV2.Unmarshal(groupValMsp.GetValue(), &mspConfig) + err = proto.Unmarshal(groupValMsp.GetValue(), &mspConfig) if err != nil { return nil, err } @@ -281,7 +286,7 @@ func GetMembershipForMspIdsFromBlock(block *common.Block, mspIds []string) (*cac // which is imported by this module. if mspConfig.GetType() == 0 { var fabricMspConfig mspprotos.FabricMSPConfig - err = protoV2.Unmarshal(mspConfig.GetConfig(), &fabricMspConfig) + err = proto.Unmarshal(mspConfig.GetConfig(), &fabricMspConfig) if err != nil { return nil, err } @@ -314,19 +319,19 @@ func GetMembershipForAllMspIdsFromBlock(block *common.Block, ordererMspIds []str } var envelope common.Envelope - err := protoV2.Unmarshal((block.GetData().GetData())[0], &envelope) + err := proto.Unmarshal((block.GetData().GetData())[0], &envelope) if err != nil { return nil, err } var payload common.Payload - err = protoV2.Unmarshal(envelope.GetPayload(), &payload) + err = proto.Unmarshal(envelope.GetPayload(), &payload) if err != nil { return nil, err } var channelHeader common.ChannelHeader - err = protoV2.Unmarshal(payload.GetHeader().GetChannelHeader(), &channelHeader) + err = proto.Unmarshal(payload.GetHeader().GetChannelHeader(), &channelHeader) if err != nil { return nil, err } @@ -336,7 +341,7 @@ func GetMembershipForAllMspIdsFromBlock(block *common.Block, ordererMspIds []str if common.HeaderType(channelHeader.GetType()) == common.HeaderType_CONFIG { var configEnvelope common.ConfigEnvelope - err = protoV2.Unmarshal(payload.GetData(), &configEnvelope) + err = proto.Unmarshal(payload.GetData(), &configEnvelope) if err != nil { return nil, err } @@ -348,7 +353,7 @@ func GetMembershipForAllMspIdsFromBlock(block *common.Block, ordererMspIds []str fmt.Println("Warning: Channel Application group has no 'MSP' key") continue } - err = protoV2.Unmarshal(groupValMsp.GetValue(), &mspConfig) + err = proto.Unmarshal(groupValMsp.GetValue(), &mspConfig) if err != nil { return nil, err } @@ -360,7 +365,7 @@ func GetMembershipForAllMspIdsFromBlock(block *common.Block, ordererMspIds []str // which is imported by this module. if mspConfig.GetType() == 0 { var fabricMspConfig mspprotos.FabricMSPConfig - err = protoV2.Unmarshal(mspConfig.GetConfig(), &fabricMspConfig) + err = proto.Unmarshal(mspConfig.GetConfig(), &fabricMspConfig) if err != nil { return nil, err } diff --git a/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager_test.go b/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager_test.go new file mode 100644 index 00000000000..7ff9cf46ad6 --- /dev/null +++ b/weaver/sdks/fabric/go-sdk/membershipmanager/membership_manager_test.go @@ -0,0 +1,64 @@ +/* + Copyright 2020 IBM All Rights Reserved. + + SPDX-License-Identifier: Apache-2.0 + */ + + package membershipmanager_test + + import ( + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/require" + mmsdk "github.com/hyperledger/cacti/weaver/sdks/fabric/go-sdk/v2/membershipmanager" + ) + + +func TestMembershipManager(t *testing.T) { + + cacti_root := os.Getenv("CACTI_ROOT") + walletPath := cacti_root + "/weaver/samples/fabric/fabric-cli/src/wallet-network1" // e.g., /weaver/samples/fabric/fabric-cli/src/wallet-network1/ + userName := "networkadmin" // e.g., networkadmin + connectionProfilePath := cacti_root + "/weaver/tests/network-setups/fabric/shared/network1/peerOrganizations/org1.network1.com/connection-org1.json" // e.g., /weaver/tests/network-setups/fabric/shared/network1/peerOrganizations/org1.network1.com/connection-org1.docker.json" + + fmt.Printf("Wallet Path: %s\n", walletPath) + fmt.Printf("Connection Profile Path: %s\n", connectionProfilePath) + + fmt.Printf("Get Recorded local Membership: ") + member, err := mmsdk.GetMembershipUnit(walletPath, userName, connectionProfilePath, "mychannel", "Org1MSP") + require.NoError(t, err) + fmt.Printf("%+v\n", member) + + fmt.Printf("Get MSP Configuration for Org2MSP: ") + membership, err := mmsdk.GetMSPConfigurations(walletPath, userName, connectionProfilePath, "mychannel", []string{"Org1MSP", "Org2MSP"}) + require.NoError(t, err) + fmt.Printf("%+v\n", membership) + + fmt.Printf("Get All MSP Configuration for Org1MSP: ") + membership, err = mmsdk.GetAllMSPConfigurations(walletPath, userName, connectionProfilePath, "mychannel", []string{"Org1MSP"}) + require.NoError(t, err) + fmt.Printf("%+v\n", membership) + + fmt.Printf("Create Local Membership: ") + err = mmsdk.CreateLocalMembership(walletPath, userName, connectionProfilePath, "network1", "mychannel", "interop", []string{"Org1MSP"}) + require.NoError(t, err) + fmt.Println(err) + + fmt.Printf("Update Local Membership: ") + err = mmsdk.UpdateLocalMembership(walletPath, userName, connectionProfilePath, "network1", "mychannel", "interop", []string{"Org1MSP"}) + require.NoError(t, err) + fmt.Println(err) + + fmt.Printf("Read Local Membership: ") + m, err := mmsdk.ReadMembership(walletPath, userName, connectionProfilePath, "mychannel", "interop", "local-security-domain", []string{"Org1MSP"}) + require.NoError(t, err) + fmt.Println(m) + fmt.Println(err) + + fmt.Printf("Delete Local Membership: ") + err = mmsdk.DeleteLocalMembership(walletPath, userName, connectionProfilePath, "mychannel", "interop", []string{"Org1MSP"}) + require.NoError(t, err) + fmt.Println(err) +} diff --git a/weaver/sdks/fabric/go-sdk/readme.md b/weaver/sdks/fabric/go-sdk/readme.md index 2224bda5bb8..32eb6d30a79 100644 --- a/weaver/sdks/fabric/go-sdk/readme.md +++ b/weaver/sdks/fabric/go-sdk/readme.md @@ -4,6 +4,12 @@ SPDX-License-Identifier: CC-BY-4.0 --> +# Go SDK for Fabric + +**NOTE:** +Due to namespace conflict between `fabric-protos-go` and `fabric-protos-go-apiv2`, use `GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn` flag when using go-sdk at runtime. + + ## Integration tests for `asset-exchange` using go-sdk To run integration tests: - First, [launch a pair of test networks](../../../tests/network-setups/fabric/dev/), one of which must be a Fabric network. @@ -24,47 +30,14 @@ Also note that similar checks need to be carried out for the connection profile ### Testing membership manager functions The [membership manager functions](./membershipmanager) are currently not covered by unit tests. As a temporary measure,below are instructions to test them in a standalone package as follows. -- Copy [membershipmanager/membership_manager.go](./membershipmanager/membership_manager.go) to an empty folder and rename the package to `main`. -- Add a `main` function with the following contents. These are samples, and you can tweak these as needed in your setup. - ```go - func main() { - walletPath := "" // e.g., /weaver/samples/fabric/fabric-cli/src/wallet-network1/ - userName := "networkadmin" // e.g., networkadmin - connectionProfilePath := "" // e.g., /weaver/tests/network-setups/fabric/shared/network1/peerOrganizations/org1.network1.com/connection-org1.docker.json" - - fmt.Printf("Get Recorded local Membership: ") - member, _ := GetMembershipUnit(walletPath, userName, connectionProfilePath, "mychannel", "Org1MSP") - fmt.Printf("%+v\n", member) - - fmt.Printf("Get MSP Configuration for Org2MSP: ") - membership, _ := GetMSPConfigurations(walletPath, userName, connectionProfilePath, "mychannel", []string{"Org1MSP", "Org2MSP"}) - fmt.Printf("%+v\n", membership) - - fmt.Printf("Get All MSP Configuration for Org1MSP: ") - membership, _ = GetAllMSPConfigurations(walletPath, userName, connectionProfilePath, "mychannel", []string{"Org1MSP"}) - fmt.Printf("%+v\n", membership) - - fmt.Printf("Create Local Membership: ") - err := CreateLocalMembership(walletPath, userName, connectionProfilePath, "network1", "mychannel", "interop", []string{"Org1MSP"}) - fmt.Println(err) - - fmt.Printf("Update Local Membership: ") - err = UpdateLocalMembership(walletPath, userName, connectionProfilePath, "network1", "mychannel", "interop", []string{"Org1MSP"}) - fmt.Println(err) - - fmt.Printf("Read Local Membership: ") - m, err := ReadMembership(walletPath, userName, connectionProfilePath, "mychannel", "interop", "local-security-domain", []string{"Org1MSP"}) - fmt.Println(m) - fmt.Println(err) - - fmt.Printf("Delete Local Membership: ") - err = DeleteLocalMembership(walletPath, userName, connectionProfilePath, "mychannel", "interop", []string{"Org1MSP"}) - fmt.Println(err) - } - ``` -- Build the program. +- Build the go-sdk. - Start the Weaver testnet, e.g., by navigating to `/weaver/tests/network-setups/fabric/dev` and running `make start-interop-local`. -- Run the above program. You should see membership contents in the output with no errors. +- From go-sdk, Run (replace `` with path to the cacti clone): + ```bash + cd membershipmanager + GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn CACTI_ROOT= go test -v . + ``` + You should see membership contents in the output with no errors. ## Configurations