How to use Status method of client Package

Best K6 code snippet using client.Status

chclient_test.go

Source:chclient_test.go Github

copy

Full Screen

...32 testErrorResponse := "internal error"33 // failed if status not 20034 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")35 testPeer2 := fcmocks.NewMockPeer("Peer2", "http://peer2.com")36 testPeer2.Status = 50037 testPeer2.ResponseMessage = testErrorResponse38 peers := []fab.Peer{testPeer1, testPeer2}39 chClient := setupChannelClient(peers, t)40 _, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})41 if err == nil {42 t.Fatal("Should have failed for not success status")43 }44 statusError, ok := status.FromError(err)45 assert.True(t, ok, "Expected status error")46 assert.EqualValues(t, common.Status_INTERNAL_SERVER_ERROR, status.ToPeerStatusCode(statusError.Code))47 assert.Equal(t, status.EndorserServerStatus, statusError.Group)48 assert.Equal(t, testErrorResponse, statusError.Message, "Expected response message from server")49 testPeer2.Payload = []byte("wrongPayload")50 testPeer2.Status = 20051 peers = []fab.Peer{testPeer1, testPeer2}52 chClient = setupChannelClient(peers, t)53 _, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})54 if err == nil {55 t.Fatal("Should have failed for not success status")56 }57 statusError, ok = status.FromError(err)58 assert.True(t, ok, "Expected status error")59 assert.EqualValues(t, status.EndorsementMismatch, status.ToSDKStatusCode(statusError.Code))60 assert.Equal(t, status.EndorserClientStatus, statusError.Group)61 assert.Equal(t, "ProposalResponsePayloads do not match", statusError.Message, "Expected response message from server")62}63func TestQuery(t *testing.T) {64 chClient := setupChannelClient(nil, t)65 _, err := chClient.Query(Request{})66 if err == nil {67 t.Fatal("Should have failed for empty query request")68 }69 _, err = chClient.Query(Request{Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})70 if err == nil {71 t.Fatal("Should have failed for empty chaincode ID")72 }73 _, err = chClient.Query(Request{ChaincodeID: "testCC", Args: [][]byte{[]byte("query"), []byte("b")}})74 if err == nil {75 t.Fatal("Should have failed for empty function")76 }77 response, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})78 if err != nil {79 t.Fatalf("Failed to invoke test cc: %s", err)80 }81 if response.Payload != nil {82 t.Fatalf("Expecting nil, got %s", response.Payload)83 }84 // Test return different payload85 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")86 testPeer1.Payload = []byte("test1")87 testPeer2 := fcmocks.NewMockPeer("Peer2", "http://peer2.com")88 testPeer2.Payload = []byte("test2")89 chClient = setupChannelClient([]fab.Peer{testPeer1, testPeer2}, t)90 _, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})91 if err == nil {92 t.Fatal("Should have failed")93 }94 s, ok := status.FromError(err)95 assert.True(t, ok, "expected status error")96 assert.EqualValues(t, status.EndorsementMismatch.ToInt32(), s.Code, "expected mismatch error")97}98func TestQuerySelectionError(t *testing.T) {99 chClient := setupChannelClientWithError(nil, errors.New("Test Error"), nil, t)100 _, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})101 if err == nil {102 t.Fatal("Should have failed to query with error in selection.GetEndorsersFor ...")103 }104}105func TestQueryWithOptSync(t *testing.T) {106 chClient := setupChannelClient(nil, t)107 response, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})108 if err != nil {109 t.Fatalf("Failed to invoke test cc: %s", err)110 }111 if response.Payload != nil {112 t.Fatalf("Expecting nil, got %s", response.Payload)113 }114}115// TestQueryWithOptAsync demonstrates an example of an asynchronous query call116func TestQueryWithOptAsync(t *testing.T) {117 chClient := setupChannelClient(nil, t)118 type responseAndError struct {119 Response Response120 Error error121 }122 notifier := make(chan responseAndError)123 go func() {124 resp, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})125 notifier <- responseAndError{Response: resp, Error: err}126 }()127 resp := <-notifier128 if resp.Error != nil {129 t.Fatalf("Failed to invoke test cc: %s", resp.Error)130 }131 if resp.Response.Payload != nil {132 t.Fatalf("Expecting nil, got %s", resp.Response.Payload)133 }134}135func TestQueryWithOptTarget(t *testing.T) {136 chClient := setupChannelClient(nil, t)137 testPeer := fcmocks.NewMockPeer("Peer1", "http://peer1.com")138 peers := []fab.Peer{testPeer}139 response, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke",140 Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(peers...))141 if err != nil {142 t.Fatalf("Failed to invoke test cc: %s", err)143 }144 if response.Payload != nil {145 t.Fatalf("Expecting nil, got %s", response.Payload)146 }147}148func TestQueryWithNilTargets(t *testing.T) {149 chClient := setupChannelClient(nil, t)150 _, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke",151 Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(nil, nil))152 if err == nil || !strings.Contains(err.Error(), "target is nil") {153 t.Fatal("Should have failed to invoke test cc due to nil target")154 }155 peers := []fab.Peer{fcmocks.NewMockPeer("Peer1", "http://peer1.com"), nil}156 _, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke",157 Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(peers...))158 if err == nil || !strings.Contains(err.Error(), "target is nil") {159 t.Fatal("Should have failed to invoke test cc due to nil target")160 }161}162func TestExecuteTx(t *testing.T) {163 chClient := setupChannelClient(nil, t)164 _, err := chClient.Execute(Request{})165 if err == nil {166 t.Fatal("Should have failed for empty invoke request")167 }168 _, err = chClient.Execute(Request{Fcn: "invoke", Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})169 if err == nil {170 t.Fatal("Should have failed for empty chaincode ID")171 }172 _, err = chClient.Execute(Request{ChaincodeID: "testCC", Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})173 if err == nil {174 t.Fatal("Should have failed for empty function")175 }176 // Test return different payload177 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")178 testPeer1.Payload = []byte("test1")179 testPeer2 := fcmocks.NewMockPeer("Peer2", "http://peer2.com")180 testPeer2.Payload = []byte("test2")181 chClient = setupChannelClient([]fab.Peer{testPeer1, testPeer2}, t)182 _, err = chClient.Execute(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("move"), []byte("b")}})183 if err == nil {184 t.Fatal("Should have failed")185 }186 s, ok := status.FromError(err)187 assert.True(t, ok, "expected status error")188 assert.EqualValues(t, status.EndorsementMismatch.ToInt32(), s.Code, "expected mismatch error")189 // TODO: Test Valid Scenario with mockcore190}191type customHandler struct {192 expectedPayload []byte193}194func (c *customHandler) Handle(requestContext *invoke.RequestContext, clientContext *invoke.ClientContext) {195 requestContext.Response.Payload = c.expectedPayload196}197func TestInvokeHandler(t *testing.T) {198 chClient := setupChannelClient(nil, t)199 expectedPayload := "somepayload"200 handler := &customHandler{expectedPayload: []byte(expectedPayload)}201 response, err := chClient.InvokeHandler(handler, Request{ChaincodeID: "testCC", Fcn: "move", Args: [][]byte{[]byte("a"), []byte("b"), []byte("1")}})202 if err != nil {203 t.Fatalf("Should have succeeded but got error %s", err)204 }205 if string(response.Payload) != expectedPayload {206 t.Fatalf("Expecting payload [%s] but got [%s]", expectedPayload, response.Payload)207 }208}209// customEndorsementHandler ignores the channel in the ClientContext210// and instead sends the proposal to the given channel211type customEndorsementHandler struct {212 transactor fab.Transactor213 next invoke.Handler214}215func (h *customEndorsementHandler) Handle(requestContext *invoke.RequestContext, clientContext *invoke.ClientContext) {216 transactionProposalResponses, txnID, err := createAndSendTestTransactionProposal(h.transactor, &requestContext.Request, peer.PeersToTxnProcessors(requestContext.Opts.Targets))217 requestContext.Response.TransactionID = txnID218 if err != nil {219 requestContext.Error = err220 return221 }222 requestContext.Response.Responses = transactionProposalResponses223 if len(transactionProposalResponses) > 0 {224 requestContext.Response.Payload = transactionProposalResponses[0].ProposalResponse.GetResponse().Payload225 }226 //Delegate to next step if any227 if h.next != nil {228 h.next.Handle(requestContext, clientContext)229 }230}231func TestQueryWithCustomEndorser(t *testing.T) {232 chClient := setupChannelClient(nil, t)233 // Use the customEndorsementHandler to send the proposal to234 // the system channel instead of the channel in context235 ctx := setupTestContext()236 transactor := txnmocks.MockTransactor{237 Ctx: ctx,238 ChannelID: "",239 }240 response, err := chClient.InvokeHandler(241 invoke.NewProposalProcessorHandler(242 &customEndorsementHandler{243 transactor: &transactor,244 next: invoke.NewEndorsementValidationHandler(),245 },246 ),247 Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}},248 )249 if err != nil {250 t.Fatalf("Failed to invoke test cc: %s", err)251 }252 if response.Payload != nil {253 t.Fatalf("Expecting nil, got %s", response.Payload)254 }255}256func TestExecuteTxSelectionError(t *testing.T) {257 chClient := setupChannelClientWithError(nil, errors.New("Test Error"), nil, t)258 _, err := chClient.Execute(Request{ChaincodeID: "testCC", Fcn: "invoke",259 Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})260 if err == nil {261 t.Fatal("Should have failed to execute tx with error in selection.GetEndorserrsFor ...")262 }263}264// TestRPCErrorPropagation tests if status errors are wrapped and propagated from265// the lower level APIs to the high level channel client API266// This ensures that the status is not swallowed by calling error.Error()267func TestRPCStatusErrorPropagation(t *testing.T) {268 testErrMessage := "Test RPC Error"269 testStatus := status.New(status.EndorserClientStatus, status.ConnectionFailed.ToInt32(), testErrMessage, nil)270 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")271 testPeer1.Error = testStatus272 chClient := setupChannelClient([]fab.Peer{testPeer1}, t)273 _, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})274 if err == nil {275 t.Fatal("Should have failed for not success status")276 }277 statusError, ok := status.FromError(err)278 assert.True(t, ok, "Expected status error")279 assert.EqualValues(t, status.ConnectionFailed, status.ToSDKStatusCode(statusError.Code))280 assert.Equal(t, status.EndorserClientStatus, statusError.Group)281 assert.Equal(t, testErrMessage, statusError.Message, "Expected response message from server")282}283// TestOrdererStatusError ensures that status errors are propagated through284// the code execution paths from the low-level orderer broadcast APIs285func TestOrdererStatusError(t *testing.T) {286 testErrorMessage := "test error"287 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")288 peers := []fab.Peer{testPeer1}289 testOrderer1 := fcmocks.NewMockOrderer("", make(chan *fab.SignedEnvelope))290 orderers := []fab.Orderer{testOrderer1}291 chClient := setupChannelClientWithNodes(peers, orderers, t)292 chClient.eventService = fcmocks.NewMockEventService()293 testOrderer1.EnqueueSendBroadcastError(status.New(status.OrdererClientStatus,294 status.ConnectionFailed.ToInt32(), testErrorMessage, nil))295 _, err := chClient.Execute(Request{ChaincodeID: "test", Fcn: "invoke",296 Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})297 statusError, ok := status.FromError(err)298 assert.True(t, ok, "Expected status error got %+v", err)299 assert.EqualValues(t, status.ConnectionFailed, status.ToSDKStatusCode(statusError.Code))300 assert.Equal(t, status.OrdererClientStatus, statusError.Group)301 assert.Equal(t, testErrorMessage, statusError.Message, "Expected response message from server")302}303func TestTransactionValidationError(t *testing.T) {304 validationCode := pb.TxValidationCode_BAD_RWSET305 mockEventService := fcmocks.NewMockEventService()306 mockEventService.TxValidationCode = validationCode307 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")308 peers := []fab.Peer{testPeer1}309 chClient := setupChannelClient(peers, t)310 chClient.eventService = mockEventService311 response, err := chClient.Execute(Request{ChaincodeID: "test", Fcn: "invoke",312 Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})313 assert.Nil(t, response.Payload, "Expected nil result on failed execute operation")314 assert.NotNil(t, err, "expected error")315 statusError, ok := status.FromError(err)316 assert.True(t, ok, "Expected status error got %+v", err)317 assert.EqualValues(t, validationCode, status.ToTransactionValidationCode(statusError.Code))318}319func TestTransactionTimeout(t *testing.T) {320 mockEventService := fcmocks.NewMockEventService()321 mockEventService.Timeout = true322 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")323 peers := []fab.Peer{testPeer1}324 chClient := setupChannelClient(peers, t)325 chClient.eventService = mockEventService326 response, err := chClient.Execute(Request{ChaincodeID: "test", Fcn: "invoke",327 Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})328 assert.Nil(t, response.Payload, "Expected nil result on failed execute operation")329 assert.NotNil(t, err, "expected error")330 statusError, ok := status.FromError(err)331 assert.True(t, ok, "Expected status error got %+v", err)332 assert.EqualValues(t, statusError.Code, status.Timeout)333}334func TestExecuteTxWithRetries(t *testing.T) {335 testStatus := status.New(status.EndorserClientStatus, status.ConnectionFailed.ToInt32(), "test", nil)336 testResp := []byte("test")337 retryInterval := 2 * time.Second338 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")339 testPeer1.Error = testStatus340 chClient := setupChannelClient([]fab.Peer{testPeer1}, t)341 retryOpts := retry.DefaultOpts342 retryOpts.Attempts = 3343 retryOpts.BackoffFactor = 1344 retryOpts.InitialBackoff = retryInterval345 retryOpts.RetryableCodes = retry.ChannelClientRetryableCodes346 go func() {347 // Remove peer error condition after retry attempt interval348 time.Sleep(retryInterval / 2)349 testPeer1.RWLock.Lock()350 testPeer1.Error = nil351 testPeer1.Payload = testResp352 testPeer1.RWLock.Unlock()353 }()354 resp, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}},355 WithRetry(retryOpts))356 assert.Nil(t, err, "expected error to be nil")357 assert.Equal(t, 2, testPeer1.ProcessProposalCalls, "Expected peer to be called twice")358 assert.Equal(t, testResp, resp.Payload, "expected correct response")359}360func TestBeforeRetryOption(t *testing.T) {361 testStatus := status.New(status.EndorserClientStatus, status.ConnectionFailed.ToInt32(), "test", nil)362 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")363 testPeer1.Error = testStatus364 chClient := setupChannelClient([]fab.Peer{testPeer1}, t)365 var callbacks int366 _, _ = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}},367 WithRetry(retry.DefaultChannelOpts), WithBeforeRetry(func(error) { callbacks++ }))368 assert.Equal(t, retry.DefaultChannelOpts.Attempts, callbacks, "Expected callback on each attempt")369}370func TestMultiErrorPropogation(t *testing.T) {371 testErr := fmt.Errorf("Test Error")372 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")373 testPeer1.Error = testErr374 testPeer2 := fcmocks.NewMockPeer("Peer2", "http://peer2.com")375 testPeer2.Error = testErr376 chClient := setupChannelClient([]fab.Peer{testPeer1, testPeer2}, t)377 _, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})378 if err == nil {379 t.Fatalf("Should have failed for not success status")380 }381 statusError, ok := status.FromError(err)382 assert.True(t, ok, "Expected status error")383 assert.EqualValues(t, status.MultipleErrors, status.ToSDKStatusCode(statusError.Code))384 assert.Equal(t, status.ClientStatus, statusError.Group)385 assert.Equal(t, "Multiple errors occurred: - Test Error - Test Error", statusError.Message, "Expected multi error message")386}387func TestDiscoveryGreylist(t *testing.T) {388 testPeer1 := fcmocks.NewMockPeer("Peer1", "http://peer1.com")389 testPeer1.Error = status.New(status.EndorserClientStatus,390 status.ConnectionFailed.ToInt32(), "test", []interface{}{testPeer1.URL()})391 discoveryService := txnmocks.NewMockDiscoveryService(nil, testPeer1)392 selectionService, err := staticselection.NewService(discoveryService)393 assert.Nil(t, err, "Got error %s", err)394 fabCtx := setupCustomTestContext(t, selectionService, discoveryService, nil)395 ctx := createChannelContext(fabCtx, channelID)396 chClient, err := New(ctx)397 assert.Nil(t, err, "Got error %s", err)398 attempts := 3399 retryOpts := retry.Opts{400 Attempts: attempts,401 BackoffFactor: 1,402 InitialBackoff: time.Millisecond * 1,403 MaxBackoff: time.Second * 1,404 RetryableCodes: retry.ChannelClientRetryableCodes,405 }406 _, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}},407 WithRetry(retryOpts))408 assert.NotNil(t, err, "expected error")409 s, ok := status.FromError(err)410 assert.True(t, ok, "expected status error")411 assert.EqualValues(t, status.NoPeersFound.ToInt32(), s.Code, "expected No Peers Found status on greylist")412 assert.Equal(t, 1, testPeer1.ProcessProposalCalls, "expected peer 1 to be greylisted")413 // Wait for greylist expiry414 time.Sleep(chClient.context.EndpointConfig().Timeout(fab.DiscoveryGreylistExpiry))415 testPeer1.ProcessProposalCalls = 0416 testPeer1.Error = status.New(status.EndorserServerStatus, int32(common.Status_SERVICE_UNAVAILABLE), "test", nil)417 // Try again418 _, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}},419 WithRetry(retryOpts))420 assert.NotNil(t, err, "expected error")421 s, ok = status.FromError(err)422 assert.True(t, ok, "expected status error")423 assert.EqualValues(t, int32(common.Status_SERVICE_UNAVAILABLE), s.Code, "expected configured mock error")424 assert.Equal(t, attempts+1, testPeer1.ProcessProposalCalls, "expected peer 1 not to be greylisted")425}426func setupTestChannelService(ctx context.Client, orderers []fab.Orderer) (fab.ChannelService, error) {427 chProvider, err := fcmocks.NewMockChannelProvider(ctx)428 if err != nil {429 return nil, errors.WithMessage(err, "mock channel provider creation failed")430 }431 chService, err := chProvider.ChannelService(ctx, channelID)432 if err != nil {433 return nil, errors.WithMessage(err, "mock channel service creation failed")434 }435 return chService, nil436}437func setupTestContext() context.Client {...

Full Screen

Full Screen

get_transaction_status_test.go

Source:get_transaction_status_test.go Github

copy

Full Screen

...14 "github.com/stretchr/testify/require"15 "testing"16 "time"17)18func TestGetTransactionStatus_PrepareResponse(t *testing.T) {19 ctrlRand := rand.NewControlledRand(t)20 cfg := config.ForPublicApiTests(22, 0, time.Minute)21 blockTime := primitives.TimestampNano(time.Now().UnixNano())22 receipt := builders.TransactionReceipt().WithRandomHash(ctrlRand).Build()23 response := toGetTxStatusOutput(cfg, &txOutput{24 transactionStatus: protocol.TRANSACTION_STATUS_COMMITTED,25 transactionReceipt: receipt,26 blockHeight: 126,27 blockTimestamp: blockTime,28 })29 require.EqualValues(t, protocol.REQUEST_STATUS_COMPLETED, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")30 require.EqualValues(t, 126, response.ClientResponse.RequestResult().BlockHeight(), "Block height response is wrong")31 require.EqualValues(t, blockTime, response.ClientResponse.RequestResult().BlockTimestamp(), "Block time response is wrong")32 require.EqualValues(t, protocol.TRANSACTION_STATUS_COMMITTED, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")33 test.RequireCmpEqual(t, receipt, response.ClientResponse.TransactionReceipt(), "Transaction receipt is not equal")34}35func TestGetTransactionStatus_PrepareResponse_NilReceipt(t *testing.T) {36 cfg := config.ForPublicApiTests(22, 0, time.Minute)37 blockTime := primitives.TimestampNano(time.Now().UnixNano())38 response := toGetTxStatusOutput(cfg, &txOutput{39 transactionStatus: protocol.TRANSACTION_STATUS_PENDING,40 transactionReceipt: nil,41 blockHeight: 8,42 blockTimestamp: blockTime,43 })44 require.EqualValues(t, protocol.REQUEST_STATUS_IN_PROCESS, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")45 require.EqualValues(t, 8, response.ClientResponse.RequestResult().BlockHeight(), "Block height response is wrong")46 require.EqualValues(t, blockTime, response.ClientResponse.RequestResult().BlockTimestamp(), "Block time response is wrong")47 require.EqualValues(t, protocol.TRANSACTION_STATUS_PENDING, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")48 require.Equal(t, 0, len(response.ClientResponse.TransactionReceipt().Raw()), "Transaction receipt is not equal")49 test.RequireCmpEqual(t, (*protocol.TransactionReceiptBuilder)(nil).Build(), response.ClientResponse.TransactionReceipt(), "Transaction receipt is not equal")50}51func TestGetTransactionStatus_PrepareResponse_OutOfSync(t *testing.T) {52 ctrlRand := rand.NewControlledRand(t)53 cfg := config.ForPublicApiTests(22, 0, time.Minute)54 blockTime := primitives.TimestampNano(time.Now().Add(time.Hour * -1).UnixNano())55 receipt := builders.TransactionReceipt().WithRandomHash(ctrlRand).Build()56 response := toGetTxStatusOutput(cfg, &txOutput{57 transactionStatus: protocol.TRANSACTION_STATUS_COMMITTED,58 transactionReceipt: receipt,59 blockHeight: 126,60 blockTimestamp: blockTime,61 })62 require.EqualValues(t, protocol.REQUEST_STATUS_COMPLETED, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")63 require.EqualValues(t, 126, response.ClientResponse.RequestResult().BlockHeight(), "Block height response is wrong")64 require.EqualValues(t, blockTime, response.ClientResponse.RequestResult().BlockTimestamp(), "Block time response is wrong")65 require.EqualValues(t, protocol.TRANSACTION_STATUS_COMMITTED, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")66 test.RequireCmpEqual(t, receipt, response.ClientResponse.TransactionReceipt(), "Transaction receipt is not equal")67}68func TestGetTransactionStatus_PrepareResponse_NilReceipt_OutOfSync(t *testing.T) {69 cfg := config.ForPublicApiTests(22, 0, time.Minute)70 blockTime := primitives.TimestampNano(time.Now().Add(time.Hour * -1).UnixNano())71 response := toGetTxStatusOutput(cfg, &txOutput{72 transactionStatus: protocol.TRANSACTION_STATUS_PENDING,73 transactionReceipt: nil,74 blockHeight: 8,75 blockTimestamp: blockTime,76 })77 require.EqualValues(t, protocol.REQUEST_STATUS_OUT_OF_SYNC, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")78 require.EqualValues(t, 8, response.ClientResponse.RequestResult().BlockHeight(), "Block height response is wrong")79 require.EqualValues(t, blockTime, response.ClientResponse.RequestResult().BlockTimestamp(), "Block time response is wrong")80 require.EqualValues(t, protocol.TRANSACTION_STATUS_PENDING, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")81 require.Equal(t, 0, len(response.ClientResponse.TransactionReceipt().Raw()), "Transaction receipt is not equal")82 test.RequireCmpEqual(t, (*protocol.TransactionReceiptBuilder)(nil).Build(), response.ClientResponse.TransactionReceipt(), "Transaction receipt is not equal")83}...

Full Screen

Full Screen

get_transaction_receipt_proof_test.go

Source:get_transaction_receipt_proof_test.go Github

copy

Full Screen

...19func TestGetTransactionReceiptProof_PrepareResponse(t *testing.T) {20 ctrlRand := rand.NewControlledRand(t)21 blockTime := primitives.TimestampNano(time.Now().UnixNano())22 receipt := builders.TransactionReceipt().WithRandomHash(ctrlRand).Builder()23 txStatusOutput := &services.GetTransactionStatusOutput{24 ClientResponse: (&client.GetTransactionStatusResponseBuilder{25 RequestResult: &client.RequestResultBuilder{26 RequestStatus: protocol.REQUEST_STATUS_COMPLETED,27 BlockHeight: 126,28 BlockTimestamp: blockTime,29 },30 TransactionStatus: protocol.TRANSACTION_STATUS_COMMITTED,31 TransactionReceipt: receipt,32 }).Build(),33 }34 proof := (&protocol.ReceiptProofBuilder{35 Header: &protocol.ResultsBlockHeaderBuilder{},36 BlockProof: &protocol.ResultsBlockProofBuilder{},37 ReceiptProof: primitives.MerkleTreeProof([]byte{0x01, 0x02}),38 }).Build()39 proofOutput := &services.GenerateReceiptProofOutput{40 Proof: proof,41 }42 response := toGetTxProofOutput(txStatusOutput, proofOutput)43 require.EqualValues(t, protocol.REQUEST_STATUS_COMPLETED, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")44 require.EqualValues(t, 126, response.ClientResponse.RequestResult().BlockHeight(), "Block height response is wrong")45 require.EqualValues(t, blockTime, response.ClientResponse.RequestResult().BlockTimestamp(), "Block time response is wrong")46 require.EqualValues(t, protocol.TRANSACTION_STATUS_COMMITTED, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")47 test.RequireCmpEqual(t, receipt.Build(), response.ClientResponse.TransactionReceipt(), "Transaction receipt is not equal")48 require.EqualValues(t, proof.Raw(), response.ClientResponse.PackedProof(), "Packed proof is not equal")49}50func TestGetTransactionReceiptProof_PrepareResponse_NilProof(t *testing.T) {51 blockTime := primitives.TimestampNano(time.Now().UnixNano())52 txStatusOutput := &services.GetTransactionStatusOutput{53 ClientResponse: (&client.GetTransactionStatusResponseBuilder{54 RequestResult: &client.RequestResultBuilder{55 RequestStatus: protocol.REQUEST_STATUS_IN_PROCESS,56 BlockHeight: 8,57 BlockTimestamp: blockTime,58 },59 TransactionStatus: protocol.TRANSACTION_STATUS_PENDING,60 TransactionReceipt: nil,61 }).Build(),62 }63 response := toGetTxProofOutput(txStatusOutput, nil)64 require.EqualValues(t, protocol.REQUEST_STATUS_IN_PROCESS, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")65 require.EqualValues(t, 8, response.ClientResponse.RequestResult().BlockHeight(), "Block height response is wrong")66 require.EqualValues(t, blockTime, response.ClientResponse.RequestResult().BlockTimestamp(), "Block time response is wrong")67 require.EqualValues(t, protocol.TRANSACTION_STATUS_PENDING, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")68 require.Equal(t, 0, len(response.ClientResponse.TransactionReceipt().Raw()), "Transaction receipt is not equal")69 test.RequireCmpEqual(t, (*protocol.TransactionReceiptBuilder)(nil).Build(), response.ClientResponse.TransactionReceipt(), "Transaction receipt is not equal")70 require.Equal(t, 0, len(response.ClientResponse.PackedProof()), "Transaction proof is not equal")71 require.EqualValues(t, []byte{}, response.ClientResponse.PackedProof(), "Transaction proof is not equal")72}73func TestGetTransactionReceiptProof_EmptyResponse(t *testing.T) {74 response := toGetTxProofOutput(nil, nil)75 require.EqualValues(t, protocol.REQUEST_STATUS_NOT_FOUND, response.ClientResponse.RequestResult().RequestStatus(), "Request status is wrong")76 require.EqualValues(t, protocol.TRANSACTION_STATUS_NO_RECORD_FOUND, response.ClientResponse.TransactionStatus(), "txStatus response is wrong")77}...

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 status, err := client.Status()7 if err != nil {8 fmt.Println(err)9 }10 fmt.Println(status)11}12{0 0 0 0 0 0 0}

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 header, err := client.HeaderByNumber(nil)7 if err != nil {8 log.Fatal(err)9 }10}11func (ec *Client) Status(ctx context.Context) (*Status, error) {12 err := ec.c.CallContext(ctx, &status, "eth_syncing")13}14func (ec *Client) Status(ctx context.Context) (*Status, error) {15 err := ec.c.CallContext(ctx, &status, "eth_syncing")16}17func (ec *Client) Status(ctx context.Context) (*Status, error) {

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := http.Client{4 }5 if err != nil {6 fmt.Println("Error in creating request")7 }8 req.Header.Set("User-Agent", "my-app/0.0.1")9 resp, err := client.Do(req)10 if err != nil {11 fmt.Println("Error in getting response")12 }13 fmt.Println(resp.Status)14}15import (16func main() {17 client := http.Client{18 }19 if err != nil {20 fmt.Println("Error in creating request")21 }22 req.Header.Set("User-Agent", "my-app/0.0.1")23 resp, err := client.Do(req)24 if err != nil {25 fmt.Println("Error in getting response")26 }27 fmt.Println(resp.Status)28}29import (30func main() {31 client := http.Client{32 }33 if err != nil {34 fmt.Println("Error in creating request")35 }36 req.Header.Set("User-Agent", "my-app/0.0.1")37 resp, err := client.Do(req)38 if err != nil {39 fmt.Println("Error in getting response")40 }41 fmt.Println(resp.StatusCode)42}43import

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 blockNumber := big.NewInt(3000000)7 header, err := client.HeaderByNumber(context.Background(), blockNumber)8 if err != nil {9 log.Fatal(err)10 }11}12import (13func main() {14 if err != nil {15 log.Fatal(err)16 }17 blockNumber := big.NewInt(3000000)18 header, err := client.HeaderByNumber(context.Background(), blockNumber)19 if err != nil {20 log.Fatal(err)21 }22}

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1func main() {2 client := &http.Client{}3 if err != nil {4 panic(err)5 }6 resp, err := client.Do(req)7 if err != nil {8 panic(err)9 }10 defer resp.Body.Close()11 fmt.Println(resp.Status)12}

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 service := micro.NewService()4 service.Init()5 greeter := pb.NewGreeterService("greeter", service.Client())6 rsp, err := greeter.Hello(context.Background(), &pb.Request{7 })8 if err != nil {9 fmt.Println(err)10 }11 fmt.Println(rsp.Greeting)12}13import (14func main() {15 service := micro.NewService()16 service.Init()17 greeter := pb.NewGreeterService("greeter", service.Client())18 rsp, err := greeter.Hello(context.Background(), &pb.Request{19 })20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(rsp.Greeting)24}25import (26func main() {27 service := micro.NewService()28 service.Init()29 greeter := pb.NewGreeterService("greeter", service.Client())30 rsp, err := greeter.Hello(context.Background(), &pb.Request{31 })32 if err != nil {33 fmt.Println(err)34 }35 fmt.Println(rsp.Greeting)36}

Full Screen

Full Screen

Status

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := &http.Client{}4 if err != nil {5 fmt.Println(err)6 }7 res, err := client.Do(req)8 if err != nil {9 fmt.Println(err)10 }11 fmt.Println(res.Status)12}13import (14func main() {15 client := &http.Client{}16 if err != nil {17 fmt.Println(err)18 }19 res, err := client.Do(req)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(res.StatusCode)24}25import (26func main() {27 client := &http.Client{}28 if err != nil {29 fmt.Println(err)30 }31 res, err := client.Do(req)32 if err != nil {33 fmt.Println(err)34 }35 fmt.Println(res.Status)36}37import (38func main() {39 client := &http.Client{}40 if err != nil {41 fmt.Println(err)42 }43 res, err := client.Do(req)44 if err != nil {45 fmt.Println(err)46 }

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.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful