github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rpc/backend/historical_access_test.go (about) 1 package backend 2 3 import ( 4 "context" 5 6 accessproto "github.com/onflow/flow/protobuf/go/flow/access" 7 "github.com/onflow/flow/protobuf/go/flow/entities" 8 "google.golang.org/grpc/codes" 9 "google.golang.org/grpc/status" 10 11 "github.com/onflow/flow-go/engine/common/rpc/convert" 12 "github.com/onflow/flow-go/model/flow" 13 "github.com/onflow/flow-go/utils/unittest" 14 ) 15 16 // TestHistoricalTransactionResult tests to see if the historical transaction status can be retrieved 17 func (suite *Suite) TestHistoricalTransactionResult() { 18 19 ctx := context.Background() 20 collection := unittest.CollectionFixture(1) 21 transactionBody := collection.Transactions[0] 22 23 txID := transactionBody.ID() 24 // transaction storage returns the corresponding transaction 25 suite.transactions. 26 On("ByID", txID). 27 Return(nil, status.Errorf(codes.NotFound, "not found on main node")) 28 29 accessEventReq := accessproto.GetTransactionRequest{ 30 Id: txID[:], 31 } 32 33 accessEventResp := accessproto.TransactionResultResponse{ 34 Status: entities.TransactionStatus(flow.TransactionStatusSealed), 35 Events: nil, 36 } 37 38 params := suite.defaultBackendParams() 39 params.HistoricalAccessNodes = []accessproto.AccessAPIClient{suite.historicalAccessClient} 40 41 backend, err := New(params) 42 suite.Require().NoError(err) 43 44 // Successfully return the transaction from the historical node 45 suite.historicalAccessClient. 46 On("GetTransactionResult", ctx, &accessEventReq). 47 Return(&accessEventResp, nil). 48 Once() 49 50 // Make the call for the transaction result 51 result, err := backend.GetTransactionResult( 52 ctx, 53 txID, 54 flow.ZeroID, 55 flow.ZeroID, 56 entities.EventEncodingVersion_JSON_CDC_V0, 57 ) 58 suite.checkResponse(result, err) 59 60 // status should be sealed 61 suite.Assert().Equal(flow.TransactionStatusSealed, result.Status) 62 63 suite.assertAllExpectations() 64 } 65 66 // TestHistoricalTransaction tests to see if the historical transaction can be retrieved 67 func (suite *Suite) TestHistoricalTransaction() { 68 69 ctx := context.Background() 70 collection := unittest.CollectionFixture(1) 71 transactionBody := collection.Transactions[0] 72 73 txID := transactionBody.ID() 74 // transaction storage returns the corresponding transaction 75 suite.transactions. 76 On("ByID", txID). 77 Return(nil, status.Errorf(codes.NotFound, "not found on main node")) 78 79 accessEventReq := accessproto.GetTransactionRequest{ 80 Id: txID[:], 81 } 82 83 accessEventResp := accessproto.TransactionResponse{ 84 Transaction: convert.TransactionToMessage(*transactionBody), 85 } 86 87 params := suite.defaultBackendParams() 88 params.HistoricalAccessNodes = []accessproto.AccessAPIClient{suite.historicalAccessClient} 89 90 backend, err := New(params) 91 suite.Require().NoError(err) 92 93 // Successfully return the transaction from the historical node 94 suite.historicalAccessClient. 95 On("GetTransaction", ctx, &accessEventReq). 96 Return(&accessEventResp, nil). 97 Once() 98 99 // Make the call for the transaction result 100 tx, err := backend.GetTransaction(ctx, txID) 101 suite.checkResponse(tx, err) 102 103 suite.assertAllExpectations() 104 }