From dcf36eb5bb454934fbaec9f80b2c22e177e54740 Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Wed, 3 May 2017 10:40:04 +0800 Subject: [PATCH] [FAB-3603] Enable more strict code checking * Update the linter script to checking go vet result when `make linter`; * Add the new created idemix path to the check list; * Update source code to pass the more strict checking; * Fix several wrong usages in Error msg. Change-Id: I1ed61745079726df00643206069b56b9846fa1c1 Signed-off-by: Baohua Yang --- common/cauthdsl/cauthdsl_builder.go | 2 +- common/cauthdsl/cauthdsl_test.go | 6 +- common/cauthdsl/policy_test.go | 4 +- common/channelconfig/channel_test.go | 2 +- common/channelconfig/realconfig_test.go | 2 +- common/configtx/configmap.go | 6 +- common/configtx/manager.go | 4 +- common/configtx/update.go | 2 +- common/configtx/update_test.go | 2 +- common/policies/policy_test.go | 36 ++-- common/resourcesconfig/bundle_test.go | 2 +- .../tools/configtxlator/update/update_test.go | 94 +++++------ common/tools/protolator/dynamic_test.go | 4 +- common/tools/protolator/nested_test.go | 4 +- core/admin.go | 8 +- core/admin_test.go | 6 +- core/chaincode/chaincode_support_test.go | 50 +++--- core/chaincode/platforms/golang/env.go | 2 +- core/chaincode/platforms/util/utils_test.go | 6 +- core/chaincode/shim/shim_test.go | 154 +++++++++--------- core/comm/creds.go | 2 +- core/comm/server_test.go | 4 +- .../committer/txvalidator/txvalidator_test.go | 22 +-- core/common/ccpackage/ccpackage_test.go | 2 +- core/common/validation/fullflow_test.go | 2 +- core/fsm.go | 10 +- core/ledger/kvledger/kv_ledger_test.go | 2 +- .../txmgmt/privacyenabledstate/db_test.go | 8 +- .../txmgmt/rwsetutil/rwset_builder_test.go | 16 +- .../txmgmt/rwsetutil/rwset_proto_util_test.go | 42 ++--- .../kvledger/txmgmt/statedb/statedb_test.go | 14 +- core/ledger/ledgerstorage/store_test.go | 6 +- core/ledger/pkg_test.go | 6 +- core/ledger/pvtdatastorage/store_impl_test.go | 12 +- core/ledger/util/util_test.go | 2 +- core/policy/policy.go | 2 +- core/policy/policy_test.go | 8 +- core/scc/lscc/lscc.go | 2 +- core/scc/lscc/lscc_test.go | 10 +- core/scc/qscc/query.go | 2 +- core/scc/rscc/rsccpolicy.go | 2 +- core/scc/vscc/validator_onevalidsignature.go | 2 +- core/transientstore/store_test.go | 12 +- events/consumer/consumer_test.go | 2 +- events/producer/producer_test.go | 2 +- gossip/comm/mock/mock_comm_test.go | 14 +- gossip/privdata/util.go | 4 +- gossip/state/state.go | 2 +- gossip/state/state_test.go | 8 +- msp/idemixmsp.go | 12 +- msp/idemixmsp_test.go | 4 +- orderer/common/deliver/deliver_test.go | 16 +- orderer/common/ledger/blackbox_test.go | 14 +- orderer/common/ledger/file/impl_test.go | 10 +- orderer/common/ledger/json/impl_test.go | 6 +- orderer/common/ledger/ram/impl_test.go | 14 +- .../common/msgprocessor/systemchannel_test.go | 22 +-- .../common/multichannel/blockwriter_test.go | 2 +- .../mocks/common/blockcutter/blockcutter.go | 2 +- .../sample_clients/deliver_stdout/client.go | 2 +- peer/chaincode/list_test.go | 4 +- peer/channel/getinfo.go | 2 +- peer/common/common_test.go | 4 +- protos/common/block_test.go | 2 +- protos/common/common_test.go | 2 +- protos/common/configtx_test.go | 2 +- protos/common/policies_test.go | 4 +- protos/common/signed_data.go | 2 +- protos/gossip/extensions_test.go | 2 +- .../rwset/kvrwset/tests/kv_rwset_test.go | 8 +- protos/ledger/rwset/tests/rwset_test.go | 4 +- protos/utils/blockutils.go | 2 +- protos/utils/txutils_test.go | 10 +- scripts/golinter.sh | 22 ++- 74 files changed, 401 insertions(+), 391 deletions(-) diff --git a/common/cauthdsl/cauthdsl_builder.go b/common/cauthdsl/cauthdsl_builder.go index f71dea36b1c..2eee89bd78c 100644 --- a/common/cauthdsl/cauthdsl_builder.go +++ b/common/cauthdsl/cauthdsl_builder.go @@ -57,7 +57,7 @@ func init() { // Envelope builds an envelope message embedding a SignaturePolicy func Envelope(policy *cb.SignaturePolicy, identities [][]byte) *cb.SignaturePolicyEnvelope { ids := make([]*msp.MSPPrincipal, len(identities)) - for i, _ := range ids { + for i := range ids { ids[i] = &msp.MSPPrincipal{PrincipalClassification: msp.MSPPrincipal_IDENTITY, Principal: identities[i]} } diff --git a/common/cauthdsl/cauthdsl_test.go b/common/cauthdsl/cauthdsl_test.go index 1294bffdc43..f1573ed085f 100644 --- a/common/cauthdsl/cauthdsl_test.go +++ b/common/cauthdsl/cauthdsl_test.go @@ -184,13 +184,13 @@ func TestNilSignaturePolicyEnvelope(t *testing.T) { func TestDeduplicate(t *testing.T) { ids := []*cb.SignedData{ - &cb.SignedData{ + { Identity: []byte("id1"), }, - &cb.SignedData{ + { Identity: []byte("id2"), }, - &cb.SignedData{ + { Identity: []byte("id3"), }, } diff --git a/common/cauthdsl/policy_test.go b/common/cauthdsl/policy_test.go index e010983cc6a..ebc159ae915 100644 --- a/common/cauthdsl/policy_test.go +++ b/common/cauthdsl/policy_test.go @@ -67,7 +67,7 @@ func TestAccept(t *testing.T) { policyID := "policyID" m, err := policies.NewManagerImpl("test", providerMap(), &cb.ConfigGroup{ Policies: map[string]*cb.ConfigPolicy{ - policyID: &cb.ConfigPolicy{Policy: acceptAllPolicy}, + policyID: {Policy: acceptAllPolicy}, }, }) assert.NoError(t, err) @@ -83,7 +83,7 @@ func TestReject(t *testing.T) { policyID := "policyID" m, err := policies.NewManagerImpl("test", providerMap(), &cb.ConfigGroup{ Policies: map[string]*cb.ConfigPolicy{ - policyID: &cb.ConfigPolicy{Policy: rejectAllPolicy}, + policyID: {Policy: rejectAllPolicy}, }, }) assert.NoError(t, err) diff --git a/common/channelconfig/channel_test.go b/common/channelconfig/channel_test.go index 8be6ba7ad9b..3a9ba482649 100644 --- a/common/channelconfig/channel_test.go +++ b/common/channelconfig/channel_test.go @@ -30,7 +30,7 @@ func TestInterface(t *testing.T) { func TestChannelConfig(t *testing.T) { cc, err := NewChannelConfig(&cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - "UnknownGroupKey": &cb.ConfigGroup{}, + "UnknownGroupKey": {}, }, }) assert.Error(t, err) diff --git a/common/channelconfig/realconfig_test.go b/common/channelconfig/realconfig_test.go index f7892be2f7c..77ec1d5564f 100644 --- a/common/channelconfig/realconfig_test.go +++ b/common/channelconfig/realconfig_test.go @@ -29,7 +29,7 @@ func TestWithRealConfigtx(t *testing.T) { }, } conf.Application.Organizations[0].AnchorPeers = []*genesisconfig.AnchorPeer{ - &genesisconfig.AnchorPeer{ + { Host: "foo", Port: 7, }, diff --git a/common/configtx/configmap.go b/common/configtx/configmap.go index 3ffbe8b679f..d138cda0430 100644 --- a/common/configtx/configmap.go +++ b/common/configtx/configmap.go @@ -133,7 +133,7 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG newConfigGroup := cb.NewConfigGroup() proto.Merge(newConfigGroup, group.ConfigGroup) - for key, _ := range group.Groups { + for key := range group.Groups { updatedGroup, err := recurseConfigMap(path+PathSeparator+key, configMap) if err != nil { return nil, err @@ -141,7 +141,7 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG newConfigGroup.Groups[key] = updatedGroup } - for key, _ := range group.Values { + for key := range group.Values { valuePath := ValuePrefix + path + PathSeparator + key value, ok := configMap[valuePath] if !ok { @@ -153,7 +153,7 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG newConfigGroup.Values[key] = proto.Clone(value.ConfigValue).(*cb.ConfigValue) } - for key, _ := range group.Policies { + for key := range group.Policies { policyPath := PolicyPrefix + path + PathSeparator + key policy, ok := configMap[policyPath] if !ok { diff --git a/common/configtx/manager.go b/common/configtx/manager.go index 3952245485a..755363053bf 100644 --- a/common/configtx/manager.go +++ b/common/configtx/manager.go @@ -36,8 +36,8 @@ var ( configAllowedChars = "[a-zA-Z0-9.-]+" maxLength = 249 illegalNames = map[string]struct{}{ - ".": struct{}{}, - "..": struct{}{}, + ".": {}, + "..": {}, } ) diff --git a/common/configtx/update.go b/common/configtx/update.go index 74470e70ccd..0564fd4c015 100644 --- a/common/configtx/update.go +++ b/common/configtx/update.go @@ -113,7 +113,7 @@ func (cm *configManager) verifyDeltaSet(deltaSet map[string]comparable, signedDa } func verifyFullProposedConfig(writeSet, fullProposedConfig map[string]comparable) error { - for key, _ := range writeSet { + for key := range writeSet { if _, ok := fullProposedConfig[key]; !ok { return fmt.Errorf("Writeset contained key %s which did not appear in proposed config", key) } diff --git a/common/configtx/update_test.go b/common/configtx/update_test.go index 0498ae1db88..73135c5bf0d 100644 --- a/common/configtx/update_test.go +++ b/common/configtx/update_test.go @@ -144,7 +144,7 @@ func TestPolicyForItem(t *testing.T) { PolicyManagerVal: &mockpolicies.Manager{ Policy: rootPolicy, SubManagersMap: map[string]*mockpolicies.Manager{ - "foo": &mockpolicies.Manager{ + "foo": { Policy: fooPolicy, }, }, diff --git a/common/policies/policy_test.go b/common/policies/policy_test.go index 770a3160586..e55c06174ac 100644 --- a/common/policies/policy_test.go +++ b/common/policies/policy_test.go @@ -37,9 +37,9 @@ func defaultProviders() map[int32]Provider { func TestUnnestedManager(t *testing.T) { config := &cb.ConfigGroup{ Policies: map[string]*cb.ConfigPolicy{ - "1": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "2": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "3": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, + "1": {Policy: &cb.Policy{Type: mockType}}, + "2": {Policy: &cb.Policy{Type: mockType}}, + "3": {Policy: &cb.Policy{Type: mockType}}, }, } @@ -65,30 +65,30 @@ func TestUnnestedManager(t *testing.T) { func TestNestedManager(t *testing.T) { config := &cb.ConfigGroup{ Policies: map[string]*cb.ConfigPolicy{ - "n0a": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n0b": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n0c": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, + "n0a": {Policy: &cb.Policy{Type: mockType}}, + "n0b": {Policy: &cb.Policy{Type: mockType}}, + "n0c": {Policy: &cb.Policy{Type: mockType}}, }, Groups: map[string]*cb.ConfigGroup{ - "nest1": &cb.ConfigGroup{ + "nest1": { Policies: map[string]*cb.ConfigPolicy{ - "n1a": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n1b": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n1c": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, + "n1a": {Policy: &cb.Policy{Type: mockType}}, + "n1b": {Policy: &cb.Policy{Type: mockType}}, + "n1c": {Policy: &cb.Policy{Type: mockType}}, }, Groups: map[string]*cb.ConfigGroup{ - "nest2a": &cb.ConfigGroup{ + "nest2a": { Policies: map[string]*cb.ConfigPolicy{ - "n2a_1": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n2a_2": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n2a_3": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, + "n2a_1": {Policy: &cb.Policy{Type: mockType}}, + "n2a_2": {Policy: &cb.Policy{Type: mockType}}, + "n2a_3": {Policy: &cb.Policy{Type: mockType}}, }, }, - "nest2b": &cb.ConfigGroup{ + "nest2b": { Policies: map[string]*cb.ConfigPolicy{ - "n2b_1": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n2b_2": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, - "n2b_3": &cb.ConfigPolicy{Policy: &cb.Policy{Type: mockType}}, + "n2b_1": {Policy: &cb.Policy{Type: mockType}}, + "n2b_2": {Policy: &cb.Policy{Type: mockType}}, + "n2b_3": {Policy: &cb.Policy{Type: mockType}}, }, }, }, diff --git a/common/resourcesconfig/bundle_test.go b/common/resourcesconfig/bundle_test.go index 79219d2eb65..5e1e5fdebe9 100644 --- a/common/resourcesconfig/bundle_test.go +++ b/common/resourcesconfig/bundle_test.go @@ -87,7 +87,7 @@ func TestBundleBadSubGroup(t *testing.T) { Groups: map[string]*cb.ConfigGroup{ PeerPoliciesGroupKey: &cb.ConfigGroup{ Values: map[string]*cb.ConfigValue{ - "Foo": &cb.ConfigValue{ + "Foo": { Value: utils.MarshalOrPanic(&pb.Resource{ PolicyRef: "foo", }), diff --git a/common/tools/configtxlator/update/update_test.go b/common/tools/configtxlator/update/update_test.go index 0a44747b8f3..c01f3f0477c 100644 --- a/common/tools/configtxlator/update/update_test.go +++ b/common/tools/configtxlator/update/update_test.go @@ -83,13 +83,13 @@ func TestGroupPolicyModification(t *testing.T) { original := &cb.ConfigGroup{ Version: 4, Policies: map[string]*cb.ConfigPolicy{ - policy1Name: &cb.ConfigPolicy{ + policy1Name: { Version: 2, Policy: &cb.Policy{ Type: 3, }, }, - policy2Name: &cb.ConfigPolicy{ + policy2Name: { Version: 1, Policy: &cb.Policy{ Type: 5, @@ -100,7 +100,7 @@ func TestGroupPolicyModification(t *testing.T) { updated := &cb.ConfigGroup{ Policies: map[string]*cb.ConfigPolicy{ policy1Name: original.Policies[policy1Name], - policy2Name: &cb.ConfigPolicy{ + policy2Name: { Policy: &cb.Policy{ Type: 9, }, @@ -128,7 +128,7 @@ func TestGroupPolicyModification(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version, Policies: map[string]*cb.ConfigPolicy{ - policy2Name: &cb.ConfigPolicy{ + policy2Name: { Policy: &cb.Policy{ Type: updated.Policies[policy2Name].Policy.Type, }, @@ -149,11 +149,11 @@ func TestGroupValueModification(t *testing.T) { original := &cb.ConfigGroup{ Version: 7, Values: map[string]*cb.ConfigValue{ - value1Name: &cb.ConfigValue{ + value1Name: { Version: 3, Value: []byte("value1value"), }, - value2Name: &cb.ConfigValue{ + value2Name: { Version: 6, Value: []byte("value2value"), }, @@ -162,7 +162,7 @@ func TestGroupValueModification(t *testing.T) { updated := &cb.ConfigGroup{ Values: map[string]*cb.ConfigValue{ value1Name: original.Values[value1Name], - value2Name: &cb.ConfigValue{ + value2Name: { Value: []byte("updatedValued2Value"), }, }, @@ -188,7 +188,7 @@ func TestGroupValueModification(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version, Values: map[string]*cb.ConfigValue{ - value2Name: &cb.ConfigValue{ + value2Name: { Value: updated.Values[value2Name].Value, Version: original.Values[value2Name].Version + 1, }, @@ -206,10 +206,10 @@ func TestGroupGroupsModification(t *testing.T) { original := &cb.ConfigGroup{ Version: 7, Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Version: 3, Values: map[string]*cb.ConfigValue{ - "testValue": &cb.ConfigValue{ + "testValue": { Version: 3, }, }, @@ -218,7 +218,7 @@ func TestGroupGroupsModification(t *testing.T) { } updated := &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{}, + subGroupName: {}, }, } @@ -233,7 +233,7 @@ func TestGroupGroupsModification(t *testing.T) { expectedReadSet := &cb.ConfigGroup{ Version: original.Version, Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Version: original.Groups[subGroupName].Version, Policies: map[string]*cb.ConfigPolicy{}, Values: map[string]*cb.ConfigValue{}, @@ -249,7 +249,7 @@ func TestGroupGroupsModification(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version, Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Version: original.Groups[subGroupName].Version + 1, Groups: map[string]*cb.ConfigGroup{}, Policies: map[string]*cb.ConfigPolicy{}, @@ -270,7 +270,7 @@ func TestGroupValueAddition(t *testing.T) { original := &cb.ConfigGroup{ Version: 7, Values: map[string]*cb.ConfigValue{ - value1Name: &cb.ConfigValue{ + value1Name: { Version: 3, Value: []byte("value1value"), }, @@ -279,7 +279,7 @@ func TestGroupValueAddition(t *testing.T) { updated := &cb.ConfigGroup{ Values: map[string]*cb.ConfigValue{ value1Name: original.Values[value1Name], - value2Name: &cb.ConfigValue{ + value2Name: { Version: 9, Value: []byte("newValue2"), }, @@ -297,7 +297,7 @@ func TestGroupValueAddition(t *testing.T) { expectedReadSet := &cb.ConfigGroup{ Version: original.Version, Values: map[string]*cb.ConfigValue{ - value1Name: &cb.ConfigValue{ + value1Name: { Version: original.Values[value1Name].Version, }, }, @@ -310,10 +310,10 @@ func TestGroupValueAddition(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version + 1, Values: map[string]*cb.ConfigValue{ - value1Name: &cb.ConfigValue{ + value1Name: { Version: original.Values[value1Name].Version, }, - value2Name: &cb.ConfigValue{ + value2Name: { Value: updated.Values[value2Name].Value, Version: 0, }, @@ -332,7 +332,7 @@ func TestGroupPolicySwap(t *testing.T) { original := &cb.ConfigGroup{ Version: 4, Policies: map[string]*cb.ConfigPolicy{ - policy1Name: &cb.ConfigPolicy{ + policy1Name: { Version: 2, Policy: &cb.Policy{ Type: 3, @@ -342,7 +342,7 @@ func TestGroupPolicySwap(t *testing.T) { } updated := &cb.ConfigGroup{ Policies: map[string]*cb.ConfigPolicy{ - policy2Name: &cb.ConfigPolicy{ + policy2Name: { Version: 1, Policy: &cb.Policy{ Type: 5, @@ -371,7 +371,7 @@ func TestGroupPolicySwap(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version + 1, Policies: map[string]*cb.ConfigPolicy{ - policy2Name: &cb.ConfigPolicy{ + policy2Name: { Policy: &cb.Policy{ Type: updated.Policies[policy2Name].Policy.Type, }, @@ -393,15 +393,15 @@ func TestComplex(t *testing.T) { original := &cb.ConfigGroup{ Version: 4, Groups: map[string]*cb.ConfigGroup{ - existingGroup1Name: &cb.ConfigGroup{ + existingGroup1Name: { Version: 2, }, - existingGroup2Name: &cb.ConfigGroup{ + existingGroup2Name: { Version: 2, }, }, Policies: map[string]*cb.ConfigPolicy{ - existingPolicyName: &cb.ConfigPolicy{ + existingPolicyName: { Version: 8, Policy: &cb.Policy{ Type: 5, @@ -415,20 +415,20 @@ func TestComplex(t *testing.T) { newValueName := "newValue" updated := &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - existingGroup1Name: &cb.ConfigGroup{}, - newGroupName: &cb.ConfigGroup{ + existingGroup1Name: {}, + newGroupName: { Values: map[string]*cb.ConfigValue{ - newValueName: &cb.ConfigValue{}, + newValueName: {}, }, }, }, Policies: map[string]*cb.ConfigPolicy{ - existingPolicyName: &cb.ConfigPolicy{ + existingPolicyName: { Policy: &cb.Policy{ Type: 5, }, }, - newPolicyName: &cb.ConfigPolicy{ + newPolicyName: { Version: 6, Policy: &cb.Policy{ Type: 5, @@ -448,13 +448,13 @@ func TestComplex(t *testing.T) { expectedReadSet := &cb.ConfigGroup{ Version: original.Version, Policies: map[string]*cb.ConfigPolicy{ - existingPolicyName: &cb.ConfigPolicy{ + existingPolicyName: { Version: original.Policies[existingPolicyName].Version, }, }, Values: map[string]*cb.ConfigValue{}, Groups: map[string]*cb.ConfigGroup{ - existingGroup1Name: &cb.ConfigGroup{ + existingGroup1Name: { Version: original.Groups[existingGroup1Name].Version, }, }, @@ -465,10 +465,10 @@ func TestComplex(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version + 1, Policies: map[string]*cb.ConfigPolicy{ - existingPolicyName: &cb.ConfigPolicy{ + existingPolicyName: { Version: original.Policies[existingPolicyName].Version, }, - newPolicyName: &cb.ConfigPolicy{ + newPolicyName: { Version: 0, Policy: &cb.Policy{ Type: 5, @@ -476,13 +476,13 @@ func TestComplex(t *testing.T) { }, }, Groups: map[string]*cb.ConfigGroup{ - existingGroup1Name: &cb.ConfigGroup{ + existingGroup1Name: { Version: original.Groups[existingGroup1Name].Version, }, - newGroupName: &cb.ConfigGroup{ + newGroupName: { Version: 0, Values: map[string]*cb.ConfigValue{ - newValueName: &cb.ConfigValue{}, + newValueName: {}, }, Policies: map[string]*cb.ConfigPolicy{}, Groups: map[string]*cb.ConfigGroup{}, @@ -501,11 +501,11 @@ func TestTwiceNestedModification(t *testing.T) { valueName := "testValue" original := &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Groups: map[string]*cb.ConfigGroup{ - subSubGroupName: &cb.ConfigGroup{ + subSubGroupName: { Values: map[string]*cb.ConfigValue{ - valueName: &cb.ConfigValue{}, + valueName: {}, }, }, }, @@ -514,11 +514,11 @@ func TestTwiceNestedModification(t *testing.T) { } updated := &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Groups: map[string]*cb.ConfigGroup{ - subSubGroupName: &cb.ConfigGroup{ + subSubGroupName: { Values: map[string]*cb.ConfigValue{ - valueName: &cb.ConfigValue{ + valueName: { ModPolicy: "new", }, }, @@ -539,9 +539,9 @@ func TestTwiceNestedModification(t *testing.T) { expectedReadSet := &cb.ConfigGroup{ Version: original.Version, Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Groups: map[string]*cb.ConfigGroup{ - subSubGroupName: &cb.ConfigGroup{ + subSubGroupName: { Policies: map[string]*cb.ConfigPolicy{}, Values: map[string]*cb.ConfigValue{}, Groups: map[string]*cb.ConfigGroup{}, @@ -560,11 +560,11 @@ func TestTwiceNestedModification(t *testing.T) { expectedWriteSet := &cb.ConfigGroup{ Version: original.Version, Groups: map[string]*cb.ConfigGroup{ - subGroupName: &cb.ConfigGroup{ + subGroupName: { Groups: map[string]*cb.ConfigGroup{ - subSubGroupName: &cb.ConfigGroup{ + subSubGroupName: { Values: map[string]*cb.ConfigValue{ - valueName: &cb.ConfigValue{ + valueName: { Version: original.Groups[subGroupName].Groups[subSubGroupName].Values[valueName].Version + 1, ModPolicy: updated.Groups[subGroupName].Groups[subSubGroupName].Values[valueName].ModPolicy, }, diff --git a/common/tools/protolator/dynamic_test.go b/common/tools/protolator/dynamic_test.go index 8262c6954bc..e4e043eb8e0 100644 --- a/common/tools/protolator/dynamic_test.go +++ b/common/tools/protolator/dynamic_test.go @@ -75,7 +75,7 @@ func TestMapDynamicMsg(t *testing.T) { startMsg := &testprotos.DynamicMsg{ DynamicType: "SimpleMsg", MapDynamicField: map[string]*testprotos.ContextlessMsg{ - mapKey: &testprotos.ContextlessMsg{ + mapKey: { OpaqueField: utils.MarshalOrPanic(&testprotos.SimpleMsg{ PlainField: pfValue, }), @@ -111,7 +111,7 @@ func TestSliceDynamicMsg(t *testing.T) { startMsg := &testprotos.DynamicMsg{ DynamicType: "SimpleMsg", SliceDynamicField: []*testprotos.ContextlessMsg{ - &testprotos.ContextlessMsg{ + { OpaqueField: utils.MarshalOrPanic(&testprotos.SimpleMsg{ PlainField: pfValue, }), diff --git a/common/tools/protolator/nested_test.go b/common/tools/protolator/nested_test.go index 6af47e42575..e8673032e8d 100644 --- a/common/tools/protolator/nested_test.go +++ b/common/tools/protolator/nested_test.go @@ -70,7 +70,7 @@ func TestMapNestedMsg(t *testing.T) { mapKey := "bar" startMsg := &testprotos.NestedMsg{ MapNestedField: map[string]*testprotos.SimpleMsg{ - mapKey: &testprotos.SimpleMsg{ + mapKey: { PlainField: pfValue, }, }, @@ -103,7 +103,7 @@ func TestSliceNestedMsg(t *testing.T) { pfValue := "foo" startMsg := &testprotos.NestedMsg{ SliceNestedField: []*testprotos.SimpleMsg{ - &testprotos.SimpleMsg{ + { PlainField: pfValue, }, }, diff --git a/core/admin.go b/core/admin.go index 3c152758839..6b683070f36 100644 --- a/core/admin.go +++ b/core/admin.go @@ -23,7 +23,7 @@ import ( "golang.org/x/net/context" ) -var log = flogging.MustGetLogger("server") +var logger = flogging.MustGetLogger("server") // NewAdminServer creates and returns a Admin service instance. func NewAdminServer() *ServerAdmin { @@ -38,14 +38,14 @@ type ServerAdmin struct { // GetStatus reports the status of the server func (*ServerAdmin) GetStatus(context.Context, *empty.Empty) (*pb.ServerStatus, error) { status := &pb.ServerStatus{Status: pb.ServerStatus_STARTED} - log.Debugf("returning status: %s", status) + logger.Debugf("returning status: %s", status) return status, nil } // StartServer starts the server func (*ServerAdmin) StartServer(context.Context, *empty.Empty) (*pb.ServerStatus, error) { status := &pb.ServerStatus{Status: pb.ServerStatus_STARTED} - log.Debugf("returning status: %s", status) + logger.Debugf("returning status: %s", status) return status, nil } @@ -64,7 +64,7 @@ func (*ServerAdmin) SetModuleLogLevel(ctx context.Context, request *pb.LogLevelR return logResponse, err } -// RevertLogLevels reverts the log levels for all modules to the level +// RevertLogLevels reverts the logger levels for all modules to the level // defined at the end of peer startup. func (*ServerAdmin) RevertLogLevels(context.Context, *empty.Empty) (*empty.Empty, error) { err := flogging.RevertToPeerStartupLevels() diff --git a/core/admin_test.go b/core/admin_test.go index a5329dca7d1..01f81d88cab 100644 --- a/core/admin_test.go +++ b/core/admin_test.go @@ -52,12 +52,12 @@ func TestLoggingCalls(t *testing.T) { logResponse, err := adminServer.GetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: "test"}) assert.NotNil(t, logResponse, "logResponse should have been set") - assert.Equal(t, flogging.DefaultLevel(), logResponse.LogLevel, "log level should have been the default") + assert.Equal(t, flogging.DefaultLevel(), logResponse.LogLevel, "logger level should have been the default") assert.Nil(t, err, "Error should have been nil") logResponse, err = adminServer.SetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: "test", LogLevel: "debug"}) assert.NotNil(t, logResponse, "logResponse should have been set") - assert.Equal(t, "DEBUG", logResponse.LogLevel, "log level should have been set to debug") + assert.Equal(t, "DEBUG", logResponse.LogLevel, "logger level should have been set to debug") assert.Nil(t, err, "Error should have been nil") _, err = adminServer.RevertLogLevels(context.Background(), &empty.Empty{}) @@ -65,6 +65,6 @@ func TestLoggingCalls(t *testing.T) { logResponse, err = adminServer.GetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: "test"}) assert.NotNil(t, logResponse, "logResponse should have been set") - assert.Equal(t, flogging.DefaultLevel(), logResponse.LogLevel, "log level should have been the default") + assert.Equal(t, flogging.DefaultLevel(), logResponse.LogLevel, "logger level should have been the default") assert.Nil(t, err, "Error should have been nil") } diff --git a/core/chaincode/chaincode_support_test.go b/core/chaincode/chaincode_support_test.go index c234b87cb6d..aaa87870092 100644 --- a/core/chaincode/chaincode_support_test.go +++ b/core/chaincode/chaincode_support_test.go @@ -307,8 +307,8 @@ func startCC(t *testing.T, ccname string) (*mockpeer.MockCCComm, *mockpeer.MockC //start the mock peer go func() { respSet := &mockpeer.MockResponseSet{errorFunc, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}, nil}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}, nil}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY}, nil}}} ccSide.SetResponses(respSet) ccSide.Run() }() @@ -369,7 +369,7 @@ func initializeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCC } chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() @@ -428,7 +428,7 @@ func invokeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCComm) } chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid) @@ -481,7 +481,7 @@ func invokePrivateDataGetPutDelCC(t *testing.T, chainID, ccname string, ccSide * } chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("invokePrivateData")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("invokePrivateData")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid) @@ -529,7 +529,7 @@ func getQueryStateByRange(t *testing.T, collection, chainID, ccname string, ccSi } chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid) @@ -595,7 +595,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock } chaincodeID := &pb.ChaincodeID{Name: calledCC, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("deploycc")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("deploycc")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() //first deploy the new cc to LSCC @@ -617,7 +617,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock //now do the cc2cc chaincodeID = &pb.ChaincodeID{Name: ccname, Version: "0"} - ci = &pb.ChaincodeInput{[][]byte{[]byte("invokecc")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("invokecc")}, Decorations: nil} cis = &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid = util.GenerateUUID() ctxt, txsim, sprop, prop = startTx(t, chainID, cis, txid) @@ -639,13 +639,13 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock sysCCVers := util.GetSysCCVersion() //call a callable system CC, a regular cc, a regular cc on a different chain and an uncallable system cc and expect an error inthe last one respSet := &mockpeer.MockResponseSet{errorFunc, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "lscc:" + sysCCVers}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte{}}}}), Txid: txid}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "calledCC:0/" + chainID}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte{}}}}), Txid: txid}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "calledCC:0/" + chainID2}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte{}}}}), Txid: txid}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "vscc:" + sysCCVers}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte{}}}}), Txid: txid}}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "lscc:" + sysCCVers}, Input: &pb.ChaincodeInput{Args: [][]byte{{}}}}), Txid: txid}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "calledCC:0/" + chainID}, Input: &pb.ChaincodeInput{Args: [][]byte{{}}}}), Txid: txid}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "calledCC:0/" + chainID2}, Input: &pb.ChaincodeInput{Args: [][]byte{{}}}}), Txid: txid}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Payload: putils.MarshalOrPanic(&pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "vscc:" + sysCCVers}, Input: &pb.ChaincodeInput{Args: [][]byte{{}}}}), Txid: txid}}}} respSet2 := &mockpeer.MockResponseSet{nil, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: putils.MarshalOrPanic(&pb.Response{Status: shim.OK, Payload: []byte("OK")}), Txid: txid}}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: putils.MarshalOrPanic(&pb.Response{Status: shim.OK, Payload: []byte("OK")}), Txid: txid}}}} calledCCSide.SetResponses(respSet2) cccid = ccprovider.NewCCContext(chainID, ccname, "0", txid, false, sprop, prop) @@ -656,7 +656,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock //finally lets try a Bad ACL with CC-calling-CC chaincodeID = &pb.ChaincodeID{Name: ccname, Version: "0"} - ci = &pb.ChaincodeInput{[][]byte{[]byte("invokecc")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("invokecc")}, Decorations: nil} cis = &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid = util.GenerateUUID() ctxt, txsim, sprop, prop = startTx(t, chainID, cis, txid) @@ -695,7 +695,7 @@ func getQueryResult(t *testing.T, collection, chainID, ccname string, ccSide *mo } chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid) @@ -707,11 +707,11 @@ func getQueryResult(t *testing.T, collection, chainID, ccname string, ccSide *mo kvs := make([]*plgr.KV, 1000) for i := 0; i < 1000; i++ { - kvs[i] = &plgr.KV{chainID, fmt.Sprintf("%d", i), []byte(fmt.Sprintf("%d", i))} + kvs[i] = &plgr.KV{Namespace: chainID, Key: fmt.Sprintf("%d", i), Value: []byte(fmt.Sprintf("%d", i))} } queryExec := &mockExecQuerySimulator{resultsIter: make(map[string]map[string]*mockResultsIterator)} - queryExec.resultsIter[ccname] = map[string]*mockResultsIterator{"goodquery": &mockResultsIterator{kvs: kvs}} + queryExec.resultsIter[ccname] = map[string]*mockResultsIterator{"goodquery": {kvs: kvs}} queryExec.txsim = ctxt.Value(TXSimulatorKey).(ledger.TxSimulator) ctxt = context.WithValue(ctxt, TXSimulatorKey, queryExec) @@ -763,7 +763,7 @@ func getHistory(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCCom } chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"} - ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}} txid := util.GenerateUUID() ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid) @@ -775,11 +775,11 @@ func getHistory(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCCom kvs := make([]*plgr.KV, 1000) for i := 0; i < 1000; i++ { - kvs[i] = &plgr.KV{chainID, fmt.Sprintf("%d", i), []byte(fmt.Sprintf("%d", i))} + kvs[i] = &plgr.KV{Namespace: chainID, Key: fmt.Sprintf("%d", i), Value: []byte(fmt.Sprintf("%d", i))} } queryExec := &mockExecQuerySimulator{resultsIter: make(map[string]map[string]*mockResultsIterator)} - queryExec.resultsIter[ccname] = map[string]*mockResultsIterator{"goodquery": &mockResultsIterator{kvs: kvs}} + queryExec.resultsIter[ccname] = map[string]*mockResultsIterator{"goodquery": {kvs: kvs}} queryExec.txsim = ctxt.Value(TXSimulatorKey).(ledger.TxSimulator) ctxt = context.WithValue(ctxt, TXSimulatorKey, queryExec) @@ -797,11 +797,11 @@ func getHistory(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCCom } respSet := &mockpeer.MockResponseSet{errorFunc, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_HISTORY_FOR_KEY, Payload: putils.MarshalOrPanic(&pb.GetQueryResult{Query: "goodquery"}), Txid: txid}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, queryStateNextFunc}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, queryStateNextFunc}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR}, queryStateCloseFunc}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: putils.MarshalOrPanic(&pb.Response{Status: shim.OK, Payload: []byte("OK")}), Txid: txid}}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_HISTORY_FOR_KEY, Payload: putils.MarshalOrPanic(&pb.GetQueryResult{Query: "goodquery"}), Txid: txid}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, queryStateNextFunc}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, queryStateNextFunc}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR}, queryStateCloseFunc}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: putils.MarshalOrPanic(&pb.Response{Status: shim.OK, Payload: []byte("OK")}), Txid: txid}}}} cccid := ccprovider.NewCCContext(chainID, ccname, "0", txid, false, sprop, prop) execCC(t, ctxt, ccSide, cccid, false, false, done, cis, respSet) diff --git a/core/chaincode/platforms/golang/env.go b/core/chaincode/platforms/golang/env.go index 2d0eb134bf3..2f8cc4ed44a 100644 --- a/core/chaincode/platforms/golang/env.go +++ b/core/chaincode/platforms/golang/env.go @@ -81,7 +81,7 @@ func splitEnvPaths(value string) Paths { func flattenEnvPaths(paths Paths) string { _paths := make([]string, 0) - for path, _ := range paths { + for path := range paths { _paths = append(_paths, path) } diff --git a/core/chaincode/platforms/util/utils_test.go b/core/chaincode/platforms/util/utils_test.go index 1a682f81047..c6dd23fdea2 100644 --- a/core/chaincode/platforms/util/utils_test.go +++ b/core/chaincode/platforms/util/utils_test.go @@ -230,7 +230,7 @@ func TestHashNonExistentDir(t *testing.T) { b := []byte("firstcontent") hash := util.ComputeSHA256(b) _, err := HashFilesInDir(".", "idontexist", hash, nil) - assert.Error(t, err, "Expected an error for non existent directory %s", "idontexist") + assert.Error(t, err, "Expected an error for non existent directory idontexist") } // TestIsCodeExist tests isCodeExist function @@ -248,12 +248,12 @@ func TestIsCodeExist(t *testing.T) { path = dir + "/blah" err = IsCodeExist(path) assert.Error(err, - "%s directory does not exist, IsCodeExist should have returned error", path) + fmt.Sprintf("%s directory does not exist, IsCodeExist should have returned error", path)) f := createTempFile(t) defer os.Remove(f) err = IsCodeExist(f) - assert.Error(err, "%s is a file, IsCodeExist should have returned error", f) + assert.Error(err, fmt.Sprintf("%s is a file, IsCodeExist should have returned error", f)) } // TestDockerBuild tests DockerBuild function diff --git a/core/chaincode/shim/shim_test.go b/core/chaincode/shim/shim_test.go index c71150d4516..df7b220bbd4 100644 --- a/core/chaincode/shim/shim_test.go +++ b/core/chaincode/shim/shim_test.go @@ -573,7 +573,7 @@ func TestInvoke(t *testing.T) { //start the mock peer go func() { respSet := &mockpeer.MockResponseSet{errorFunc, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}}}} peerSide.SetResponses(respSet) peerSide.SetKeepAlive(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_KEEPALIVE}) err = peerSide.Run() @@ -584,12 +584,12 @@ func TestInvoke(t *testing.T) { peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY, Txid: "1"}) - ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, Decorations: nil} payload := utils.MarshalOrPanic(ci) respSet := &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "2"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "2"}, nil}}} peerSide.SetResponses(respSet) //use the payload computed from prev init @@ -600,14 +600,14 @@ func TestInvoke(t *testing.T) { //good invoke respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("100"), Txid: "3"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("200"), Txid: "3"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "3"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "3"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("100"), Txid: "3"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("200"), Txid: "3"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "3"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "3"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3"}) @@ -616,13 +616,13 @@ func TestInvoke(t *testing.T) { //bad put respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("100"), Txid: "3a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("200"), Txid: "3a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "3a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "3a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3a"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("100"), Txid: "3a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: []byte("200"), Txid: "3a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "3a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "3a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3a"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3a"}) @@ -631,11 +631,11 @@ func TestInvoke(t *testing.T) { //bad get respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "3b"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3b"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE, Txid: "3b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "3b"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3b"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3b"}) @@ -644,11 +644,11 @@ func TestInvoke(t *testing.T) { //bad delete respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_DEL_STATE, Txid: "4"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "4"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_DEL_STATE, Txid: "4"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "4"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("delete"), []byte("A")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("delete"), []byte("A")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "4"}) @@ -657,11 +657,11 @@ func TestInvoke(t *testing.T) { //good delete respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_DEL_STATE, Txid: "4a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "4a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4a"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_DEL_STATE, Txid: "4a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "4a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4a"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("delete"), []byte("A")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("delete"), []byte("A")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "4a"}) @@ -670,10 +670,10 @@ func TestInvoke(t *testing.T) { //bad invoke respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "5"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "5"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("badinvoke")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("badinvoke")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "5"}) @@ -684,8 +684,8 @@ func TestInvoke(t *testing.T) { //create the response rangeQueryResponse := &pb.QueryResponse{Results: []*pb.QueryResultBytes{ - &pb.QueryResultBytes{ResultBytes: utils.MarshalOrPanic(&lproto.KV{"getputcc", "A", []byte("100")})}, - &pb.QueryResultBytes{ResultBytes: utils.MarshalOrPanic(&lproto.KV{"getputcc", "B", []byte("200")})}}, + {ResultBytes: utils.MarshalOrPanic(&lproto.KV{Namespace: "getputcc", Key: "A", Value: []byte("100")})}, + {ResultBytes: utils.MarshalOrPanic(&lproto.KV{Namespace: "getputcc", Key: "B", Value: []byte("200")})}}, HasMore: true} rangeQPayload := utils.MarshalOrPanic(rangeQueryResponse) @@ -693,13 +693,13 @@ func TestInvoke(t *testing.T) { rangeQueryNext := &pb.QueryResponse{Results: nil, HasMore: false} respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: rangeQPayload, Txid: "6"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "6"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: utils.MarshalOrPanic(rangeQueryNext), Txid: "6"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "6"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "6"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: rangeQPayload, Txid: "6"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "6"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: utils.MarshalOrPanic(rangeQueryNext), Txid: "6"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "6"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "6"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6"}) @@ -710,11 +710,11 @@ func TestInvoke(t *testing.T) { //create the response respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: "6a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6a"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: "6a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6a"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6a"}) @@ -725,13 +725,13 @@ func TestInvoke(t *testing.T) { //create the response respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: rangeQPayload, Txid: "6b"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "6b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "6b"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "6b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "6b"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6b"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: rangeQPayload, Txid: "6b"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "6b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "6b"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "6b"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "6b"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6b"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6b"}) @@ -742,13 +742,13 @@ func TestInvoke(t *testing.T) { //create the response respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6c"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: rangeQPayload, Txid: "6c"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "6c"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "6c"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "6c"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "6c"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6c"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_STATE_BY_RANGE, Txid: "6c"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: rangeQPayload, Txid: "6c"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "6c"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "6c"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "6c"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Txid: "6c"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6c"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6c"}) @@ -759,18 +759,18 @@ func TestInvoke(t *testing.T) { //create the response historyQueryResponse := &pb.QueryResponse{Results: []*pb.QueryResultBytes{ - &pb.QueryResultBytes{ResultBytes: utils.MarshalOrPanic(&lproto.KeyModification{TxId: "6", Value: []byte("100")})}}, + {ResultBytes: utils.MarshalOrPanic(&lproto.KeyModification{TxId: "6", Value: []byte("100")})}}, HasMore: true} payload = utils.MarshalOrPanic(historyQueryResponse) respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_HISTORY_FOR_KEY, Txid: "7"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payload, Txid: "7"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "7"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: utils.MarshalOrPanic(rangeQueryNext), Txid: "7"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "7"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "7"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "7"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_HISTORY_FOR_KEY, Txid: "7"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payload, Txid: "7"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "7"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: utils.MarshalOrPanic(rangeQueryNext), Txid: "7"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "7"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "7"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "7"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("historyq"), []byte("A")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("historyq"), []byte("A")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "7"}) @@ -781,11 +781,11 @@ func TestInvoke(t *testing.T) { //create the response respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_HISTORY_FOR_KEY, Txid: "7a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: "7a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "7a"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_HISTORY_FOR_KEY, Txid: "7a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: payload, Txid: "7a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "7a"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("historyq"), []byte("A")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("historyq"), []byte("A")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "7a"}) @@ -796,8 +796,8 @@ func TestInvoke(t *testing.T) { //create the response getQRResp := &pb.QueryResponse{Results: []*pb.QueryResultBytes{ - &pb.QueryResultBytes{ResultBytes: utils.MarshalOrPanic(&lproto.KV{"getputcc", "A", []byte("100")})}, - &pb.QueryResultBytes{ResultBytes: utils.MarshalOrPanic(&lproto.KV{"getputcc", "B", []byte("200")})}}, + {ResultBytes: utils.MarshalOrPanic(&lproto.KV{Namespace: "getputcc", Key: "A", Value: []byte("100")})}, + {ResultBytes: utils.MarshalOrPanic(&lproto.KV{Namespace: "getputcc", Key: "B", Value: []byte("200")})}}, HasMore: true} getQRRespPayload := utils.MarshalOrPanic(getQRResp) @@ -805,13 +805,13 @@ func TestInvoke(t *testing.T) { rangeQueryNext = &pb.QueryResponse{Results: nil, HasMore: false} respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_QUERY_RESULT, Txid: "8"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: getQRRespPayload, Txid: "8"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "8"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: utils.MarshalOrPanic(rangeQueryNext), Txid: "8"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "8"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "8"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "8"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_QUERY_RESULT, Txid: "8"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: getQRRespPayload, Txid: "8"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_NEXT, Txid: "8"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: utils.MarshalOrPanic(rangeQueryNext), Txid: "8"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_QUERY_STATE_CLOSE, Txid: "8"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "8"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "8"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("richq"), []byte("A")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("richq"), []byte("A")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "8"}) @@ -821,11 +821,11 @@ func TestInvoke(t *testing.T) { //query result error respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_QUERY_RESULT, Txid: "8a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: nil, Txid: "8a"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "8a"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_GET_QUERY_RESULT, Txid: "8a"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: nil, Txid: "8a"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "8a"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("richq"), []byte("A")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("richq"), []byte("A")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "8a"}) @@ -853,7 +853,7 @@ func TestStartInProc(t *testing.T) { //start the mock peer go func() { respSet := &mockpeer.MockResponseSet{doneFunc, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}}}} peerSide.SetResponses(respSet) peerSide.SetKeepAlive(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_KEEPALIVE}) err = peerSide.Run() @@ -895,7 +895,7 @@ func TestCC2CC(t *testing.T) { //start the mock peer go func() { respSet := &mockpeer.MockResponseSet{errorFunc, nil, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}}}} peerSide.SetResponses(respSet) peerSide.SetKeepAlive(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_KEEPALIVE}) err = peerSide.Run() @@ -906,12 +906,12 @@ func TestCC2CC(t *testing.T) { peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY, Txid: "1"}) - ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, nil} + ci := &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, Decorations: nil} payload := utils.MarshalOrPanic(ci) respSet := &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "2"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "2"}, nil}}} peerSide.SetResponses(respSet) //use the payload computed from prev init @@ -924,11 +924,11 @@ func TestCC2CC(t *testing.T) { innerResp := utils.MarshalOrPanic(&pb.Response{Status: OK, Payload: []byte("CC2CC rocks")}) cc2ccresp := utils.MarshalOrPanic(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Payload: innerResp}) respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: cc2ccresp, Txid: "3"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Txid: "3"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: cc2ccresp, Txid: "3"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3"}, nil}}} peerSide.SetResponses(respSet) - ci = &pb.ChaincodeInput{[][]byte{[]byte("cc2cc"), []byte("othercc"), []byte("arg1"), []byte("arg2")}, nil} + ci = &pb.ChaincodeInput{Args: [][]byte{[]byte("cc2cc"), []byte("othercc"), []byte("arg1"), []byte("arg2")}, Decorations: nil} payload = utils.MarshalOrPanic(ci) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3"}) @@ -937,8 +937,8 @@ func TestCC2CC(t *testing.T) { //error response cc2cc respSet = &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{ - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Txid: "4"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: cc2ccresp, Txid: "4"}}, - &mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4"}, nil}}} + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_INVOKE_CHAINCODE, Txid: "4"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: cc2ccresp, Txid: "4"}}, + {&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4"}, nil}}} peerSide.SetResponses(respSet) peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "4"}) diff --git a/core/comm/creds.go b/core/comm/creds.go index bba72c2252a..b89a256f27c 100644 --- a/core/comm/creds.go +++ b/core/comm/creds.go @@ -56,7 +56,7 @@ func (sc *serverCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentials. if err := conn.Handshake(); err != nil { return nil, nil, err } - return conn, credentials.TLSInfo{conn.ConnectionState()}, nil + return conn, credentials.TLSInfo{State: conn.ConnectionState()}, nil } // Info provides the ProtocolInfo of this TransportCredentials. diff --git a/core/comm/server_test.go b/core/comm/server_test.go index 00422c975b1..455a8a89711 100644 --- a/core/comm/server_test.go +++ b/core/comm/server_test.go @@ -360,7 +360,7 @@ func TestNewGRPCServerInvalidParameters(t *testing.T) { msgs := [3]string{"listen tcp: lookup tcp/1BBB: nodename nor servname provided, or not known", "listen tcp: unknown port tcp/1BBB", "listen tcp: address tcp/1BBB: unknown port"} - if assert.Error(t, err, "[%s], [%s] or [%s] expected", msgs[0], msgs[1], msgs[2]) { + if assert.Error(t, err, fmt.Sprintf("[%s], [%s] or [%s] expected", msgs[0], msgs[1], msgs[2])) { assert.Contains(t, msgs, err.Error()) } if err != nil { @@ -375,7 +375,7 @@ func TestNewGRPCServerInvalidParameters(t *testing.T) { systems will automatically resolve unknown host names to a "search" address so we just check to make sure that an error was returned */ - assert.Error(t, err, "%s error expected", msg) + assert.Error(t, err, fmt.Sprintf("%s error expected", msg)) if err != nil { t.Log(err.Error()) } diff --git a/core/committer/txvalidator/txvalidator_test.go b/core/committer/txvalidator/txvalidator_test.go index 6628ff5e568..5589185ad21 100644 --- a/core/committer/txvalidator/txvalidator_test.go +++ b/core/committer/txvalidator/txvalidator_test.go @@ -376,19 +376,19 @@ func TestGetTxCCInstance(t *testing.T) { func TestInvalidTXsForUpgradeCC(t *testing.T) { txsChaincodeNames := map[int]*sysccprovider.ChaincodeInstance{ - 0: &sysccprovider.ChaincodeInstance{"chain0", "cc0", "v0"}, // invoke cc0/chain0:v0, should not be affected by upgrade tx in other chain - 1: &sysccprovider.ChaincodeInstance{"chain1", "cc0", "v0"}, // invoke cc0/chain1:v0, should be invalided by cc1/chain1 upgrade tx - 2: &sysccprovider.ChaincodeInstance{"chain1", "lscc", ""}, // upgrade cc0/chain1 to v1, should be invalided by latter cc0/chain1 upgtade tx - 3: &sysccprovider.ChaincodeInstance{"chain1", "cc0", "v0"}, // invoke cc0/chain1:v0, should be invalided by cc1/chain1 upgrade tx - 4: &sysccprovider.ChaincodeInstance{"chain1", "cc0", "v1"}, // invoke cc0/chain1:v1, should be invalided by cc1/chain1 upgrade tx - 5: &sysccprovider.ChaincodeInstance{"chain1", "cc1", "v0"}, // invoke cc1/chain1:v0, should not be affected by other chaincode upgrade tx - 6: &sysccprovider.ChaincodeInstance{"chain1", "lscc", ""}, // upgrade cc0/chain1 to v2, should be invalided by latter cc0/chain1 upgtade tx - 7: &sysccprovider.ChaincodeInstance{"chain1", "lscc", ""}, // upgrade cc0/chain1 to v3 + 0: {"chain0", "cc0", "v0"}, // invoke cc0/chain0:v0, should not be affected by upgrade tx in other chain + 1: {"chain1", "cc0", "v0"}, // invoke cc0/chain1:v0, should be invalided by cc1/chain1 upgrade tx + 2: {"chain1", "lscc", ""}, // upgrade cc0/chain1 to v1, should be invalided by latter cc0/chain1 upgtade tx + 3: {"chain1", "cc0", "v0"}, // invoke cc0/chain1:v0, should be invalided by cc1/chain1 upgrade tx + 4: {"chain1", "cc0", "v1"}, // invoke cc0/chain1:v1, should be invalided by cc1/chain1 upgrade tx + 5: {"chain1", "cc1", "v0"}, // invoke cc1/chain1:v0, should not be affected by other chaincode upgrade tx + 6: {"chain1", "lscc", ""}, // upgrade cc0/chain1 to v2, should be invalided by latter cc0/chain1 upgtade tx + 7: {"chain1", "lscc", ""}, // upgrade cc0/chain1 to v3 } upgradedChaincodes := map[int]*sysccprovider.ChaincodeInstance{ - 2: &sysccprovider.ChaincodeInstance{"chain1", "cc0", "v1"}, - 6: &sysccprovider.ChaincodeInstance{"chain1", "cc0", "v2"}, - 7: &sysccprovider.ChaincodeInstance{"chain1", "cc0", "v3"}, + 2: {"chain1", "cc0", "v1"}, + 6: {"chain1", "cc0", "v2"}, + 7: {"chain1", "cc0", "v3"}, } txsfltr := ledgerUtil.NewTxValidationFlags(8) diff --git a/core/common/ccpackage/ccpackage_test.go b/core/common/ccpackage/ccpackage_test.go index b59cbe2091e..a4496d18f90 100644 --- a/core/common/ccpackage/ccpackage_test.go +++ b/core/common/ccpackage/ccpackage_test.go @@ -39,7 +39,7 @@ func ownerCreateCCDepSpec(codepackage []byte, sigpolicy *common.SignaturePolicyE // create an instantiation policy with just the local msp admin func createInstantiationPolicy(mspid string, role mspprotos.MSPRole_MSPRoleType) *common.SignaturePolicyEnvelope { - principals := []*mspprotos.MSPPrincipal{&mspprotos.MSPPrincipal{ + principals := []*mspprotos.MSPPrincipal{{ PrincipalClassification: mspprotos.MSPPrincipal_ROLE, Principal: utils.MarshalOrPanic(&mspprotos.MSPRole{Role: role, MspIdentifier: mspid})}} sigspolicy := []*common.SignaturePolicy{cauthdsl.SignedBy(int32(0))} diff --git a/core/common/validation/fullflow_test.go b/core/common/validation/fullflow_test.go index ea36564af03..1578eec124f 100644 --- a/core/common/validation/fullflow_test.go +++ b/core/common/validation/fullflow_test.go @@ -462,7 +462,7 @@ func TestInvocationsBadArgs(t *testing.T) { assert.Error(t, err) _, err = validateChaincodeProposalMessage(nil, nil) assert.Error(t, err) - _, err = validateChaincodeProposalMessage(&peer.Proposal{}, &common.Header{[]byte("a"), []byte("a")}) + _, err = validateChaincodeProposalMessage(&peer.Proposal{}, &common.Header{ChannelHeader: []byte("a"), SignatureHeader: []byte("a")}) assert.Error(t, err) } diff --git a/core/fsm.go b/core/fsm.go index 339d831250f..16ca321effa 100644 --- a/core/fsm.go +++ b/core/fsm.go @@ -52,21 +52,21 @@ func NewPeerConnectionFSM(to string) *PeerConnectionFSM { } func (d *PeerConnectionFSM) enterState(e *fsm.Event) { - log.Debugf("The bi-directional stream to %s is %s, from event %s\n", d.To, e.Dst, e.Event) + logger.Debugf("The bi-directional stream to %s is %s, from event %s\n", d.To, e.Dst, e.Event) } func (d *PeerConnectionFSM) beforeHello(e *fsm.Event) { - log.Debugf("Before reception of %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) + logger.Debugf("Before reception of %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) } func (d *PeerConnectionFSM) afterHello(e *fsm.Event) { - log.Debugf("After reception of %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) + logger.Debugf("After reception of %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) } func (d *PeerConnectionFSM) afterPing(e *fsm.Event) { - log.Debugf("After reception of %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) + logger.Debugf("After reception of %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) } func (d *PeerConnectionFSM) beforePing(e *fsm.Event) { - log.Debugf("Before %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) + logger.Debugf("Before %s, dest is %s, current is %s", e.Event, e.Dst, d.FSM.Current()) } diff --git a/core/ledger/kvledger/kv_ledger_test.go b/core/ledger/kvledger/kv_ledger_test.go index 89459b3841d..7256725abb5 100644 --- a/core/ledger/kvledger/kv_ledger_test.go +++ b/core/ledger/kvledger/kv_ledger_test.go @@ -493,7 +493,7 @@ func prepareNextBlockForTest(t *testing.T, l lgr.PeerLedger, bg *testutil.BlockG pubSimBytes, _ := simRes.GetPubSimulationBytes() block := bg.NextBlock([][]byte{pubSimBytes}) return &lgr.BlockAndPvtData{Block: block, - BlockPvtData: map[uint64]*lgr.TxPvtData{0: &lgr.TxPvtData{SeqInBlock: 0, WriteSet: simRes.PvtSimulationResults}}, + BlockPvtData: map[uint64]*lgr.TxPvtData{0: {SeqInBlock: 0, WriteSet: simRes.PvtSimulationResults}}, } } diff --git a/core/ledger/kvledger/txmgmt/privacyenabledstate/db_test.go b/core/ledger/kvledger/txmgmt/privacyenabledstate/db_test.go index 2a9c46132ea..fec91d87c85 100644 --- a/core/ledger/kvledger/txmgmt/privacyenabledstate/db_test.go +++ b/core/ledger/kvledger/txmgmt/privacyenabledstate/db_test.go @@ -159,8 +159,8 @@ func testGetStateMultipleKeys(t *testing.T, env TestEnv) { assert.NoError(t, err) assert.Equal(t, []*statedb.VersionedValue{ - &statedb.VersionedValue{Value: []byte("value1"), Version: version.NewHeight(1, 1)}, - &statedb.VersionedValue{Value: []byte("value3"), Version: version.NewHeight(1, 3)}, + {Value: []byte("value1"), Version: version.NewHeight(1, 1)}, + {Value: []byte("value3"), Version: version.NewHeight(1, 3)}, }, versionedVals) @@ -168,8 +168,8 @@ func testGetStateMultipleKeys(t *testing.T, env TestEnv) { assert.NoError(t, err) assert.Equal(t, []*statedb.VersionedValue{ - &statedb.VersionedValue{Value: []byte("pvt_value1"), Version: version.NewHeight(1, 4)}, - &statedb.VersionedValue{Value: []byte("pvt_value3"), Version: version.NewHeight(1, 6)}, + {Value: []byte("pvt_value1"), Version: version.NewHeight(1, 4)}, + {Value: []byte("pvt_value3"), Version: version.NewHeight(1, 6)}, }, pvtVersionedVals) } diff --git a/core/ledger/kvledger/txmgmt/rwsetutil/rwset_builder_test.go b/core/ledger/kvledger/txmgmt/rwsetutil/rwset_builder_test.go index ecb66f19f15..ee6df49997c 100644 --- a/core/ledger/kvledger/txmgmt/rwsetutil/rwset_builder_test.go +++ b/core/ledger/kvledger/txmgmt/rwsetutil/rwset_builder_test.go @@ -125,20 +125,20 @@ func TestTxSimulationResultWithPvtData(t *testing.T) { expectedPvtRWSet := &rwset.TxPvtReadWriteSet{ DataModel: rwset.TxReadWriteSet_KV, NsPvtRwset: []*rwset.NsPvtReadWriteSet{ - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns1", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll2", Rwset: serializeTestProtoMsg(t, pvt_Ns1_Coll2), }, }, }, - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns2", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll2", Rwset: serializeTestProtoMsg(t, pvt_Ns2_Coll2), }, @@ -190,11 +190,11 @@ func TestTxSimulationResultWithPvtData(t *testing.T) { Namespace: "ns1", Rwset: serializeTestProtoMsg(t, pub_Ns1), CollectionHashedRwset: []*rwset.CollectionHashedReadWriteSet{ - &rwset.CollectionHashedReadWriteSet{ + { CollectionName: "coll1", HashedRwset: serializeTestProtoMsg(t, hashed_Ns1_Coll1), }, - &rwset.CollectionHashedReadWriteSet{ + { CollectionName: "coll2", HashedRwset: serializeTestProtoMsg(t, hashed_Ns1_Coll2), PvtRwsetHash: util.ComputeHash(serializeTestProtoMsg(t, pvt_Ns1_Coll2)), @@ -207,11 +207,11 @@ func TestTxSimulationResultWithPvtData(t *testing.T) { Namespace: "ns2", Rwset: serializeTestProtoMsg(t, pub_Ns2), CollectionHashedRwset: []*rwset.CollectionHashedReadWriteSet{ - &rwset.CollectionHashedReadWriteSet{ + { CollectionName: "coll1", HashedRwset: serializeTestProtoMsg(t, hashed_Ns2_Coll1), }, - &rwset.CollectionHashedReadWriteSet{ + { CollectionName: "coll2", HashedRwset: serializeTestProtoMsg(t, hashed_Ns2_Coll2), PvtRwsetHash: util.ComputeHash(serializeTestProtoMsg(t, pvt_Ns2_Coll2)), diff --git a/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util_test.go b/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util_test.go index 37fd4daa686..1fbab3975f8 100644 --- a/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util_test.go +++ b/core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util_test.go @@ -31,30 +31,30 @@ func TestTxRWSetMarshalUnmarshal(t *testing.T) { rqi1 := &kvrwset.RangeQueryInfo{StartKey: "k0", EndKey: "k9", ItrExhausted: true} rqi1.SetRawReads([]*kvrwset.KVRead{ - &kvrwset.KVRead{Key: "k1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}, - &kvrwset.KVRead{Key: "k2", Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, + {Key: "k1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}, + {Key: "k2", Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, }) rqi2 := &kvrwset.RangeQueryInfo{StartKey: "k00", EndKey: "k90", ItrExhausted: true} rqi2.SetMerkelSummary(&kvrwset.QueryReadsMerkleSummary{MaxDegree: 5, MaxLevel: 4, MaxLevelHashes: [][]byte{[]byte("Hash-1"), []byte("Hash-2")}}) txRwSet.NsRwSets = []*NsRwSet{ - &NsRwSet{NameSpace: "ns1", KvRwSet: &kvrwset.KVRWSet{ - Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, + {NameSpace: "ns1", KvRwSet: &kvrwset.KVRWSet{ + Reads: []*kvrwset.KVRead{{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, RangeQueriesInfo: []*kvrwset.RangeQueryInfo{rqi1}, - Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key2", IsDelete: false, Value: []byte("value2")}}, + Writes: []*kvrwset.KVWrite{{Key: "key2", IsDelete: false, Value: []byte("value2")}}, }}, - &NsRwSet{NameSpace: "ns2", KvRwSet: &kvrwset.KVRWSet{ - Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key3", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, + {NameSpace: "ns2", KvRwSet: &kvrwset.KVRWSet{ + Reads: []*kvrwset.KVRead{{Key: "key3", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, RangeQueriesInfo: []*kvrwset.RangeQueryInfo{rqi2}, - Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key3", IsDelete: false, Value: []byte("value3")}}, + Writes: []*kvrwset.KVWrite{{Key: "key3", IsDelete: false, Value: []byte("value3")}}, }}, - &NsRwSet{NameSpace: "ns3", KvRwSet: &kvrwset.KVRWSet{ - Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key4", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, + {NameSpace: "ns3", KvRwSet: &kvrwset.KVRWSet{ + Reads: []*kvrwset.KVRead{{Key: "key4", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, RangeQueriesInfo: nil, - Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key4", IsDelete: false, Value: []byte("value4")}}, + Writes: []*kvrwset.KVWrite{{Key: "key4", IsDelete: false, Value: []byte("value4")}}, }}, } @@ -124,16 +124,16 @@ func sampleNsRwSetWithNoCollHashedRWs(ns string) *NsRwSet { func sampleKvRwSet() *kvrwset.KVRWSet { rqi1 := &kvrwset.RangeQueryInfo{StartKey: "k0", EndKey: "k9", ItrExhausted: true} rqi1.SetRawReads([]*kvrwset.KVRead{ - &kvrwset.KVRead{Key: "k1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}, - &kvrwset.KVRead{Key: "k2", Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, + {Key: "k1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}, + {Key: "k2", Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, }) rqi2 := &kvrwset.RangeQueryInfo{StartKey: "k00", EndKey: "k90", ItrExhausted: true} rqi2.SetMerkelSummary(&kvrwset.QueryReadsMerkleSummary{MaxDegree: 5, MaxLevel: 4, MaxLevelHashes: [][]byte{[]byte("Hash-1"), []byte("Hash-2")}}) return &kvrwset.KVRWSet{ - Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, + Reads: []*kvrwset.KVRead{{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, RangeQueriesInfo: []*kvrwset.RangeQueryInfo{rqi1}, - Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key2", IsDelete: false, Value: []byte("value2")}}, + Writes: []*kvrwset.KVWrite{{Key: "key2", IsDelete: false, Value: []byte("value2")}}, } } @@ -142,12 +142,12 @@ func sampleCollHashedRwSet(collectionName string) *CollHashedRwSet { CollectionName: collectionName, HashedRwSet: &kvrwset.HashedRWSet{ HashedReads: []*kvrwset.KVReadHash{ - &kvrwset.KVReadHash{KeyHash: []byte("Key-1-hash"), Version: &kvrwset.Version{1, 2}}, - &kvrwset.KVReadHash{KeyHash: []byte("Key-2-hash"), Version: &kvrwset.Version{2, 3}}, + {KeyHash: []byte("Key-1-hash"), Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, + {KeyHash: []byte("Key-2-hash"), Version: &kvrwset.Version{BlockNum: 2, TxNum: 3}}, }, HashedWrites: []*kvrwset.KVWriteHash{ - &kvrwset.KVWriteHash{KeyHash: []byte("Key-3-hash"), ValueHash: []byte("value-3-hash"), IsDelete: false}, - &kvrwset.KVWriteHash{KeyHash: []byte("Key-4-hash"), ValueHash: []byte("value-4-hash"), IsDelete: true}, + {KeyHash: []byte("Key-3-hash"), ValueHash: []byte("value-3-hash"), IsDelete: false}, + {KeyHash: []byte("Key-4-hash"), ValueHash: []byte("value-4-hash"), IsDelete: true}, }, }, PvtRwSetHash: []byte(collectionName + "-pvt-rwset-hash"), @@ -186,8 +186,8 @@ func sampleNsPvtRwSet(ns string) *NsPvtRwSet { func sampleCollPvtRwSet(collectionName string) *CollPvtRwSet { return &CollPvtRwSet{CollectionName: collectionName, KvRwSet: &kvrwset.KVRWSet{ - Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, - Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key2", IsDelete: false, Value: []byte("value2")}}, + Reads: []*kvrwset.KVRead{{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, + Writes: []*kvrwset.KVWrite{{Key: "key2", IsDelete: false, Value: []byte("value2")}}, }} } diff --git a/core/ledger/kvledger/txmgmt/statedb/statedb_test.go b/core/ledger/kvledger/txmgmt/statedb/statedb_test.go index caaa1efded5..71c24608648 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statedb_test.go +++ b/core/ledger/kvledger/txmgmt/statedb/statedb_test.go @@ -105,19 +105,19 @@ func TestUpdateBatchIterator(t *testing.T) { batch.Put("ns2", "key4", []byte("value4"), version.NewHeight(2, 1)) checkItrResults(t, batch.GetRangeScanIterator("ns1", "key2", "key3"), []*VersionedKV{ - &VersionedKV{CompositeKey{"ns1", "key2"}, VersionedValue{[]byte("value2"), version.NewHeight(1, 2)}}, + {CompositeKey{"ns1", "key2"}, VersionedValue{[]byte("value2"), version.NewHeight(1, 2)}}, }) checkItrResults(t, batch.GetRangeScanIterator("ns2", "key0", "key8"), []*VersionedKV{ - &VersionedKV{CompositeKey{"ns2", "key4"}, VersionedValue{[]byte("value4"), version.NewHeight(2, 1)}}, - &VersionedKV{CompositeKey{"ns2", "key5"}, VersionedValue{[]byte("value5"), version.NewHeight(2, 2)}}, - &VersionedKV{CompositeKey{"ns2", "key6"}, VersionedValue{[]byte("value6"), version.NewHeight(2, 3)}}, + {CompositeKey{"ns2", "key4"}, VersionedValue{[]byte("value4"), version.NewHeight(2, 1)}}, + {CompositeKey{"ns2", "key5"}, VersionedValue{[]byte("value5"), version.NewHeight(2, 2)}}, + {CompositeKey{"ns2", "key6"}, VersionedValue{[]byte("value6"), version.NewHeight(2, 3)}}, }) checkItrResults(t, batch.GetRangeScanIterator("ns2", "", ""), []*VersionedKV{ - &VersionedKV{CompositeKey{"ns2", "key4"}, VersionedValue{[]byte("value4"), version.NewHeight(2, 1)}}, - &VersionedKV{CompositeKey{"ns2", "key5"}, VersionedValue{[]byte("value5"), version.NewHeight(2, 2)}}, - &VersionedKV{CompositeKey{"ns2", "key6"}, VersionedValue{[]byte("value6"), version.NewHeight(2, 3)}}, + {CompositeKey{"ns2", "key4"}, VersionedValue{[]byte("value4"), version.NewHeight(2, 1)}}, + {CompositeKey{"ns2", "key5"}, VersionedValue{[]byte("value5"), version.NewHeight(2, 2)}}, + {CompositeKey{"ns2", "key6"}, VersionedValue{[]byte("value6"), version.NewHeight(2, 3)}}, }) checkItrResults(t, batch.GetRangeScanIterator("non-existing-ns", "", ""), nil) diff --git a/core/ledger/ledgerstorage/store_test.go b/core/ledger/ledgerstorage/store_test.go index 0daf03823d5..b098d3b1bea 100644 --- a/core/ledger/ledgerstorage/store_test.go +++ b/core/ledger/ledgerstorage/store_test.go @@ -168,14 +168,14 @@ func sampleData(t *testing.T) []*ledger.BlockAndPvtData { func samplePvtData(t *testing.T, txNums []uint64) map[uint64]*ledger.TxPvtData { pvtWriteSet := &rwset.TxPvtReadWriteSet{DataModel: rwset.TxReadWriteSet_KV} pvtWriteSet.NsPvtRwset = []*rwset.NsPvtReadWriteSet{ - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns-1", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-1", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll1"), }, - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-2", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll2"), }, diff --git a/core/ledger/pkg_test.go b/core/ledger/pkg_test.go index 36df23679fb..4f07a9f1a75 100644 --- a/core/ledger/pkg_test.go +++ b/core/ledger/pkg_test.go @@ -19,14 +19,14 @@ func TestTxPvtData(t *testing.T) { txPvtData.WriteSet = &rwset.TxPvtReadWriteSet{ DataModel: rwset.TxReadWriteSet_KV, NsPvtRwset: []*rwset.NsPvtReadWriteSet{ - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-1", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll1"), }, - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-2", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll2"), }, diff --git a/core/ledger/pvtdatastorage/store_impl_test.go b/core/ledger/pvtdatastorage/store_impl_test.go index e321f0c1ff0..8c9ff5acbbf 100644 --- a/core/ledger/pvtdatastorage/store_impl_test.go +++ b/core/ledger/pvtdatastorage/store_impl_test.go @@ -142,28 +142,28 @@ func testLastCommittedBlockHeight(expectedBlockHt uint64, assert *assert.Asserti func samplePvtData(t *testing.T, txNums []uint64) []*ledger.TxPvtData { pvtWriteSet := &rwset.TxPvtReadWriteSet{DataModel: rwset.TxReadWriteSet_KV} pvtWriteSet.NsPvtRwset = []*rwset.NsPvtReadWriteSet{ - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns-1", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-1", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll1"), }, - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-2", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll2"), }, }, }, - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns-2", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-1", Rwset: []byte("RandomBytes-PvtRWSet-ns2-coll1"), }, - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-2", Rwset: []byte("RandomBytes-PvtRWSet-ns2-coll2"), }, diff --git a/core/ledger/util/util_test.go b/core/ledger/util/util_test.go index 58dae5ccf97..3040d323509 100644 --- a/core/ledger/util/util_test.go +++ b/core/ledger/util/util_test.go @@ -48,7 +48,7 @@ func TestGetValuesBySortedKeys(t *testing.T) { GetValuesBySortedKeys(&mapKeyValue, &sortedRes) assert.Equal( t, - []*name{&name{"None", "none"}, &name{"Two", "two"}, &name{"Three", "three"}, &name{"Five", "five"}}, + []*name{{"None", "none"}, {"Two", "two"}, {"Three", "three"}, {"Five", "five"}}, sortedRes, ) } diff --git a/core/policy/policy.go b/core/policy/policy.go index 936ddd769b6..9923f4d8f37 100644 --- a/core/policy/policy.go +++ b/core/policy/policy.go @@ -95,7 +95,7 @@ func (p *policyChecker) CheckPolicy(channelID, policyName string, signedProp *pb return fmt.Errorf("Invalid Proposal's SignatureHeader during check policy on channel [%s] with policy [%s]: [%s]", channelID, policyName, err) } - sd := []*common.SignedData{&common.SignedData{ + sd := []*common.SignedData{{ Data: signedProp.ProposalBytes, Identity: shdr.Creator, Signature: signedProp.Signature, diff --git a/core/policy/policy_test.go b/core/policy/policy_test.go index cb662e38590..31fc3438c6c 100644 --- a/core/policy/policy_test.go +++ b/core/policy/policy_test.go @@ -75,11 +75,11 @@ func TestCheckPolicyBySignedDataInvalidArgs(t *testing.T) { } pc := &policyChecker{channelPolicyManagerGetter: policyManagerGetter} - err := pc.CheckPolicyBySignedData("", "admin", []*common.SignedData{&common.SignedData{}}) + err := pc.CheckPolicyBySignedData("", "admin", []*common.SignedData{{}}) assert.Error(t, err) assert.Contains(t, err.Error(), "Invalid channel ID name during check policy on signed data. Name must be different from nil.") - err = pc.CheckPolicyBySignedData("A", "", []*common.SignedData{&common.SignedData{}}) + err = pc.CheckPolicyBySignedData("A", "", []*common.SignedData{{}}) assert.Error(t, err) assert.Contains(t, err.Error(), "Invalid policy name during check policy on signed data on channel [A]. Name must be different from nil.") @@ -87,11 +87,11 @@ func TestCheckPolicyBySignedDataInvalidArgs(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), "Invalid signed data during check policy on channel [A] with policy [admin]") - err = pc.CheckPolicyBySignedData("B", "admin", []*common.SignedData{&common.SignedData{}}) + err = pc.CheckPolicyBySignedData("B", "admin", []*common.SignedData{{}}) assert.Error(t, err) assert.Contains(t, err.Error(), "Failed to get policy manager for channel [B]") - err = pc.CheckPolicyBySignedData("A", "admin", []*common.SignedData{&common.SignedData{}}) + err = pc.CheckPolicyBySignedData("A", "admin", []*common.SignedData{{}}) assert.Error(t, err) assert.Contains(t, err.Error(), "Failed evaluating policy on signed data during check policy on channel [A] with policy [admin]") } diff --git a/core/scc/lscc/lscc.go b/core/scc/lscc/lscc.go index eea5fb32665..afa1e23ff68 100644 --- a/core/scc/lscc/lscc.go +++ b/core/scc/lscc/lscc.go @@ -535,7 +535,7 @@ func (lscc *LifeCycleSysCC) checkInstantiationPolicy(stub shim.ChaincodeStubInte return err } // construct signed data we can evaluate the instantiation policy against - sd := []*common.SignedData{&common.SignedData{ + sd := []*common.SignedData{{ Data: signedProp.ProposalBytes, Identity: shdr.Creator, Signature: signedProp.Signature, diff --git a/core/scc/lscc/lscc_test.go b/core/scc/lscc/lscc_test.go index 09d07b4c750..d73f7db963f 100644 --- a/core/scc/lscc/lscc_test.go +++ b/core/scc/lscc/lscc_test.go @@ -739,7 +739,7 @@ func testIPolDeploy(t *testing.T, iPol string, successExpected bool) { args := [][]byte{[]byte(DEPLOY), []byte(chainid), cdsbytes} if res := stub.MockInvokeWithSignedProposal("1", args, sProp2); res.Status != shim.OK { if successExpected { - t.Fatalf("Deploy failed %s", res) + t.Fatalf("Deploy failed %v", res) } } @@ -748,7 +748,7 @@ func testIPolDeploy(t *testing.T, iPol string, successExpected bool) { args = [][]byte{[]byte(GETCCINFO), []byte(chainid), []byte(cds.ChaincodeSpec.ChaincodeId.Name)} if res := stub.MockInvokeWithSignedProposal("1", args, sProp); res.Status != shim.OK { if successExpected { - t.Fatalf("GetCCInfo failed %s", res) + t.Fatalf("GetCCInfo failed %v", res) } } } @@ -886,13 +886,13 @@ func testIPolUpgrade(t *testing.T, iPol string, successExpected bool) { assert.NoError(t, err) args := [][]byte{[]byte(DEPLOY), []byte(chainid), cdsbytes} if res := stub.MockInvokeWithSignedProposal("1", args, sProp2); res.Status != shim.OK { - t.Fatalf("Deploy failed %s", res) + t.Fatalf("Deploy failed %v", res) } mockAclProvider.Reset() mockAclProvider.On("CheckACL", aclmgmt.LSCC_GETCCINFO, chainid, sProp).Return(nil) args = [][]byte{[]byte(GETCCINFO), []byte(chainid), []byte(cds.ChaincodeSpec.ChaincodeId.Name)} if res := stub.MockInvokeWithSignedProposal("1", args, sProp); res.Status != shim.OK { - t.Fatalf("GetCCInfo after deploy failed %s", res) + t.Fatalf("GetCCInfo after deploy failed %v", res) } // here starts the interesting part for upgrade @@ -920,7 +920,7 @@ func testIPolUpgrade(t *testing.T, iPol string, successExpected bool) { args = [][]byte{[]byte(UPGRADE), []byte(chainid), cdsbytes} if res := stub.MockInvokeWithSignedProposal("1", args, sProp2); res.Status != shim.OK { if successExpected { - t.Fatalf("Upgrade failed %s", res) + t.Fatalf("Upgrade failed %v", res) } } args = [][]byte{[]byte(GETCCINFO), []byte(chainid), []byte(cds.ChaincodeSpec.ChaincodeId.Name)} diff --git a/core/scc/qscc/query.go b/core/scc/qscc/query.go index 1a4ae08076f..20c59a18fd9 100644 --- a/core/scc/qscc/query.go +++ b/core/scc/qscc/query.go @@ -95,7 +95,7 @@ func (e *LedgerQuerier) Invoke(stub shim.ChaincodeStubInterface) pb.Response { // 2. check the channel reader policy res := getACLResource(fname) if err = aclmgmt.GetACLProvider().CheckACL(res, cid, sp); err != nil { - return shim.Error(fmt.Sprintf("Authorization request for [%s][%cid] failed: [%s]", fname, cid, err)) + return shim.Error(fmt.Sprintf("Authorization request for [%s][%s] failed: [%s]", fname, cid, err)) } switch fname { diff --git a/core/scc/rscc/rsccpolicy.go b/core/scc/rscc/rsccpolicy.go index b0cf5e52309..c566ac6748c 100644 --- a/core/scc/rscc/rsccpolicy.go +++ b/core/scc/rscc/rsccpolicy.go @@ -114,7 +114,7 @@ func (rp *rsccPolicyProviderImpl) CheckACL(polName string, idinfo interface{}) e return fmt.Errorf("Invalid Proposal's SignatureHeader during check policy [%s]: [%s]", polName, err) } - sd := []*common.SignedData{&common.SignedData{ + sd := []*common.SignedData{{ Data: signedProp.ProposalBytes, Identity: shdr.Creator, Signature: signedProp.Signature, diff --git a/core/scc/vscc/validator_onevalidsignature.go b/core/scc/vscc/validator_onevalidsignature.go index 103ee39af9a..55306aecd0d 100644 --- a/core/scc/vscc/validator_onevalidsignature.go +++ b/core/scc/vscc/validator_onevalidsignature.go @@ -201,7 +201,7 @@ func (vscc *ValidatorOneValidSignature) checkInstantiationPolicy(chainName strin } // construct signed data we can evaluate the instantiation policy against - sd := []*common.SignedData{&common.SignedData{ + sd := []*common.SignedData{{ Data: env.Payload, Identity: shdr.Creator, Signature: env.Signature, diff --git a/core/transientstore/store_test.go b/core/transientstore/store_test.go index 8f268fdc478..7504a994c18 100644 --- a/core/transientstore/store_test.go +++ b/core/transientstore/store_test.go @@ -454,28 +454,28 @@ func sortResults(res []*EndorserPvtSimulationResults) { func samplePvtData(t *testing.T) *rwset.TxPvtReadWriteSet { pvtWriteSet := &rwset.TxPvtReadWriteSet{DataModel: rwset.TxReadWriteSet_KV} pvtWriteSet.NsPvtRwset = []*rwset.NsPvtReadWriteSet{ - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns-1", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-1", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll1"), }, - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-2", Rwset: []byte("RandomBytes-PvtRWSet-ns1-coll2"), }, }, }, - &rwset.NsPvtReadWriteSet{ + { Namespace: "ns-2", CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{ - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-1", Rwset: []byte("RandomBytes-PvtRWSet-ns2-coll1"), }, - &rwset.CollectionPvtReadWriteSet{ + { CollectionName: "coll-2", Rwset: []byte("RandomBytes-PvtRWSet-ns2-coll2"), }, diff --git a/events/consumer/consumer_test.go b/events/consumer/consumer_test.go index 33367f38c4c..82f72c05696 100644 --- a/events/consumer/consumer_test.go +++ b/events/consumer/consumer_test.go @@ -67,7 +67,7 @@ func (a *BadAdapter) Disconnected(err error) { func (a *MockAdapter) GetInterestedEvents() ([]*ehpb.Interest, error) { return []*ehpb.Interest{ - &ehpb.Interest{EventType: ehpb.EventType_BLOCK}, + {EventType: ehpb.EventType_BLOCK}, }, nil } diff --git a/events/producer/producer_test.go b/events/producer/producer_test.go index 899891e446a..78ede933a17 100644 --- a/events/producer/producer_test.go +++ b/events/producer/producer_test.go @@ -275,7 +275,7 @@ func TestReceiveCCWildcard(t *testing.T) { t.Logf("timed out on message") } adapter.count = 1 - obcEHClient.UnregisterAsync([]*ehpb.Interest{&ehpb.Interest{EventType: ehpb.EventType_CHAINCODE, RegInfo: &ehpb.Interest_ChaincodeRegInfo{ChaincodeRegInfo: &ehpb.ChaincodeReg{ChaincodeId: "0xffffffff", EventName: ""}}}}) + obcEHClient.UnregisterAsync([]*ehpb.Interest{{EventType: ehpb.EventType_CHAINCODE, RegInfo: &ehpb.Interest_ChaincodeRegInfo{ChaincodeRegInfo: &ehpb.ChaincodeReg{ChaincodeId: "0xffffffff", EventName: ""}}}}) select { case <-adapter.notfy: diff --git a/gossip/comm/mock/mock_comm_test.go b/gossip/comm/mock/mock_comm_test.go index d3cd8d88a85..8f521872919 100644 --- a/gossip/comm/mock/mock_comm_test.go +++ b/gossip/comm/mock/mock_comm_test.go @@ -35,12 +35,12 @@ func TestMockComm(t *testing.T) { defer comm2.Stop() sMsg, _ := (&proto.GossipMessage{ - Content: &proto.GossipMessage_StateRequest{&proto.RemoteStateRequest{ + Content: &proto.GossipMessage_StateRequest{StateRequest: &proto.RemoteStateRequest{ StartSeqNum: 1, EndSeqNum: 3, }}, }).NoopSign() - comm2.Send(sMsg, &comm.RemotePeer{"first", common.PKIidType("first")}) + comm2.Send(sMsg, &comm.RemotePeer{Endpoint: "first", PKIID: common.PKIidType("first")}) msg := <-msgCh @@ -66,14 +66,14 @@ func TestMockComm_PingPong(t *testing.T) { sMsg, _ := (&proto.GossipMessage{ Content: &proto.GossipMessage_DataMsg{ - &proto.DataMessage{ - &proto.Payload{ + DataMsg: &proto.DataMessage{ + Payload: &proto.Payload{ SeqNum: 1, Data: []byte("Ping"), }, }}, }).NoopSign() - peerA.Send(sMsg, &comm.RemotePeer{"peerB", common.PKIidType("peerB")}) + peerA.Send(sMsg, &comm.RemotePeer{Endpoint: "peerB", PKIID: common.PKIidType("peerB")}) msg := <-rcvChB dataMsg := msg.GetGossipMessage().GetDataMsg() @@ -82,8 +82,8 @@ func TestMockComm_PingPong(t *testing.T) { msg.Respond(&proto.GossipMessage{ Content: &proto.GossipMessage_DataMsg{ - &proto.DataMessage{ - &proto.Payload{ + DataMsg: &proto.DataMessage{ + Payload: &proto.Payload{ SeqNum: 1, Data: []byte("Pong"), }, diff --git a/gossip/privdata/util.go b/gossip/privdata/util.go index 7a59cc1e7e4..24794f5aabc 100644 --- a/gossip/privdata/util.go +++ b/gossip/privdata/util.go @@ -193,8 +193,8 @@ func sampleCollHashedRwSet(collectionName string, hash []byte) *rwsetutil.CollHa CollectionName: collectionName, HashedRwSet: &kvrwset.HashedRWSet{ HashedReads: []*kvrwset.KVReadHash{ - {KeyHash: []byte("Key-1-hash"), Version: &kvrwset.Version{1, 2}}, - {KeyHash: []byte("Key-2-hash"), Version: &kvrwset.Version{2, 3}}, + {KeyHash: []byte("Key-1-hash"), Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, + {KeyHash: []byte("Key-2-hash"), Version: &kvrwset.Version{BlockNum: 2, TxNum: 3}}, }, HashedWrites: []*kvrwset.KVWriteHash{ {KeyHash: []byte("Key-3-hash"), ValueHash: []byte("value-3-hash"), IsDelete: false}, diff --git a/gossip/state/state.go b/gossip/state/state.go index d03fd9b4ecf..917ae6e4203 100644 --- a/gossip/state/state.go +++ b/gossip/state/state.go @@ -459,7 +459,7 @@ func (s *GossipStateProviderImpl) handleStateRequest(msg proto.ReceivedMessage) Nonce: msg.GetGossipMessage().Nonce, Tag: proto.GossipMessage_CHAN_OR_ORG, Channel: []byte(s.chainID), - Content: &proto.GossipMessage_StateResponse{response}, + Content: &proto.GossipMessage_StateResponse{StateResponse: response}, }) } diff --git a/gossip/state/state_test.go b/gossip/state/state_test.go index 8695f02f00a..1c4ad7e87d4 100644 --- a/gossip/state/state_test.go +++ b/gossip/state/state_test.go @@ -1015,7 +1015,7 @@ func TestGossipStateProvider_TestStateMessages(t *testing.T) { logger.Info("Bootstrap node got message, ", msg) assert.True(t, msg.GetGossipMessage().GetStateRequest() != nil) msg.Respond(&proto.GossipMessage{ - Content: &proto.GossipMessage_StateResponse{&proto.RemoteStateResponse{nil}}, + Content: &proto.GossipMessage_StateResponse{StateResponse: &proto.RemoteStateResponse{Payloads: nil}}, }) wg.Done() }() @@ -1040,8 +1040,8 @@ func TestGossipStateProvider_TestStateMessages(t *testing.T) { chainID := common.ChainID(util.GetTestChainID()) peer.g.Send(&proto.GossipMessage{ - Content: &proto.GossipMessage_StateRequest{&proto.RemoteStateRequest{0, 1}}, - }, &comm.RemotePeer{peer.g.PeersOfChannel(chainID)[0].Endpoint, peer.g.PeersOfChannel(chainID)[0].PKIid}) + Content: &proto.GossipMessage_StateRequest{StateRequest: &proto.RemoteStateRequest{StartSeqNum: 0, EndSeqNum: 1}}, + }, &comm.RemotePeer{Endpoint: peer.g.PeersOfChannel(chainID)[0].Endpoint, PKIID: peer.g.PeersOfChannel(chainID)[0].PKIid}) logger.Info("Waiting until peers exchange messages") select { @@ -1331,7 +1331,7 @@ func TestTransferOfPrivateRWSet(t *testing.T) { Nonce: 1, Tag: proto.GossipMessage_CHAN_OR_ORG, Channel: []byte(chainID), - Content: &proto.GossipMessage_StateRequest{&proto.RemoteStateRequest{ + Content: &proto.GossipMessage_StateRequest{StateRequest: &proto.RemoteStateRequest{ StartSeqNum: 2, EndSeqNum: 3, }}, diff --git a/msp/idemixmsp.go b/msp/idemixmsp.go index ad35e99b19f..49bd5572c73 100644 --- a/msp/idemixmsp.go +++ b/msp/idemixmsp.go @@ -110,17 +110,17 @@ func (msp *idemixmsp) Setup(conf1 *m.MSPConfig) error { Nym, RandNym := idemix.MakeNym(sk, msp.ipk, rng) role := &m.MSPRole{ - msp.name, - m.MSPRole_MEMBER, + MspIdentifier: msp.name, + Role: m.MSPRole_MEMBER, } if conf.Signer.IsAdmin { role.Role = m.MSPRole_ADMIN } ou := &m.OrganizationUnit{ - msp.name, - conf.Signer.OrganizationalUnitIdentifier, - ipk.Hash, + MspIdentifier: msp.name, + OrganizationalUnitIdentifier: conf.Signer.OrganizationalUnitIdentifier, + CertifiersIdentifier: ipk.Hash, } // Check if credential contains the right amount of attribute values (Role and OU) @@ -408,7 +408,7 @@ func (id *idemixidentity) GetOrganizationalUnits() []*OUIdentifier { mspIdentityLogger.Errorf("Failed to marshal ipk in GetOrganizationalUnits: %s", err) return nil } - return []*OUIdentifier{&OUIdentifier{certifiersIdentifier, id.OU.OrganizationalUnitIdentifier}} + return []*OUIdentifier{{certifiersIdentifier, id.OU.OrganizationalUnitIdentifier}} } func (id *idemixidentity) Validate() error { diff --git a/msp/idemixmsp_test.go b/msp/idemixmsp_test.go index a90085e612a..cc6bdca1697 100644 --- a/msp/idemixmsp_test.go +++ b/msp/idemixmsp_test.go @@ -72,12 +72,12 @@ func TestSetupBad(t *testing.T) { assert.Error(t, err) // Setup with incorrect MSP type - conf := &msp.MSPConfig{1234, nil} + conf := &msp.MSPConfig{Type: 1234, Config: nil} err = msp1.Setup(conf) assert.Error(t, err) // Setup with bad idemix config bytes - conf = &msp.MSPConfig{int32(IDEMIX), []byte("barf")} + conf = &msp.MSPConfig{Type: int32(IDEMIX), Config: []byte("barf")} err = msp1.Setup(conf) assert.Error(t, err) diff --git a/orderer/common/deliver/deliver_test.go b/orderer/common/deliver/deliver_test.go index ba8021fdef8..6de4e8dd088 100644 --- a/orderer/common/deliver/deliver_test.go +++ b/orderer/common/deliver/deliver_test.go @@ -153,7 +153,7 @@ func initializeDeliverHandler() Handler { mm := newMockMultichainManager() for i := 1; i < ledgerSize; i++ { l := mm.chains[systemChainID].ledger - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", i))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", i))}})) } return NewHandlerImpl(mm) @@ -282,7 +282,7 @@ func TestUnauthorizedSeek(t *testing.T) { mm := newMockMultichainManager() for i := 1; i < ledgerSize; i++ { l := mm.chains[systemChainID].ledger - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", i))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", i))}})) } mm.chains[systemChainID].policyManager.Policy.Err = fmt.Errorf("Fail to evaluate policy") @@ -308,7 +308,7 @@ func TestRevokedAuthorizationSeek(t *testing.T) { mm := newMockMultichainManager() for i := 1; i < ledgerSize; i++ { l := mm.chains[systemChainID].ledger - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", i))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", i))}})) } m := newMockD() @@ -329,7 +329,7 @@ func TestRevokedAuthorizationSeek(t *testing.T) { mm.chains[systemChainID].policyManager.Policy.Err = fmt.Errorf("Fail to evaluate policy") mm.chains[systemChainID].configSeq++ l := mm.chains[systemChainID].ledger - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", ledgerSize+1))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", ledgerSize+1))}})) select { case deliverReply := <-m.sendChan: @@ -391,7 +391,7 @@ func TestBlockingSeek(t *testing.T) { mm := newMockMultichainManager() for i := 1; i < ledgerSize; i++ { l := mm.chains[systemChainID].ledger - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", i))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", i))}})) } m := newMockD() @@ -418,7 +418,7 @@ func TestBlockingSeek(t *testing.T) { } l := mm.chains[systemChainID].ledger - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", ledgerSize+1))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", ledgerSize+1))}})) select { case deliverReply := <-m.sendChan: @@ -445,7 +445,7 @@ func TestErroredSeek(t *testing.T) { l := ms.ledger close(ms.erroredChan) for i := 1; i < ledgerSize; i++ { - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", i))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", i))}})) } m := newMockD() @@ -469,7 +469,7 @@ func TestErroredBlockingSeek(t *testing.T) { ms := mm.chains[systemChainID] l := ms.ledger for i := 1; i < ledgerSize; i++ { - l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{&cb.Envelope{Payload: []byte(fmt.Sprintf("%d", i))}})) + l.Append(ledger.CreateNextBlock(l, []*cb.Envelope{{Payload: []byte(fmt.Sprintf("%d", i))}})) } m := newMockD() diff --git a/orderer/common/ledger/blackbox_test.go b/orderer/common/ledger/blackbox_test.go index 0006b40e554..e69a2852f55 100644 --- a/orderer/common/ledger/blackbox_test.go +++ b/orderer/common/ledger/blackbox_test.go @@ -86,7 +86,7 @@ func testReinitialization(lf ledgerTestFactory, t *testing.T) { return } olf, oli := lf.New() - aBlock := CreateNextBlock(oli, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}}) + aBlock := CreateNextBlock(oli, []*cb.Envelope{{Payload: []byte("My Data")}}) err := oli.Append(aBlock) if err != nil { t.Fatalf("Error appending block: %s", err) @@ -118,7 +118,7 @@ func testAddition(lf ledgerTestFactory, t *testing.T) { } prevHash := genesis.Header.Hash() - li.Append(CreateNextBlock(li, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + li.Append(CreateNextBlock(li, []*cb.Envelope{{Payload: []byte("My Data")}})) if li.Height() != 2 { t.Fatalf("Block height should be 2") } @@ -137,7 +137,7 @@ func TestRetrieval(t *testing.T) { func testRetrieval(lf ledgerTestFactory, t *testing.T) { _, li := lf.New() - li.Append(CreateNextBlock(li, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + li.Append(CreateNextBlock(li, []*cb.Envelope{{Payload: []byte("My Data")}})) it, num := li.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Oldest{}}) defer it.Close() if num != 0 { @@ -188,7 +188,7 @@ func testBlockedRetrieval(lf ledgerTestFactory, t *testing.T) { t.Fatalf("Should not be ready for block read") default: } - li.Append(CreateNextBlock(li, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + li.Append(CreateNextBlock(li, []*cb.Envelope{{Payload: []byte("My Data")}})) select { case <-signal: default: @@ -222,8 +222,8 @@ func testMultichain(lf ledgerTestFactory, t *testing.T) { t.Fatalf("Error creating chain1: %s", err) } - c1.Append(CreateNextBlock(c1, []*cb.Envelope{&cb.Envelope{Payload: c1p1}})) - c1b1 := CreateNextBlock(c1, []*cb.Envelope{&cb.Envelope{Payload: c1p2}}) + c1.Append(CreateNextBlock(c1, []*cb.Envelope{{Payload: c1p1}})) + c1b1 := CreateNextBlock(c1, []*cb.Envelope{{Payload: c1p2}}) c1.Append(c1b1) if c1.Height() != 2 { @@ -234,7 +234,7 @@ func testMultichain(lf ledgerTestFactory, t *testing.T) { if err != nil { t.Fatalf("Error creating chain2: %s", err) } - c2b0 := c2.Append(CreateNextBlock(c2, []*cb.Envelope{&cb.Envelope{Payload: c2p1}})) + c2b0 := c2.Append(CreateNextBlock(c2, []*cb.Envelope{{Payload: c2p1}})) if c2.Height() != 1 { t.Fatalf("Block height for c2 should be 1") diff --git a/orderer/common/ledger/file/impl_test.go b/orderer/common/ledger/file/impl_test.go index d5b0db02bf8..a63205d8da7 100644 --- a/orderer/common/ledger/file/impl_test.go +++ b/orderer/common/ledger/file/impl_test.go @@ -149,7 +149,7 @@ func TestReinitialization(t *testing.T) { defer tev.tearDown() // create a block to add to the ledger - b1 := ledger.CreateNextBlock(ledger1, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}}) + b1 := ledger.CreateNextBlock(ledger1, []*cb.Envelope{{Payload: []byte("My Data")}}) // add the block to the ledger ledger1.Append(b1) @@ -190,7 +190,7 @@ func TestAddition(t *testing.T) { defer tev.tearDown() info, _ := fl.blockStore.GetBlockchainInfo() prevHash := info.CurrentBlockHash - fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{{Payload: []byte("My Data")}})) assert.Equal(t, uint64(2), fl.Height(), "Block height should be 2") block := ledger.GetBlock(fl, 1) @@ -201,7 +201,7 @@ func TestAddition(t *testing.T) { func TestRetrieval(t *testing.T) { tev, fl := initialize(t) defer tev.tearDown() - fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{{Payload: []byte("My Data")}})) it, num := fl.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Oldest{}}) defer it.Close() assert.Zero(t, num, "Expected genesis block iterator, but got %d", num) @@ -250,7 +250,7 @@ func TestBlockedRetrieval(t *testing.T) { default: } - fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{{Payload: []byte("My Data")}})) select { case <-signal: default: @@ -266,7 +266,7 @@ func TestBlockedRetrieval(t *testing.T) { "Expected to successfully retrieve the second block but got block number %d", block.Header.Number) go func() { - fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{{Payload: []byte("My Data")}})) }() select { case <-it.ReadyChan(): diff --git a/orderer/common/ledger/json/impl_test.go b/orderer/common/ledger/json/impl_test.go index f45af71a485..b3fad7d3ef1 100644 --- a/orderer/common/ledger/json/impl_test.go +++ b/orderer/common/ledger/json/impl_test.go @@ -79,7 +79,7 @@ func TestInitialization(t *testing.T) { func TestReinitialization(t *testing.T) { tev, ofl := initialize(t) defer tev.tearDown() - ofl.Append(ledger.CreateNextBlock(ofl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + ofl.Append(ledger.CreateNextBlock(ofl, []*cb.Envelope{{Payload: []byte("My Data")}})) flf := New(tev.location) chains := flf.ChainIDs() assert.Len(t, chains, 1, "Should have recovered the chain") @@ -115,7 +115,7 @@ func TestAddition(t *testing.T) { tev, fl := initialize(t) defer tev.tearDown() prevHash := fl.lastHash - fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{{Payload: []byte("My Data")}})) assert.Equal(t, uint64(2), fl.height, "Block height should be 2") block, found := fl.readBlock(1) @@ -127,7 +127,7 @@ func TestAddition(t *testing.T) { func TestRetrieval(t *testing.T) { tev, fl := initialize(t) defer tev.tearDown() - fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + fl.Append(ledger.CreateNextBlock(fl, []*cb.Envelope{{Payload: []byte("My Data")}})) it, num := fl.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Oldest{}}) defer it.Close() assert.Equal(t, uint64(0), num, "Expected genesis block iterator, but got %d", num) diff --git a/orderer/common/ledger/ram/impl_test.go b/orderer/common/ledger/ram/impl_test.go index 8da2a94f595..32df9b7bc3c 100644 --- a/orderer/common/ledger/ram/impl_test.go +++ b/orderer/common/ledger/ram/impl_test.go @@ -110,7 +110,7 @@ func TestTruncationSafety(t *testing.T) { func TestRetrieval(t *testing.T) { rl := newTestChain(3) - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}})) it, num := rl.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Oldest{}}) defer it.Close() if num != 0 { @@ -157,7 +157,7 @@ func TestBlockedRetrieval(t *testing.T) { t.Fatalf("Should not be ready for block read") default: } - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}})) select { case <-signal: default: @@ -184,9 +184,9 @@ func TestIteratorPastEnd(t *testing.T) { func TestIteratorOldest(t *testing.T) { rl := newTestChain(3) // add enough block to roll off the genesis block - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}})) it, num := rl.Iterator(&ab.SeekPosition{Type: &ab.SeekPosition_Specified{Specified: &ab.SeekSpecified{Number: 1}}}) defer it.Close() if num != 1 { @@ -197,14 +197,14 @@ func TestIteratorOldest(t *testing.T) { func TestAppendBadBLock(t *testing.T) { rl := newTestChain(3) t.Run("BadBlockNumber", func(t *testing.T) { - nextBlock := ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}}) + nextBlock := ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}}) nextBlock.Header.Number = nextBlock.Header.Number + 1 if err := rl.Append(nextBlock); err == nil { t.Fatalf("Expected Append to fail.") } }) t.Run("BadPreviousHash", func(t *testing.T) { - nextBlock := ledger.CreateNextBlock(rl, []*cb.Envelope{&cb.Envelope{Payload: []byte("My Data")}}) + nextBlock := ledger.CreateNextBlock(rl, []*cb.Envelope{{Payload: []byte("My Data")}}) nextBlock.Header.PreviousHash = []byte("bad hash") if err := rl.Append(nextBlock); err == nil { t.Fatalf("Expected Append to fail.") diff --git a/orderer/common/msgprocessor/systemchannel_test.go b/orderer/common/msgprocessor/systemchannel_test.go index ba8ba5b9000..5b0660f5bcc 100644 --- a/orderer/common/msgprocessor/systemchannel_test.go +++ b/orderer/common/msgprocessor/systemchannel_test.go @@ -512,7 +512,7 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: { Version: 100, }, }, @@ -532,7 +532,7 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: { Version: 1, }, }, @@ -553,12 +553,12 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: { Version: 1, }, }, Values: map[string]*cb.ConfigValue{ - channelconfig.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: { Value: []byte("bad consortium value"), }, }, @@ -578,12 +578,12 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: { Version: 1, }, }, Values: map[string]*cb.ConfigValue{ - channelconfig.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: { Value: utils.MarshalOrPanic( &cb.Consortium{ Name: "NotTheNameYouAreLookingFor", @@ -607,12 +607,12 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: { Version: 1, }, }, Values: map[string]*cb.ConfigValue{ - channelconfig.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: { Value: utils.MarshalOrPanic( &cb.Consortium{ Name: genesisconfig.SampleConsortiumName, @@ -636,15 +636,15 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: { Version: 1, Groups: map[string]*cb.ConfigGroup{ - "BadOrgName": &cb.ConfigGroup{}, + "BadOrgName": {}, }, }, }, Values: map[string]*cb.ConfigValue{ - channelconfig.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: { Value: utils.MarshalOrPanic( &cb.Consortium{ Name: genesisconfig.SampleConsortiumName, diff --git a/orderer/common/multichannel/blockwriter_test.go b/orderer/common/multichannel/blockwriter_test.go index b82a9b5d01f..fdebded9e8e 100644 --- a/orderer/common/multichannel/blockwriter_test.go +++ b/orderer/common/multichannel/blockwriter_test.go @@ -47,7 +47,7 @@ func TestCreateBlock(t *testing.T) { bw := &BlockWriter{lastBlock: seedBlock} block := bw.CreateNextBlock([]*cb.Envelope{ - &cb.Envelope{Payload: []byte("some other bytes")}, + {Payload: []byte("some other bytes")}, }) assert.Equal(t, seedBlock.Header.Number+1, block.Header.Number) diff --git a/orderer/mocks/common/blockcutter/blockcutter.go b/orderer/mocks/common/blockcutter/blockcutter.go index 82bbfe29d8e..997ee75f0a4 100644 --- a/orderer/mocks/common/blockcutter/blockcutter.go +++ b/orderer/mocks/common/blockcutter/blockcutter.go @@ -67,7 +67,7 @@ func (mbc *Receiver) Ordered(env *cb.Envelope) ([][]*cb.Envelope, bool) { if mbc.IsolatedTx { logger.Debugf("Receiver: Returning dual batch") - res := [][]*cb.Envelope{mbc.CurBatch, []*cb.Envelope{env}} + res := [][]*cb.Envelope{mbc.CurBatch, {env}} mbc.CurBatch = nil return res, false } diff --git a/orderer/sample_clients/deliver_stdout/client.go b/orderer/sample_clients/deliver_stdout/client.go index da787d8ee3f..42d1ad408e6 100644 --- a/orderer/sample_clients/deliver_stdout/client.go +++ b/orderer/sample_clients/deliver_stdout/client.go @@ -85,7 +85,7 @@ func (r *deliverClient) readUntilClose() { fmt.Println("Received block: ") err := protolator.DeepMarshalJSON(os.Stdout, t.Block) if err != nil { - fmt.Println(" Error pretty printing block: %s", err) + fmt.Printf(" Error pretty printing block: %s", err) } } else { fmt.Println("Received block: ", t.Block.Header.Number) diff --git a/peer/chaincode/list_test.go b/peer/chaincode/list_test.go index 59a7df90f19..9a5c25a5c62 100644 --- a/peer/chaincode/list_test.go +++ b/peer/chaincode/list_test.go @@ -25,8 +25,8 @@ func TestChaincodeListCmd(t *testing.T) { installedCqr := &pb.ChaincodeQueryResponse{ Chaincodes: []*pb.ChaincodeInfo{ - &pb.ChaincodeInfo{Name: "mycc1", Version: "1.0", Path: "codePath1", Input: "input", Escc: "escc", Vscc: "vscc"}, - &pb.ChaincodeInfo{Name: "mycc2", Version: "1.0", Path: "codePath2", Input: "input", Escc: "escc", Vscc: "vscc"}, + {Name: "mycc1", Version: "1.0", Path: "codePath1", Input: "input", Escc: "escc", Vscc: "vscc"}, + {Name: "mycc2", Version: "1.0", Path: "codePath2", Input: "input", Escc: "escc", Vscc: "vscc"}, }, } installedCqrBytes, err := proto.Marshal(installedCqr) diff --git a/peer/channel/getinfo.go b/peer/channel/getinfo.go index 835e25b1b70..cd2ba6e9078 100644 --- a/peer/channel/getinfo.go +++ b/peer/channel/getinfo.go @@ -69,7 +69,7 @@ func (cc *endorserClient) getBlockChainInfo() (*cb.BlockchainInfo, error) { } if proposalResp.Response == nil || proposalResp.Response.Status != 200 { - return nil, errors.Errorf("received bad response, status %s", proposalResp.Response.Status) + return nil, errors.Errorf("received bad response, status %d", proposalResp.Response.Status) } blockChainInfo := &cb.BlockchainInfo{} diff --git a/peer/common/common_test.go b/peer/common/common_test.go index ee997494ee9..049064daebe 100644 --- a/peer/common/common_test.go +++ b/peer/common/common_test.go @@ -67,10 +67,10 @@ func TestInitCrypto(t *testing.T) { err = common.InitCrypto(mspConfigPath, localMspId) assert.NoError(t, err, "Unexpected error [%s] calling InitCrypto()", err) err = common.InitCrypto("/etc/foobaz", localMspId) - assert.Error(t, err, "Expected error [%s] calling InitCrypto()", err) + assert.Error(t, err, fmt.Sprintf("Expected error [%s] calling InitCrypto()", err)) localMspId = "" err = common.InitCrypto(mspConfigPath, localMspId) - assert.Error(t, err, "Expected error [%s] calling InitCrypto()", err) + assert.Error(t, err, fmt.Sprintf("Expected error [%s] calling InitCrypto()", err)) } func TestGetEndorserClient(t *testing.T) { diff --git a/protos/common/block_test.go b/protos/common/block_test.go index ea5d203e69f..f23fa5240e2 100644 --- a/protos/common/block_test.go +++ b/protos/common/block_test.go @@ -32,7 +32,7 @@ func TestBlock(t *testing.T) { assert.Nil(t, block.GetMetadata()) data := &BlockData{ - Data: [][]byte{[]byte{0, 1, 2}}, + Data: [][]byte{{0, 1, 2}}, } block = NewBlock(uint64(0), []byte("datahash")) assert.Equal(t, []byte("datahash"), block.Header.PreviousHash, "Incorrect previous hash") diff --git a/protos/common/common_test.go b/protos/common/common_test.go index 0448e161164..7fca47691f8 100644 --- a/protos/common/common_test.go +++ b/protos/common/common_test.go @@ -84,7 +84,7 @@ func TestCommonStructs(t *testing.T) { assert.Nil(t, meta.GetValue()) meta = &Metadata{ Value: []byte("value"), - Signatures: []*MetadataSignature{&MetadataSignature{}}, + Signatures: []*MetadataSignature{{}}, } assert.NotNil(t, meta.GetSignatures()) assert.NotNil(t, meta.GetValue()) diff --git a/protos/common/configtx_test.go b/protos/common/configtx_test.go index e706e9818b8..90bfb054f19 100644 --- a/protos/common/configtx_test.go +++ b/protos/common/configtx_test.go @@ -167,7 +167,7 @@ func TestConfigUpdateEnvelope(t *testing.T) { env = &ConfigUpdateEnvelope{ Signatures: []*ConfigSignature{ - &ConfigSignature{}, + {}, }, ConfigUpdate: []byte("configupdate"), } diff --git a/protos/common/policies_test.go b/protos/common/policies_test.go index 17d3923ba55..f3c56b1e853 100644 --- a/protos/common/policies_test.go +++ b/protos/common/policies_test.go @@ -61,7 +61,7 @@ func TestPoliciesStructs(t *testing.T) { assert.Nil(t, env.GetRule()) env = &SignaturePolicyEnvelope{ Rule: &SignaturePolicy{}, - Identities: []*common1.MSPPrincipal{&common1.MSPPrincipal{}}, + Identities: []*common1.MSPPrincipal{{}}, Version: int32(1), } assert.Equal(t, int32(1), env.GetVersion()) @@ -110,7 +110,7 @@ func TestPoliciesStructs(t *testing.T) { assert.Equal(t, int32(0), n.GetN()) assert.Nil(t, n.GetRules()) n = &SignaturePolicy_NOutOf{ - Rules: []*SignaturePolicy{&SignaturePolicy{}}, + Rules: []*SignaturePolicy{{}}, N: int32(1), } assert.Equal(t, int32(1), n.GetN()) diff --git a/protos/common/signed_data.go b/protos/common/signed_data.go index d12a25ebbd3..d8ad11a316c 100644 --- a/protos/common/signed_data.go +++ b/protos/common/signed_data.go @@ -87,7 +87,7 @@ func (env *Envelope) AsSignedData() ([]*SignedData, error) { return nil, fmt.Errorf("GetSignatureHeaderFromBytes failed, err %s", err) } - return []*SignedData{&SignedData{ + return []*SignedData{{ Data: env.Payload, Identity: shdr.Creator, Signature: env.Signature, diff --git a/protos/gossip/extensions_test.go b/protos/gossip/extensions_test.go index 4a244376962..d66fe6b30fb 100644 --- a/protos/gossip/extensions_test.go +++ b/protos/gossip/extensions_test.go @@ -436,7 +436,7 @@ func TestCheckGossipMessageTypes(t *testing.T) { // Create state response message msg = signedGossipMessage(channelID, GossipMessage_EMPTY, &GossipMessage_StateResponse{ StateResponse: &RemoteStateResponse{ - Payloads: []*Payload{&Payload{ + Payloads: []*Payload{{ SeqNum: 1, Data: []byte{1, 2, 3, 4, 5}, }}, diff --git a/protos/ledger/rwset/kvrwset/tests/kv_rwset_test.go b/protos/ledger/rwset/kvrwset/tests/kv_rwset_test.go index 726846026c0..7da05ec3645 100644 --- a/protos/ledger/rwset/kvrwset/tests/kv_rwset_test.go +++ b/protos/ledger/rwset/kvrwset/tests/kv_rwset_test.go @@ -56,15 +56,15 @@ func testPrepareBinaryFileSampleKVRWSetV1(t *testing.T) { func constructSampleKVRWSet() *kvrwset.KVRWSet { rqi1 := &kvrwset.RangeQueryInfo{StartKey: "k0", EndKey: "k9", ItrExhausted: true} rqi1.SetRawReads([]*kvrwset.KVRead{ - &kvrwset.KVRead{Key: "k1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}, - &kvrwset.KVRead{Key: "k2", Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, + {Key: "k1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}, + {Key: "k2", Version: &kvrwset.Version{BlockNum: 1, TxNum: 2}}, }) rqi2 := &kvrwset.RangeQueryInfo{StartKey: "k00", EndKey: "k90", ItrExhausted: true} rqi2.SetMerkelSummary(&kvrwset.QueryReadsMerkleSummary{MaxDegree: 5, MaxLevel: 4, MaxLevelHashes: [][]byte{[]byte("Hash-1"), []byte("Hash-2")}}) return &kvrwset.KVRWSet{ - Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, + Reads: []*kvrwset.KVRead{{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}}, RangeQueriesInfo: []*kvrwset.RangeQueryInfo{rqi1, rqi2}, - Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key2", IsDelete: false, Value: []byte("value2")}}, + Writes: []*kvrwset.KVWrite{{Key: "key2", IsDelete: false, Value: []byte("value2")}}, } } diff --git a/protos/ledger/rwset/tests/rwset_test.go b/protos/ledger/rwset/tests/rwset_test.go index c8d994ca8d8..63610c1806f 100644 --- a/protos/ledger/rwset/tests/rwset_test.go +++ b/protos/ledger/rwset/tests/rwset_test.go @@ -57,8 +57,8 @@ func constructSampleRWSet() *rwset.TxReadWriteSet { rwset1 := &rwset.TxReadWriteSet{} rwset1.DataModel = rwset.TxReadWriteSet_KV rwset1.NsRwset = []*rwset.NsReadWriteSet{ - &rwset.NsReadWriteSet{Namespace: "ns-1", Rwset: []byte("ns-1-rwset")}, - &rwset.NsReadWriteSet{Namespace: "ns-2", Rwset: []byte("ns-2-rwset")}, + {Namespace: "ns-1", Rwset: []byte("ns-1-rwset")}, + {Namespace: "ns-2", Rwset: []byte("ns-2-rwset")}, } return rwset1 } diff --git a/protos/utils/blockutils.go b/protos/utils/blockutils.go index 4e2c41493d2..a2df2db034b 100644 --- a/protos/utils/blockutils.go +++ b/protos/utils/blockutils.go @@ -119,7 +119,7 @@ func CopyBlockMetadata(src *cb.Block, dst *cb.Block) { // InitBlockMetadata copies metadata from one block into another func InitBlockMetadata(block *cb.Block) { if block.Metadata == nil { - block.Metadata = &cb.BlockMetadata{Metadata: [][]byte{[]byte{}, []byte{}, []byte{}}} + block.Metadata = &cb.BlockMetadata{Metadata: [][]byte{{}, {}, {}}} } else if len(block.Metadata.Metadata) < int(cb.BlockMetadataIndex_TRANSACTIONS_FILTER+1) { for i := int(len(block.Metadata.Metadata)); i <= int(cb.BlockMetadataIndex_TRANSACTIONS_FILTER); i++ { block.Metadata.Metadata = append(block.Metadata.Metadata, []byte{}) diff --git a/protos/utils/txutils_test.go b/protos/utils/txutils_test.go index 89582cf6db7..483d9addad0 100644 --- a/protos/utils/txutils_test.go +++ b/protos/utils/txutils_test.go @@ -132,7 +132,7 @@ func TestCreateSignedTx(t *testing.T) { shdrBytes, _ := proto.Marshal(&cb.SignatureHeader{ Creator: signerBytes, }) - responses := []*pb.ProposalResponse{&pb.ProposalResponse{}} + responses := []*pb.ProposalResponse{{}} // malformed chaincode header extension headerBytes, _ := proto.Marshal(&cb.Header{ @@ -159,7 +159,7 @@ func TestCreateSignedTx(t *testing.T) { prop.Header = headerBytes // bad status - responses = []*pb.ProposalResponse{&pb.ProposalResponse{ + responses = []*pb.ProposalResponse{{ Payload: []byte("payload"), Response: &pb.Response{ Status: int32(100), @@ -169,7 +169,7 @@ func TestCreateSignedTx(t *testing.T) { assert.Error(t, err, "Expected error with status code not equal to 200") // non-matching responses - responses = []*pb.ProposalResponse{&pb.ProposalResponse{ + responses = []*pb.ProposalResponse{{ Payload: []byte("payload"), Response: &pb.Response{ Status: int32(200), @@ -185,7 +185,7 @@ func TestCreateSignedTx(t *testing.T) { assert.Error(t, err, "Expected error with non-matching responses") // no endorsement - responses = []*pb.ProposalResponse{&pb.ProposalResponse{ + responses = []*pb.ProposalResponse{{ Payload: []byte("payload"), Response: &pb.Response{ Status: int32(200), @@ -195,7 +195,7 @@ func TestCreateSignedTx(t *testing.T) { assert.Error(t, err, "Expected error with no endorsements") // success - responses = []*pb.ProposalResponse{&pb.ProposalResponse{ + responses = []*pb.ProposalResponse{{ Payload: []byte("payload"), Endorsement: &pb.Endorsement{}, Response: &pb.Response{ diff --git a/scripts/golinter.sh b/scripts/golinter.sh index ddcc5c36a83..c08a20f388f 100755 --- a/scripts/golinter.sh +++ b/scripts/golinter.sh @@ -15,6 +15,7 @@ declare -a arr=( "./events" "./examples" "./gossip" +"./idemix" "./msp" "./orderer" "./peer" @@ -23,13 +24,22 @@ declare -a arr=( for i in "${arr[@]}" do - echo "Checking $i" - go vet $i/... + echo ">>>Checking code under $i/" + + echo "Checking with goimports" OUTPUT="$(goimports -srcdir $GOPATH/src/github.com/hyperledger/fabric -l $i)" if [[ $OUTPUT ]]; then - echo "The following files contain goimports errors" - echo $OUTPUT - echo "The goimports command must be run for these files" - exit 1 + echo "The following files contain goimports errors" + echo $OUTPUT + echo "The goimports command 'goimports -l -w' must be run for these files" + exit 1 + fi + + echo "Checking with go vet" + OUTPUT="$(go vet $i/...)" + if [[ $OUTPUT ]]; then + echo "The following files contain go vet errors" + echo $OUTPUT + exit 1 fi done