Skip to content

Commit

Permalink
[FABG-857] Add QueryConfigBlock in ledger client
Browse files Browse the repository at this point in the history
Change-Id: If23d634e31698b446d19ed75e2db5eb5ce26007d
Signed-off-by: Xu Qiaolun <jamesxql@gmail.com>
  • Loading branch information
gotoxu committed Apr 23, 2019
1 parent 745c9b9 commit 75ddf2f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/client/ledger/ledger.go
Expand Up @@ -330,6 +330,19 @@ func (c *Client) QueryConfig(options ...RequestOption) (fab.ChannelCfg, error) {
return channelConfig.Query(reqCtx)
}

// QueryConfigBlock returns the current configuration block for the specified channel.
func (c *Client) QueryConfigBlock(options ...RequestOption) (*common.Block, error) {
targets, opts, err := c.prepareRequestParams(options...)
if err != nil {
return nil, errors.WithMessage(err, "QueryConfigBlock failed to prepare request parameters")
}

reqCtx, cancel := c.createRequestContext(opts)
defer cancel()

return c.ledger.QueryConfigBlock(reqCtx, peersToTxnProcessors(targets), c.verifier)
}

//prepareRequestOpts Reads Opts from Option array
func (c *Client) prepareRequestOpts(options ...RequestOption) (requestOptions, error) {
opts := requestOptions{}
Expand Down
15 changes: 15 additions & 0 deletions pkg/client/ledger/ledger_test.go
Expand Up @@ -276,6 +276,21 @@ func TestQueryConfig(t *testing.T) {

}

func TestQueryConfigBlock(t *testing.T) {
peer := mocks.MockPeer{MockName: "Peer1", MockURL: "http://peer1.com", MockRoles: []string{}, MockCert: nil, Status: 200, MockMSP: "test"}
lc := setupLedgerClient([]fab.Peer{&peer}, t)

_, err := lc.QueryConfigBlock(WithTargets(&peer), WithTargetFilter(&mspFilter{mspID: "test"}))
expected := "If targets are provided, filter cannot be provided"
if err == nil || !strings.Contains(err.Error(), expected) {
t.Fatalf("Test ledger query config should have failed with '%s'", expected)
}

block, err := lc.QueryConfigBlock()
assert.NoError(t, err)
assert.NotNil(t, block)
}

func setupTestChannelService(ctx context.Client, orderers []fab.Orderer) (fab.ChannelService, error) {
chProvider, err := fcmocks.NewMockChannelProvider(ctx)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions test/integration/pkg/client/ledger/channel_ledger_test.go
Expand Up @@ -339,4 +339,12 @@ func testQueryConfigBlock(t *testing.T, ledgerClient *ledger.Client, targets []s
t.Fatal("QueryConfig config data is nil")
}

block, err := ledgerClient.QueryConfigBlock(ledger.WithTargetEndpoints(targets...))
if err != nil {
t.Fatalf("QueryConfigBlock return error: %s", err)
}

if block == nil {
t.Fatal("QueryConfigBlock block is nil")
}
}

0 comments on commit 75ddf2f

Please sign in to comment.