Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "[FAB-14298] Enable FabToken with V2_0 capability"
- Loading branch information
Showing
12 changed files
with
2,533 additions
and
54 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
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,105 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package server_test | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/channelconfig" | ||
"github.com/hyperledger/fabric/core/peer" | ||
"github.com/hyperledger/fabric/token/server" | ||
"github.com/hyperledger/fabric/token/server/mock" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
//go:generate counterfeiter -o mock/peer_operations.go -fake-name PeerOperations . peerOperations | ||
|
||
//go:generate counterfeiter -o mock/channel_config.go -fake-name ChannelConfig . channelConfig | ||
|
||
//go:generate counterfeiter -o mock/application_config.go -fake-name ApplicationConfig . applicationConfig | ||
|
||
//go:generate counterfeiter -o mock/application_capabilities.go -fake-name ApplicationCapabilities . applicationCapabilities | ||
|
||
type peerOperations interface { | ||
peer.Operations | ||
} | ||
|
||
type channelConfig interface { | ||
channelconfig.Resources | ||
} | ||
|
||
type applicationConfig interface { | ||
channelconfig.Application | ||
} | ||
|
||
type applicationCapabilities interface { | ||
channelconfig.ApplicationCapabilities | ||
} | ||
|
||
var _ = Describe("CapabilityChecker", func() { | ||
var ( | ||
channelId = "mychannel" | ||
|
||
fakeAppCapabilities *mock.ApplicationCapabilities | ||
fakeAppConfig *mock.ApplicationConfig | ||
fakeChannelConfig *mock.ChannelConfig | ||
fakePeerOperations *mock.PeerOperations | ||
|
||
capabilityChecker *server.TokenCapabilityChecker | ||
) | ||
|
||
BeforeEach(func() { | ||
fakeAppCapabilities = &mock.ApplicationCapabilities{} | ||
fakeAppCapabilities.FabTokenReturns(true) | ||
|
||
fakeAppConfig = &mock.ApplicationConfig{} | ||
fakeAppConfig.CapabilitiesReturns(fakeAppCapabilities) | ||
|
||
fakeChannelConfig = &mock.ChannelConfig{} | ||
fakeChannelConfig.ApplicationConfigReturns(fakeAppConfig, true) | ||
|
||
fakePeerOperations = &mock.PeerOperations{} | ||
fakePeerOperations.GetChannelConfigReturns(fakeChannelConfig) | ||
|
||
capabilityChecker = &server.TokenCapabilityChecker{PeerOps: fakePeerOperations} | ||
}) | ||
|
||
It("returns FabToken true when application capabilities returns true", func() { | ||
fakeAppCapabilities.FabTokenReturns(true) | ||
result, err := capabilityChecker.FabToken(channelId) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(result).To(Equal(true)) | ||
}) | ||
|
||
It("returns FabToken false when application capabilities returns false", func() { | ||
fakeAppCapabilities.FabTokenReturns(false) | ||
result, err := capabilityChecker.FabToken(channelId) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(result).To(Equal(false)) | ||
}) | ||
|
||
Context("when channel config is not found", func() { | ||
BeforeEach(func() { | ||
fakePeerOperations.GetChannelConfigReturns(nil) | ||
}) | ||
|
||
It("returns the error", func() { | ||
_, err := capabilityChecker.FabToken(channelId) | ||
Expect(err).To(MatchError("no channel config found for channel " + channelId)) | ||
}) | ||
}) | ||
|
||
Context("when application config is not found", func() { | ||
BeforeEach(func() { | ||
fakeChannelConfig.ApplicationConfigReturns(nil, false) | ||
}) | ||
|
||
It("returns the error", func() { | ||
_, err := capabilityChecker.FabToken(channelId) | ||
Expect(err).To(MatchError("no application config found for channel " + channelId)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.