How to use New method of pb Package

Best K6 code snippet using pb.New

endorser_test.go

Source:endorser_test.go Github

copy

Full Screen

...66 },67 }68}69func TestEndorserNilProp(t *testing.T) {70 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{71 GetApplicationConfigBoolRv: true,72 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},73 GetTransactionByIDErr: errors.New(""),74 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},75 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},76 GetTxSimulatorRv: &mockccprovider.MockTxSim{77 GetTxSimulationResultsRv: &ledger.TxSimulationResults{78 PubSimulationResults: &rwset.TxReadWriteSet{},79 },80 },81 }, platforms.NewRegistry(&golang.Platform{}))82 pResp, err := es.ProcessProposal(context.Background(), nil)83 assert.Error(t, err)84 assert.EqualValues(t, 500, pResp.Response.Status)85 assert.Equal(t, "nil arguments", pResp.Response.Message)86}87func TestEndorserUninvokableSysCC(t *testing.T) {88 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{89 GetApplicationConfigBoolRv: true,90 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},91 GetTransactionByIDErr: errors.New(""),92 IsSysCCAndNotInvokableExternalRv: true,93 }, platforms.NewRegistry(&golang.Platform{}))94 signedProp := getSignedProp("ccid", "0", t)95 pResp, err := es.ProcessProposal(context.Background(), signedProp)96 assert.Error(t, err)97 assert.EqualValues(t, 500, pResp.Response.Status)98 assert.Equal(t, "chaincode ccid cannot be invoked through a proposal", pResp.Response.Message)99}100func TestEndorserCCInvocationFailed(t *testing.T) {101 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{102 GetApplicationConfigBoolRv: true,103 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},104 GetTransactionByIDErr: errors.New(""),105 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},106 ExecuteResp: &pb.Response{Status: 1000, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}}), Message: "Chaincode Error"},107 GetTxSimulatorRv: &mockccprovider.MockTxSim{108 GetTxSimulationResultsRv: &ledger.TxSimulationResults{109 PubSimulationResults: &rwset.TxReadWriteSet{},110 },111 },112 }, platforms.NewRegistry(&golang.Platform{}))113 signedProp := getSignedProp("ccid", "0", t)114 pResp, err := es.ProcessProposal(context.Background(), signedProp)115 assert.NoError(t, err)116 assert.EqualValues(t, 1000, pResp.Response.Status)117 assert.Regexp(t, "Chaincode Error", pResp.Response.Message)118}119func TestEndorserNoCCDef(t *testing.T) {120 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{121 GetApplicationConfigBoolRv: true,122 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},123 GetTransactionByIDErr: errors.New(""),124 ChaincodeDefinitionError: errors.New(""),125 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},126 GetTxSimulatorRv: &mockccprovider.MockTxSim{127 GetTxSimulationResultsRv: &ledger.TxSimulationResults{128 PubSimulationResults: &rwset.TxReadWriteSet{},129 },130 },131 }, platforms.NewRegistry(&golang.Platform{}))132 signedProp := getSignedProp("ccid", "0", t)133 pResp, err := es.ProcessProposal(context.Background(), signedProp)134 assert.NoError(t, err)135 assert.EqualValues(t, 500, pResp.Response.Status)136 assert.Regexp(t, "make sure the chaincode", pResp.Response.Message)137}138func TestEndorserBadInstPolicy(t *testing.T) {139 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{140 GetApplicationConfigBoolRv: true,141 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},142 GetTransactionByIDErr: errors.New(""),143 CheckInstantiationPolicyError: errors.New(""),144 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},145 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},146 GetTxSimulatorRv: &mockccprovider.MockTxSim{147 GetTxSimulationResultsRv: &ledger.TxSimulationResults{148 PubSimulationResults: &rwset.TxReadWriteSet{},149 },150 },151 }, platforms.NewRegistry(&golang.Platform{}))152 signedProp := getSignedProp("ccid", "0", t)153 pResp, err := es.ProcessProposal(context.Background(), signedProp)154 assert.NoError(t, err)155 assert.EqualValues(t, 500, pResp.Response.Status)156}157func TestEndorserSysCC(t *testing.T) {158 m := &mock.Mock{}159 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)160 m.On("Serialize").Return([]byte{1, 1, 1}, nil)161 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)162 support := &em.MockSupport{163 Mock: m,164 GetApplicationConfigBoolRv: true,165 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},166 GetTransactionByIDErr: errors.New(""),167 IsSysCCRv: true,168 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},169 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},170 }171 attachPluginEndorser(support)172 es := endorser.NewEndorserServer(pvtEmptyDistributor, support, platforms.NewRegistry(&golang.Platform{}))173 signedProp := getSignedProp("ccid", "0", t)174 pResp, err := es.ProcessProposal(context.Background(), signedProp)175 assert.NoError(t, err)176 assert.EqualValues(t, 200, pResp.Response.Status)177}178func TestEndorserCCInvocationError(t *testing.T) {179 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{180 GetApplicationConfigBoolRv: true,181 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},182 GetTransactionByIDErr: errors.New(""),183 ExecuteError: errors.New(""),184 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},185 GetTxSimulatorRv: &mockccprovider.MockTxSim{186 GetTxSimulationResultsRv: &ledger.TxSimulationResults{187 PubSimulationResults: &rwset.TxReadWriteSet{},188 },189 },190 }, platforms.NewRegistry(&golang.Platform{}))191 signedProp := getSignedProp("ccid", "0", t)192 pResp, err := es.ProcessProposal(context.Background(), signedProp)193 assert.NoError(t, err)194 assert.EqualValues(t, 500, pResp.Response.Status)195}196func TestEndorserLSCCBadType(t *testing.T) {197 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{198 GetApplicationConfigBoolRv: true,199 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},200 GetTransactionByIDErr: errors.New(""),201 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},202 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},203 GetTxSimulatorRv: &mockccprovider.MockTxSim{204 GetTxSimulationResultsRv: &ledger.TxSimulationResults{205 PubSimulationResults: &rwset.TxReadWriteSet{},206 },207 },208 }, platforms.NewRegistry(&golang.Platform{}))209 cds := utils.MarshalOrPanic(210 &pb.ChaincodeDeploymentSpec{211 ChaincodeSpec: &pb.ChaincodeSpec{212 ChaincodeId: &pb.ChaincodeID{Name: "barf"},213 Type: pb.ChaincodeSpec_UNDEFINED,214 },215 },216 )217 signedProp := getSignedPropWithCHIdAndArgs(util.GetTestChainID(), "lscc", "0", [][]byte{[]byte("deploy"), []byte("a"), cds}, t)218 pResp, err := es.ProcessProposal(context.Background(), signedProp)219 assert.NoError(t, err)220 assert.EqualValues(t, 500, pResp.Response.Status)221 assert.Equal(t, "Unknown chaincodeType: UNDEFINED", pResp.Response.Message)222}223func TestEndorserDupTXId(t *testing.T) {224 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{225 GetApplicationConfigBoolRv: true,226 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},227 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},228 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},229 GetTxSimulatorRv: &mockccprovider.MockTxSim{230 GetTxSimulationResultsRv: &ledger.TxSimulationResults{231 PubSimulationResults: &rwset.TxReadWriteSet{},232 },233 },234 }, platforms.NewRegistry(&golang.Platform{}))235 signedProp := getSignedProp("ccid", "0", t)236 pResp, err := es.ProcessProposal(context.Background(), signedProp)237 assert.Error(t, err)238 assert.EqualValues(t, 500, pResp.Response.Status)239 assert.Regexp(t, "duplicate transaction found", pResp.Response.Message)240}241func TestEndorserBadACL(t *testing.T) {242 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{243 GetApplicationConfigBoolRv: true,244 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},245 CheckACLErr: errors.New(""),246 GetTransactionByIDErr: errors.New(""),247 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},248 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},249 GetTxSimulatorRv: &mockccprovider.MockTxSim{250 GetTxSimulationResultsRv: &ledger.TxSimulationResults{251 PubSimulationResults: &rwset.TxReadWriteSet{},252 },253 },254 }, platforms.NewRegistry(&golang.Platform{}))255 signedProp := getSignedProp("ccid", "0", t)256 pResp, err := es.ProcessProposal(context.Background(), signedProp)257 assert.Error(t, err)258 assert.EqualValues(t, 500, pResp.Response.Status)259}260func TestEndorserGoodPathEmptyChannel(t *testing.T) {261 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{262 GetApplicationConfigBoolRv: true,263 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},264 GetTransactionByIDErr: errors.New(""),265 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},266 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},267 GetTxSimulatorRv: &mockccprovider.MockTxSim{268 GetTxSimulationResultsRv: &ledger.TxSimulationResults{269 PubSimulationResults: &rwset.TxReadWriteSet{},270 },271 },272 }, platforms.NewRegistry(&golang.Platform{}))273 signedProp := getSignedPropWithCHIdAndArgs("", "ccid", "0", [][]byte{[]byte("args")}, t)274 pResp, err := es.ProcessProposal(context.Background(), signedProp)275 assert.NoError(t, err)276 assert.EqualValues(t, 200, pResp.Response.Status)277}278func TestEndorserLSCCInitFails(t *testing.T) {279 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{280 GetApplicationConfigBoolRv: true,281 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},282 GetTransactionByIDErr: errors.New(""),283 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},284 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},285 GetTxSimulatorRv: &mockccprovider.MockTxSim{286 GetTxSimulationResultsRv: &ledger.TxSimulationResults{287 PubSimulationResults: &rwset.TxReadWriteSet{},288 },289 },290 ExecuteCDSError: errors.New(""),291 }, platforms.NewRegistry(&golang.Platform{}))292 cds := utils.MarshalOrPanic(293 &pb.ChaincodeDeploymentSpec{294 ChaincodeSpec: &pb.ChaincodeSpec{295 ChaincodeId: &pb.ChaincodeID{Name: "barf"},296 Type: pb.ChaincodeSpec_GOLANG,297 },298 },299 )300 signedProp := getSignedPropWithCHIdAndArgs(util.GetTestChainID(), "lscc", "0", [][]byte{[]byte("deploy"), []byte("a"), cds}, t)301 pResp, err := es.ProcessProposal(context.Background(), signedProp)302 assert.NoError(t, err)303 assert.EqualValues(t, 500, pResp.Response.Status)304}305func TestEndorserLSCCDeploySysCC(t *testing.T) {306 SysCCMap := make(map[string]struct{})307 deployedCCName := "barf"308 SysCCMap[deployedCCName] = struct{}{}309 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{310 GetApplicationConfigBoolRv: true,311 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},312 GetTransactionByIDErr: errors.New(""),313 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},314 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},315 GetTxSimulatorRv: &mockccprovider.MockTxSim{316 GetTxSimulationResultsRv: &ledger.TxSimulationResults{317 PubSimulationResults: &rwset.TxReadWriteSet{},318 },319 },320 SysCCMap: SysCCMap,321 }, platforms.NewRegistry(&golang.Platform{}))322 cds := utils.MarshalOrPanic(323 &pb.ChaincodeDeploymentSpec{324 ChaincodeSpec: &pb.ChaincodeSpec{325 ChaincodeId: &pb.ChaincodeID{Name: deployedCCName},326 Type: pb.ChaincodeSpec_GOLANG,327 },328 },329 )330 signedProp := getSignedPropWithCHIdAndArgs(util.GetTestChainID(), "lscc", "0", [][]byte{[]byte("deploy"), []byte("a"), cds}, t)331 pResp, err := es.ProcessProposal(context.Background(), signedProp)332 assert.NoError(t, err)333 assert.EqualValues(t, 500, pResp.Response.Status)334 assert.Equal(t, "attempting to deploy a system chaincode barf/testchainid", pResp.Response.Message)335}336func TestEndorserGoodPathWEvents(t *testing.T) {337 m := &mock.Mock{}338 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)339 m.On("Serialize").Return([]byte{1, 1, 1}, nil)340 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)341 support := &em.MockSupport{342 Mock: m,343 GetApplicationConfigBoolRv: true,344 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},345 GetTransactionByIDErr: errors.New(""),346 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},347 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},348 ExecuteEvent: &pb.ChaincodeEvent{},349 }350 attachPluginEndorser(support)351 es := endorser.NewEndorserServer(pvtEmptyDistributor, support, platforms.NewRegistry(&golang.Platform{}))352 signedProp := getSignedProp("ccid", "0", t)353 pResp, err := es.ProcessProposal(context.Background(), signedProp)354 assert.NoError(t, err)355 assert.EqualValues(t, 200, pResp.Response.Status)356}357func TestEndorserBadChannel(t *testing.T) {358 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{359 GetApplicationConfigBoolRv: true,360 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},361 GetTransactionByIDErr: errors.New(""),362 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},363 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},364 GetTxSimulatorRv: &mockccprovider.MockTxSim{365 GetTxSimulationResultsRv: &ledger.TxSimulationResults{366 PubSimulationResults: &rwset.TxReadWriteSet{},367 },368 },369 }, platforms.NewRegistry(&golang.Platform{}))370 signedProp := getSignedPropWithCHID("ccid", "0", "barfchain", t)371 pResp, err := es.ProcessProposal(context.Background(), signedProp)372 assert.Error(t, err)373 assert.EqualValues(t, 500, pResp.Response.Status)374 assert.Equal(t, "access denied: channel [barfchain] creator org [SampleOrg]", pResp.Response.Message)375}376func TestEndorserGoodPath(t *testing.T) {377 m := &mock.Mock{}378 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)379 m.On("Serialize").Return([]byte{1, 1, 1}, nil)380 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)381 support := &em.MockSupport{382 Mock: m,383 GetApplicationConfigBoolRv: true,384 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},385 GetTransactionByIDErr: errors.New(""),386 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},387 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},388 }389 attachPluginEndorser(support)390 es := endorser.NewEndorserServer(pvtEmptyDistributor, support, platforms.NewRegistry(&golang.Platform{}))391 signedProp := getSignedProp("ccid", "0", t)392 pResp, err := es.ProcessProposal(context.Background(), signedProp)393 assert.NoError(t, err)394 assert.EqualValues(t, 200, pResp.Response.Status)395}396func TestEndorserChaincodeCallLogging(t *testing.T) {397 gt := NewGomegaWithT(t)398 m := &mock.Mock{}399 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)400 m.On("Serialize").Return([]byte{1, 1, 1}, nil)401 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)402 support := &em.MockSupport{403 Mock: m,404 GetApplicationConfigBoolRv: true,405 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},406 GetTransactionByIDErr: errors.New(""),407 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},408 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},409 }410 attachPluginEndorser(support)411 es := endorser.NewEndorserServer(pvtEmptyDistributor, support, platforms.NewRegistry(&golang.Platform{}))412 buf := gbytes.NewBuffer()413 flogging.Global.SetWriter(buf)414 defer flogging.Global.SetWriter(os.Stderr)415 es.ProcessProposal(context.Background(), getSignedProp("chaincode-name", "chaincode-version", t))416 t.Logf("contents:\n%s", buf.Contents())417 gt.Eventually(buf).Should(gbytes.Say(`INFO.*\[testchainid\]\[[[:xdigit:]]{8}\] Entry chaincode: name:"chaincode-name" version:"chaincode-version"`))418 gt.Eventually(buf).Should(gbytes.Say(`INFO.*\[testchainid\]\[[[:xdigit:]]{8}\] Exit chaincode: name:"chaincode-name" version:"chaincode-version" (.*ms)`))419}420func TestEndorserLSCC(t *testing.T) {421 m := &mock.Mock{}422 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)423 m.On("Serialize").Return([]byte{1, 1, 1}, nil)424 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)425 support := &em.MockSupport{426 Mock: m,427 GetApplicationConfigBoolRv: true,428 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},429 GetTransactionByIDErr: errors.New(""),430 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},431 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},432 }433 attachPluginEndorser(support)434 es := endorser.NewEndorserServer(pvtEmptyDistributor, support, platforms.NewRegistry(&golang.Platform{}))435 cds := utils.MarshalOrPanic(436 &pb.ChaincodeDeploymentSpec{437 ChaincodeSpec: &pb.ChaincodeSpec{438 ChaincodeId: &pb.ChaincodeID{Name: "barf"},439 Type: pb.ChaincodeSpec_GOLANG,440 },441 },442 )443 signedProp := getSignedPropWithCHIdAndArgs(util.GetTestChainID(), "lscc", "0", [][]byte{[]byte("deploy"), []byte("a"), cds}, t)444 pResp, err := es.ProcessProposal(context.Background(), signedProp)445 assert.NoError(t, err)446 assert.EqualValues(t, 200, pResp.Response.Status)447}448func attachPluginEndorser(support *em.MockSupport) {449 csr := &mocks.ChannelStateRetriever{}450 queryCreator := &mocks.QueryCreator{}451 csr.On("NewQueryCreator", mock.Anything).Return(queryCreator, nil)452 sif := &mocks.SigningIdentityFetcher{}453 sif.On("SigningIdentityForRequest", mock.Anything).Return(support, nil)454 pm := &mocks.PluginMapper{}455 pm.On("PluginFactoryByName", mock.Anything).Return(&builtin.DefaultEndorsementFactory{})456 support.PluginEndorser = endorser.NewPluginEndorser(&endorser.PluginSupport{457 ChannelStateRetriever: csr,458 SigningIdentityFetcher: sif,459 PluginMapper: pm,460 TransientStoreRetriever: mockTransientStoreRetriever,461 })462}463func TestEndorseWithPlugin(t *testing.T) {464 m := &mock.Mock{}465 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)466 m.On("Serialize").Return([]byte{1, 1, 1}, nil)467 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)468 support := &em.MockSupport{469 Mock: m,470 GetApplicationConfigBoolRv: true,471 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},472 GetTransactionByIDErr: errors.New("can't find this transaction in the index"),473 ChaincodeDefinitionRv: &resourceconfig.MockChaincodeDefinition{EndorsementStr: "ESCC"},474 ExecuteResp: &pb.Response{Status: 200, Payload: []byte{1}},475 }476 attachPluginEndorser(support)477 es := endorser.NewEndorserServer(pvtEmptyDistributor, support, platforms.NewRegistry(&golang.Platform{}))478 signedProp := getSignedProp("ccid", "0", t)479 resp, err := es.ProcessProposal(context.Background(), signedProp)480 assert.NoError(t, err)481 assert.Equal(t, []byte{1, 2, 3, 4, 5}, resp.Endorsement.Signature)482 assert.Equal(t, []byte{1, 1, 1}, resp.Endorsement.Endorser)483 assert.Equal(t, 200, int(resp.Response.Status))484}485func TestSimulateProposal(t *testing.T) {486 es := endorser.NewEndorserServer(pvtEmptyDistributor, &em.MockSupport{487 GetApplicationConfigBoolRv: true,488 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},489 GetTransactionByIDErr: errors.New(""),490 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},491 ExecuteResp: &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},492 GetTxSimulatorRv: &mockccprovider.MockTxSim{493 GetTxSimulationResultsRv: &ledger.TxSimulationResults{494 PubSimulationResults: &rwset.TxReadWriteSet{},495 },496 },497 }, platforms.NewRegistry(&golang.Platform{}))498 _, _, _, _, err := es.SimulateProposal(&ccprovider.TransactionParams{}, nil)499 assert.Error(t, err)500}501func TestEndorserAcquireTxSimulator(t *testing.T) {502 tc := []struct {503 name string504 chainID string505 chaincodeName string506 simAcquired bool507 }{508 {"empty channel", "", "ignored", false},509 {"query scc", util.GetTestChainID(), "qscc", false},510 {"config scc", util.GetTestChainID(), "cscc", false},511 {"mainline", util.GetTestChainID(), "chaincode", true},512 }513 expectedResponse := &pb.Response{Status: 200, Payload: utils.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})}514 for _, tt := range tc {515 tt := tt516 t.Run(tt.name, func(t *testing.T) {517 m := &mock.Mock{}518 m.On("Sign", mock.Anything).Return([]byte{1, 2, 3, 4, 5}, nil)519 m.On("Serialize").Return([]byte{1, 1, 1}, nil)520 m.On("GetTxSimulator", mock.Anything, mock.Anything).Return(newMockTxSim(), nil)521 support := &em.MockSupport{522 Mock: m,523 GetApplicationConfigBoolRv: true,524 GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},525 GetTransactionByIDErr: errors.New(""),526 ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},527 ExecuteResp: expectedResponse,528 }529 attachPluginEndorser(support)530 es := endorser.NewEndorserServer(531 pvtEmptyDistributor,532 support,533 platforms.NewRegistry(&golang.Platform{}),534 )535 t.Parallel()536 args := [][]byte{[]byte("args")}537 signedProp := getSignedPropWithCHIdAndArgs(tt.chainID, tt.chaincodeName, "version", args, t)538 resp, err := es.ProcessProposal(context.Background(), signedProp)539 assert.NoError(t, err)540 assert.Equal(t, expectedResponse, resp.Response)541 if tt.simAcquired {542 m.AssertCalled(t, "GetTxSimulator", mock.Anything, mock.Anything)543 } else {544 m.AssertNotCalled(t, "GetTxSimulator", mock.Anything, mock.Anything)545 }546 })547 }548}549var signer msp.SigningIdentity550func TestMain(m *testing.M) {551 // setup the MSP manager so that we can sign/verify552 err := msptesttools.LoadMSPSetupForTesting()553 if err != nil {554 fmt.Printf("Could not initialize msp/signer, err %s", err)555 os.Exit(-1)556 return557 }558 signer, err = mgmt.GetLocalMSP().GetDefaultSigningIdentity()559 if err != nil {560 fmt.Printf("Could not initialize msp/signer")561 os.Exit(-1)562 return563 }564 retVal := m.Run()565 os.Exit(retVal)566}567//go:generate counterfeiter -o mocks/support.go --fake-name Support . support568type support interface {569 endorser.Support570}571func TestUserCDSSanitization(t *testing.T) {572 fakeSupport := &mocks.Support{}573 e := endorser.NewEndorserServer(nil, fakeSupport, nil)574 userCDS := &pb.ChaincodeDeploymentSpec{575 ChaincodeSpec: &pb.ChaincodeSpec{576 ChaincodeId: &pb.ChaincodeID{577 Name: "user-cc-name",578 Version: "user-cc-version",579 Path: "user-cc-path",580 },581 Input: &pb.ChaincodeInput{582 Args: [][]byte{[]byte("foo"), []byte("bar")},583 },584 Type: pb.ChaincodeSpec_GOLANG,585 },586 CodePackage: []byte("user-code"),587 }...

Full Screen

Full Screen

scenario_bench_test.go

Source:scenario_bench_test.go Github

copy

Full Screen

...308 }309 })310 })311 b.Run("stdlib.Println", func(b *testing.B) {312 logger := log.New(ioutil.Discard, "", log.LstdFlags)313 b.ResetTimer()314 b.RunParallel(func(pb *testing.PB) {315 for pb.Next() {316 logger.Println(getMessage(0))317 }318 })319 })320 b.Run("stdlib.Printf", func(b *testing.B) {321 logger := log.New(ioutil.Discard, "", log.LstdFlags)322 b.ResetTimer()323 b.RunParallel(func(pb *testing.PB) {324 for pb.Next() {325 logger.Printf("%v %v %v %s %v %v %v %v %v %s\n", fakeFmtArgs()...)326 }327 })328 })329 b.Run("rs/zerolog", func(b *testing.B) {330 logger := newZerolog()331 b.ResetTimer()332 b.RunParallel(func(pb *testing.PB) {333 for pb.Next() {334 logger.Info().Msg(getMessage(0))335 }336 })337 })338 b.Run("rs/zerolog.Formatting", func(b *testing.B) {339 logger := newZerolog()340 b.ResetTimer()341 b.RunParallel(func(pb *testing.PB) {342 for pb.Next() {343 logger.Info().Msgf("%v %v %v %s %v %v %v %v %v %s\n", fakeFmtArgs()...)344 }345 })346 })347 b.Run("rs/zerolog.Check", func(b *testing.B) {348 logger := newZerolog()349 b.ResetTimer()350 b.RunParallel(func(pb *testing.PB) {351 for pb.Next() {352 if e := logger.Info(); e.Enabled() {353 e.Msg(getMessage(0))354 }355 }356 })357 })358}359func BenchmarkAccumulatedContext(b *testing.B) {360 b.Logf("Logging with some accumulated context.")361 b.Run("Zap", func(b *testing.B) {362 logger := newZapLogger(zap.DebugLevel).With(fakeFields()...)363 b.ResetTimer()364 b.RunParallel(func(pb *testing.PB) {365 for pb.Next() {366 logger.Info(getMessage(0))367 }368 })369 })370 b.Run("Zap.Check", func(b *testing.B) {371 logger := newZapLogger(zap.DebugLevel).With(fakeFields()...)372 b.ResetTimer()373 b.RunParallel(func(pb *testing.PB) {374 for pb.Next() {375 if ce := logger.Check(zap.InfoLevel, getMessage(0)); ce != nil {376 ce.Write()377 }378 }379 })380 })381 b.Run("Zap.CheckSampled", func(b *testing.B) {382 logger := newSampledLogger(zap.DebugLevel).With(fakeFields()...)383 b.ResetTimer()384 b.RunParallel(func(pb *testing.PB) {385 i := 0386 for pb.Next() {387 i++388 if ce := logger.Check(zap.InfoLevel, getMessage(i)); ce != nil {389 ce.Write()390 }391 }392 })393 })394 b.Run("Zap.Sugar", func(b *testing.B) {395 logger := newZapLogger(zap.DebugLevel).With(fakeFields()...).Sugar()396 b.ResetTimer()397 b.RunParallel(func(pb *testing.PB) {398 for pb.Next() {399 logger.Info(getMessage(0))400 }401 })402 })403 b.Run("Zap.SugarFormatting", func(b *testing.B) {404 logger := newZapLogger(zap.DebugLevel).With(fakeFields()...).Sugar()405 b.ResetTimer()406 b.RunParallel(func(pb *testing.PB) {407 for pb.Next() {408 logger.Infof("%v %v %v %s %v %v %v %v %v %s\n", fakeFmtArgs()...)409 }410 })411 })412 b.Run("apex/log", func(b *testing.B) {413 logger := newApexLog().WithFields(fakeApexFields())414 b.ResetTimer()415 b.RunParallel(func(pb *testing.PB) {416 for pb.Next() {417 logger.Info(getMessage(0))418 }419 })420 })421 b.Run("go-kit/kit/log", func(b *testing.B) {422 logger := newKitLog(fakeSugarFields()...)423 b.ResetTimer()424 b.RunParallel(func(pb *testing.PB) {425 for pb.Next() {426 logger.Log(getMessage(0), getMessage(1))427 }428 })429 })430 b.Run("inconshreveable/log15", func(b *testing.B) {431 logger := newLog15().New(fakeSugarFields())432 b.ResetTimer()433 b.RunParallel(func(pb *testing.PB) {434 for pb.Next() {435 logger.Info(getMessage(0))436 }437 })438 })439 b.Run("sirupsen/logrus", func(b *testing.B) {440 logger := newLogrus().WithFields(fakeLogrusFields())441 b.ResetTimer()442 b.RunParallel(func(pb *testing.PB) {443 for pb.Next() {444 logger.Info(getMessage(0))445 }...

Full Screen

Full Screen

template_timing_test.go

Source:template_timing_test.go Github

copy

Full Screen

...65 mSlice := map2slice(m)66 b.ResetTimer()67 b.RunParallel(func(pb *testing.PB) {68 for pb.Next() {69 r := strings.NewReplacer(mSlice...)70 x := r.Replace(source)71 if x != result {72 b.Fatalf("Unexpected result\n%q\nExpected\n%q\n", x, result)73 }74 }75 })76}77func BenchmarkTextTemplate(b *testing.B) {78 s := strings.Replace(source, "{{", "{{.", -1)79 t, err := template.New("test").Parse(s)80 if err != nil {81 b.Fatalf("Error when parsing template: %s", err)82 }83 mm := make(map[string]string)84 for k, v := range m {85 mm[k] = string(v.([]byte))86 }87 b.ResetTimer()88 b.RunParallel(func(pb *testing.PB) {89 var w bytes.Buffer90 for pb.Next() {91 if err := t.Execute(&w, mm); err != nil {92 b.Fatalf("error when executing template: %s", err)93 }94 x := w.Bytes()95 if !bytes.Equal(x, resultBytes) {96 b.Fatalf("unexpected result\n%q\nExpected\n%q\n", x, resultBytes)97 }98 w.Reset()99 }100 })101}102func BenchmarkFastTemplateExecuteFunc(b *testing.B) {103 t, err := NewTemplate(source, "{{", "}}")104 if err != nil {105 b.Fatalf("error in template: %s", err)106 }107 b.ResetTimer()108 b.RunParallel(func(pb *testing.PB) {109 var w bytes.Buffer110 for pb.Next() {111 if _, err := t.ExecuteFunc(&w, testTagFunc); err != nil {112 b.Fatalf("unexpected error: %s", err)113 }114 x := w.Bytes()115 if !bytes.Equal(x, resultBytes) {116 b.Fatalf("unexpected result\n%q\nExpected\n%q\n", x, resultBytes)117 }118 w.Reset()119 }120 })121}122func BenchmarkFastTemplateExecute(b *testing.B) {123 t, err := NewTemplate(source, "{{", "}}")124 if err != nil {125 b.Fatalf("error in template: %s", err)126 }127 b.ResetTimer()128 b.RunParallel(func(pb *testing.PB) {129 var w bytes.Buffer130 for pb.Next() {131 if _, err := t.Execute(&w, m); err != nil {132 b.Fatalf("unexpected error: %s", err)133 }134 x := w.Bytes()135 if !bytes.Equal(x, resultBytes) {136 b.Fatalf("unexpected result\n%q\nExpected\n%q\n", x, resultBytes)137 }138 w.Reset()139 }140 })141}142func BenchmarkFastTemplateExecuteFuncString(b *testing.B) {143 t, err := NewTemplate(source, "{{", "}}")144 if err != nil {145 b.Fatalf("error in template: %s", err)146 }147 b.ResetTimer()148 b.RunParallel(func(pb *testing.PB) {149 for pb.Next() {150 x := t.ExecuteFuncString(testTagFunc)151 if x != result {152 b.Fatalf("unexpected result\n%q\nExpected\n%q\n", x, result)153 }154 }155 })156}157func BenchmarkFastTemplateExecuteString(b *testing.B) {158 t, err := NewTemplate(source, "{{", "}}")159 if err != nil {160 b.Fatalf("error in template: %s", err)161 }162 b.ResetTimer()163 b.RunParallel(func(pb *testing.PB) {164 for pb.Next() {165 x := t.ExecuteString(m)166 if x != result {167 b.Fatalf("unexpected result\n%q\nExpected\n%q\n", x, result)168 }169 }170 })171}172func BenchmarkFastTemplateExecuteTagFunc(b *testing.B) {173 t, err := NewTemplate(source, "{{", "}}")174 if err != nil {175 b.Fatalf("error in template: %s", err)176 }177 mm := make(map[string]interface{})178 for k, v := range m {179 if k == "ref" {180 vv := v.([]byte)181 v = TagFunc(func(w io.Writer, tag string) (int, error) { return w.Write([]byte(url.QueryEscape(string(vv)))) })182 }183 mm[k] = v184 }185 b.ResetTimer()186 b.RunParallel(func(pb *testing.PB) {187 var w bytes.Buffer188 for pb.Next() {189 if _, err := t.Execute(&w, mm); err != nil {190 b.Fatalf("unexpected error: %s", err)191 }192 x := w.Bytes()193 if !bytes.Equal(x, resultEscapedBytes) {194 b.Fatalf("unexpected result\n%q\nExpected\n%q\n", x, resultEscapedBytes)195 }196 w.Reset()197 }198 })199}200func BenchmarkNewTemplate(b *testing.B) {201 b.RunParallel(func(pb *testing.PB) {202 for pb.Next() {203 _ = New(source, "{{", "}}")204 }205 })206}207func BenchmarkTemplateReset(b *testing.B) {208 b.RunParallel(func(pb *testing.PB) {209 t := New(source, "{{", "}}")210 for pb.Next() {211 t.Reset(source, "{{", "}}")212 }213 })214}215func BenchmarkTemplateResetExecuteFunc(b *testing.B) {216 b.RunParallel(func(pb *testing.PB) {217 t := New(source, "{{", "}}")218 var w bytes.Buffer219 for pb.Next() {220 t.Reset(source, "{{", "}}")221 t.ExecuteFunc(&w, testTagFunc)222 w.Reset()223 }224 })225}226func BenchmarkExecuteFunc(b *testing.B) {227 b.RunParallel(func(pb *testing.PB) {228 var bb bytes.Buffer229 for pb.Next() {230 ExecuteFunc(source, "{{", "}}", &bb, testTagFunc)231 bb.Reset()...

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 pb := New()4 fmt.Println(pb)5}6import "fmt"7func main() {8 pb := New()9 fmt.Println(pb)10}11import "fmt"12func main() {13 pb := New()14 fmt.Println(pb)15}16import "fmt"17func main() {18 pb := New()19 fmt.Println(pb)20}21import "fmt"22func main() {23 pb := New()24 fmt.Println(pb)25}26import "fmt"27func main() {28 pb := New()29 fmt.Println(pb)30}31import "fmt"32func main() {33 pb := New()34 fmt.Println(pb)35}36import "fmt"37func main() {38 pb := New()39 fmt.Println(pb)40}41import "fmt"42func main() {43 pb := New()44 fmt.Println(pb)45}46import "fmt"47func main() {48 pb := New()49 fmt.Println(pb)50}51import "fmt"52func main() {53 pb := New()54 fmt.Println(pb)55}56import "fmt"57func main() {58 pb := New()59 fmt.Println(pb)60}61import "fmt"62func main() {63 pb := New()64 fmt.Println(pb)65}66import "fmt"67func main() {68 pb := New()69 fmt.Println(pb)70}71import "fmt"72func main() {73 pb := New()74 fmt.Println(pb)75}76import "fmt"77func main() {78 pb := New()79 fmt.Println(pb)80}81import "fmt"82func main() {83 pb := New()84 fmt.Println(pb)85}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 pb := somepb.New()4 fmt.Println(pb)5}6import (7func main() {8 pb := somepb.New()9 fmt.Println(pb)10}11I want to be able to import the same package in multiple files and use the same pb class without getting this error. Is this possible? If so, how?12syntax = "proto3";13package pb;14enum Enum {15 A = 0;16 B = 1;17}18message Message {19 Enum enum = 1;20}21import proto "github.com/golang/protobuf/proto"22import fmt "fmt"23import math "math"24import (25const (26var Enum_name = map[int32]string{27}28var Enum_value = map[string]int32{29}30func (x Enum) String() string {31 return proto.EnumName(Enum_name, int32(x))32}33func (Enum) EnumDescriptor

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 pb.New()4}5import (6type pb struct {7}8func New() *pb {9 fmt.Println("New method of pb class")10 return &pb{}11}12import proto "github.com/golang/protobuf/proto"13import fmt "fmt"14import math "math"15import _ "github.com/golang/protobuf/protoc-gen-go/descriptor"16type _ struct{}17func (m *pb) Reset() { *m = pb{} }18func (m *pb) String() string { return proto.CompactTextString(m) }19func (*pb) ProtoM

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1func init() {2 fmt.Println("init function is called")3}4func init() {5 fmt.Println("init function is called")6}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1func main() {2 pb := pb.New()3 pb.DoSomething()4}5func main() {6 pb := pb.New()7 pb.DoSomething()8}9func New() *pb {10 return &pb{}11}12func (p *pb) DoSomething() {13 fmt.Println("Do something")14}15import (16func TestNew(t *testing.T) {17 pb := pb.New()18 pb.DoSomething()19}

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())4 if err != nil {5 log.Fatalf("did not connect: %v", err)6 }7 defer conn.Close()8 c := pb.NewEmployeeServiceClient(conn)9 emp, err := c.New(context.Background(), &pb.Employee{

Full Screen

Full Screen

New

Using AI Code Generation

copy

Full Screen

1p := &pb.Person{}2p1 := pb.NewPerson("abc", 10, "xyz")3p2 := pb.NewPerson("abc", 10, "xyz")4p3 := pb.NewPerson("abc", 10, "xyz")5p4 := pb.NewPerson("abc", 10, "xyz")6p5 := pb.NewPerson("abc", 10, "xyz")7p6 := pb.NewPerson("abc", 10, "xyz")8p7 := pb.NewPerson("abc", 10, "xyz")9p8 := pb.NewPerson("abc", 10, "xyz")10p9 := pb.NewPerson("abc", 10, "xyz")11p10 := pb.NewPerson("abc", 10, "xyz")12p11 := pb.NewPerson("abc", 10, "xyz")13p12 := pb.NewPerson("abc", 10, "xyz")14p13 := pb.NewPerson("abc", 10, "xyz")15p14 := pb.NewPerson("abc", 10, "xyz")16p15 := pb.NewPerson("abc", 10, "xyz")17p16 := pb.NewPerson("abc", 10, "xyz")18p17 := pb.NewPerson("abc", 10, "xyz")19p18 := pb.NewPerson("abc", 10, "xyz")20p19 := pb.NewPerson("abc", 10, "xyz

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful