diff --git a/cmd/api/handlers/operations.go b/cmd/api/handlers/operations.go index 7817e8674..8ae054bc8 100644 --- a/cmd/api/handlers/operations.go +++ b/cmd/api/handlers/operations.go @@ -26,63 +26,6 @@ import ( "github.com/tidwall/gjson" ) -// GetContractOperations godoc -// @Summary Get contract operations -// @Description Get contract operations -// @Tags contract -// @ID get-contract-operations -// @Param network path string true "Network" -// @Param address path string true "KT address" minlength(36) maxlength(36) -// @Param last_id query string false "Last operation ID" -// @Param from query integer false "Timestamp" -// @Param to query integer false "Timestamp" -// @Param size query integer false "Expected OPG count" mininum(1) -// @Param status query string false "Comma-separated operations statuses" -// @Param entrypoints query string false "Comma-separated called entrypoints list" -// @Param with_storage_diff query bool false "Include storage diff to operations or not" -// @Accept json -// @Produce json -// @Success 200 {object} OperationResponse -// @Failure 400 {object} Error -// @Failure 404 {object} Error -// @Failure 500 {object} Error -// @Router /v1/contract/{network}/{address}/operations [get] -func GetContractOperations() gin.HandlerFunc { - return func(c *gin.Context) { - ctx := c.MustGet("context").(*config.Context) - - var req getAccountRequest - if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) { - return - } - - var filtersReq operationsRequest - if err := c.BindQuery(&filtersReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) { - return - } - - account, err := ctx.Accounts.Get(c.Request.Context(), req.Address) - if handleError(c, ctx.Storage, err, http.StatusNotFound) { - return - } - - filters := prepareFilters(filtersReq) - ops, err := ctx.Operations.GetByAccount(c.Request.Context(), account, filtersReq.Size, filters) - if handleError(c, ctx.Storage, err, 0) { - return - } - - resp, err := PrepareOperations(c.Request.Context(), ctx, ops.Operations, filtersReq.WithStorageDiff) - if handleError(c, ctx.Storage, err, 0) { - return - } - c.SecureJSON(http.StatusOK, OperationResponse{ - Operations: resp, - LastID: ops.LastID, - }) - } -} - // GetOperation godoc // @Summary Get operation group // @Description Get operation group by hash @@ -207,12 +150,12 @@ func GetImplicitOperation() gin.HandlerFunc { return } - op, err := ctx.Operations.GetImplicitOperation(c.Request.Context(), req.Counter) + operations, err := ctx.Operations.GetByHashAndCounter(c.Request.Context(), nil, req.Counter) if handleError(c, ctx.Storage, err, 0) { return } - resp, err := PrepareOperations(c.Request.Context(), ctx, []operation.Operation{op}, false) + resp, err := PrepareOperations(c.Request.Context(), ctx, operations, false) if handleError(c, ctx.Storage, err, 0) { return } @@ -402,8 +345,8 @@ func GetByHashAndCounter() gin.HandlerFunc { var opg []operation.Operation var foundContext *config.Context - ctx, err := ctxs.Get(modelTypes.NewNetwork(args.Network)) - if err == nil { + network := modelTypes.NewNetwork(args.Network) + if ctx, ok := ctxs[network]; ok { opg, err = ctx.Operations.GetByHashAndCounter(c.Request.Context(), hash, req.Counter) if handleError(c, ctx.Storage, err, 0) { return @@ -447,36 +390,6 @@ func getOperationFromMempool(c context.Context, ctx *config.Context, hash string } } -func prepareFilters(req operationsRequest) map[string]interface{} { - filters := map[string]interface{}{} - - if req.LastID != "" { - filters["last_id"] = req.LastID - } - - if req.From > 0 { - filters["from"] = req.From / 1000 - } - - if req.To > 0 { - filters["to"] = req.To / 1000 - } - - if req.Status != "" { - statusList := make([]modelTypes.OperationStatus, 0) - for _, item := range strings.Split(req.Status, ",") { - status := modelTypes.NewOperationStatus(item) - statusList = append(statusList, status) - } - filters["status"] = statusList - } - - if req.Entrypoints != "" { - filters["entrypoints"] = strings.Split(req.Entrypoints, ",") - } - return filters -} - func formatErrors(errs []*tezerrors.Error, op *Operation) error { for i := range errs { if err := errs[i].Format(); err != nil { diff --git a/cmd/api/handlers/requests.go b/cmd/api/handlers/requests.go index 346a98f81..fbe9d3916 100644 --- a/cmd/api/handlers/requests.go +++ b/cmd/api/handlers/requests.go @@ -92,16 +92,6 @@ type OauthParams struct { Provider string `uri:"provider"` } -type operationsRequest struct { - LastID string `form:"last_id" binding:"omitempty,numeric"` - From uint `form:"from" binding:"omitempty"` - To uint `form:"to" binding:"omitempty,gtfield=From"` - Size uint64 `form:"size" binding:"min=0"` - Status string `form:"status" binding:"omitempty,status"` - Entrypoints string `form:"entrypoints" binding:"omitempty,excludesall=\"'"` - WithStorageDiff bool `form:"with_storage_diff"` -} - type opgForAddressRequest struct { LastID int64 `form:"last_id" binding:"omitempty"` Size uint64 `form:"size" binding:"min=0"` diff --git a/cmd/api/main.go b/cmd/api/main.go index f3e043dd5..835077e2e 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -178,7 +178,6 @@ func (api *app) makeRouter() { { contract.GET("", handlers.ContextsMiddleware(api.Contexts), handlers.GetContract()) contract.GET("code", handlers.GetContractCode()) - contract.GET("operations", handlers.GetContractOperations()) contract.GET("opg", handlers.GetOperationGroups()) contract.GET("migrations", handlers.GetContractMigrations()) contract.GET("global_constants", handlers.GetContractGlobalConstants()) diff --git a/internal/models/mock/operation/mock.go b/internal/models/mock/operation/mock.go index cc4cd4034..626d3e55a 100644 --- a/internal/models/mock/operation/mock.go +++ b/internal/models/mock/operation/mock.go @@ -12,7 +12,6 @@ import ( context "context" reflect "reflect" - account "github.com/baking-bad/bcdhub/internal/models/account" operation "github.com/baking-bad/bcdhub/internal/models/operation" gomock "go.uber.org/mock/gomock" ) @@ -79,84 +78,6 @@ func (c *RepositoryEventsCountCall) DoAndReturn(f func(context.Context, int64) ( return c } -// Get mocks base method. -func (m *MockRepository) Get(ctx context.Context, filter map[string]any, size int64, sort bool) ([]operation.Operation, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", ctx, filter, size, sort) - ret0, _ := ret[0].([]operation.Operation) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Get indicates an expected call of Get. -func (mr *MockRepositoryMockRecorder) Get(ctx, filter, size, sort any) *RepositoryGetCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRepository)(nil).Get), ctx, filter, size, sort) - return &RepositoryGetCall{Call: call} -} - -// RepositoryGetCall wrap *gomock.Call -type RepositoryGetCall struct { - *gomock.Call -} - -// Return rewrite *gomock.Call.Return -func (c *RepositoryGetCall) Return(arg0 []operation.Operation, arg1 error) *RepositoryGetCall { - c.Call = c.Call.Return(arg0, arg1) - return c -} - -// Do rewrite *gomock.Call.Do -func (c *RepositoryGetCall) Do(f func(context.Context, map[string]any, int64, bool) ([]operation.Operation, error)) *RepositoryGetCall { - c.Call = c.Call.Do(f) - return c -} - -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *RepositoryGetCall) DoAndReturn(f func(context.Context, map[string]any, int64, bool) ([]operation.Operation, error)) *RepositoryGetCall { - c.Call = c.Call.DoAndReturn(f) - return c -} - -// GetByAccount mocks base method. -func (m *MockRepository) GetByAccount(ctx context.Context, acc account.Account, size uint64, filters map[string]any) (operation.Pageable, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetByAccount", ctx, acc, size, filters) - ret0, _ := ret[0].(operation.Pageable) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetByAccount indicates an expected call of GetByAccount. -func (mr *MockRepositoryMockRecorder) GetByAccount(ctx, acc, size, filters any) *RepositoryGetByAccountCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByAccount", reflect.TypeOf((*MockRepository)(nil).GetByAccount), ctx, acc, size, filters) - return &RepositoryGetByAccountCall{Call: call} -} - -// RepositoryGetByAccountCall wrap *gomock.Call -type RepositoryGetByAccountCall struct { - *gomock.Call -} - -// Return rewrite *gomock.Call.Return -func (c *RepositoryGetByAccountCall) Return(arg0 operation.Pageable, arg1 error) *RepositoryGetByAccountCall { - c.Call = c.Call.Return(arg0, arg1) - return c -} - -// Do rewrite *gomock.Call.Do -func (c *RepositoryGetByAccountCall) Do(f func(context.Context, account.Account, uint64, map[string]any) (operation.Pageable, error)) *RepositoryGetByAccountCall { - c.Call = c.Call.Do(f) - return c -} - -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *RepositoryGetByAccountCall) DoAndReturn(f func(context.Context, account.Account, uint64, map[string]any) (operation.Pageable, error)) *RepositoryGetByAccountCall { - c.Call = c.Call.DoAndReturn(f) - return c -} - // GetByHash mocks base method. func (m *MockRepository) GetByHash(ctx context.Context, hash []byte) ([]operation.Operation, error) { m.ctrl.T.Helper() @@ -274,45 +195,6 @@ func (c *RepositoryGetByIDCall) DoAndReturn(f func(context.Context, int64) (oper return c } -// GetImplicitOperation mocks base method. -func (m *MockRepository) GetImplicitOperation(ctx context.Context, counter int64) (operation.Operation, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetImplicitOperation", ctx, counter) - ret0, _ := ret[0].(operation.Operation) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetImplicitOperation indicates an expected call of GetImplicitOperation. -func (mr *MockRepositoryMockRecorder) GetImplicitOperation(ctx, counter any) *RepositoryGetImplicitOperationCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImplicitOperation", reflect.TypeOf((*MockRepository)(nil).GetImplicitOperation), ctx, counter) - return &RepositoryGetImplicitOperationCall{Call: call} -} - -// RepositoryGetImplicitOperationCall wrap *gomock.Call -type RepositoryGetImplicitOperationCall struct { - *gomock.Call -} - -// Return rewrite *gomock.Call.Return -func (c *RepositoryGetImplicitOperationCall) Return(arg0 operation.Operation, arg1 error) *RepositoryGetImplicitOperationCall { - c.Call = c.Call.Return(arg0, arg1) - return c -} - -// Do rewrite *gomock.Call.Do -func (c *RepositoryGetImplicitOperationCall) Do(f func(context.Context, int64) (operation.Operation, error)) *RepositoryGetImplicitOperationCall { - c.Call = c.Call.Do(f) - return c -} - -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *RepositoryGetImplicitOperationCall) DoAndReturn(f func(context.Context, int64) (operation.Operation, error)) *RepositoryGetImplicitOperationCall { - c.Call = c.Call.DoAndReturn(f) - return c -} - // Last mocks base method. func (m *MockRepository) Last(ctx context.Context, filter map[string]any, lastID int64) (operation.Operation, error) { m.ctrl.T.Helper() diff --git a/internal/models/operation/repository.go b/internal/models/operation/repository.go index 0fce04ea3..388099c16 100644 --- a/internal/models/operation/repository.go +++ b/internal/models/operation/repository.go @@ -2,26 +2,16 @@ package operation import ( "context" - - "github.com/baking-bad/bcdhub/internal/models/account" ) //go:generate mockgen -source=$GOFILE -destination=../mock/operation/mock.go -package=operation -typed type Repository interface { - GetByAccount(ctx context.Context, acc account.Account, size uint64, filters map[string]interface{}) (Pageable, error) - // Last - get last operation by `filters` with not empty deffated_storage. Last(ctx context.Context, filter map[string]interface{}, lastID int64) (Operation, error) GetByHash(ctx context.Context, hash []byte) ([]Operation, error) GetByHashAndCounter(ctx context.Context, hash []byte, counter int64) ([]Operation, error) - GetImplicitOperation(ctx context.Context, counter int64) (Operation, error) OPG(ctx context.Context, address string, size, lastID int64) ([]OPG, error) Origination(ctx context.Context, accountID int64) (Operation, error) - - // GetOperations - get operation by `filter`. `Size` - if 0 - return all, else certain `size` operations. - // `Sort` - sort by time and content index by desc - Get(ctx context.Context, filter map[string]interface{}, size int64, sort bool) ([]Operation, error) GetByID(ctx context.Context, id int64) (Operation, error) - ListEvents(ctx context.Context, accountID int64, size, offset int64) ([]Operation, error) EventsCount(ctx context.Context, accountID int64) (int, error) } diff --git a/internal/parsers/stacktrace/stacktrace.go b/internal/parsers/stacktrace/stacktrace.go index 2ac8e431e..9010307d0 100644 --- a/internal/parsers/stacktrace/stacktrace.go +++ b/internal/parsers/stacktrace/stacktrace.go @@ -1,7 +1,6 @@ package stacktrace import ( - "context" "fmt" "io" "strings" @@ -173,17 +172,3 @@ func (st *StackTrace) print(arr []int64, depth int, builder io.StringWriter) err } return nil } - -// Fill - -func (st *StackTrace) Fill(ctx context.Context, repo operation.Repository, op operation.Operation) error { - ops, err := repo.Get(ctx, map[string]interface{}{ - "hash": op.Hash, - }, 0, true) - if err != nil { - return err - } - for i := range ops { - st.Add(ops[i]) - } - return nil -} diff --git a/internal/postgres/operation/storage.go b/internal/postgres/operation/storage.go index 2926f7a3c..2b6bce2d7 100644 --- a/internal/postgres/operation/storage.go +++ b/internal/postgres/operation/storage.go @@ -3,7 +3,6 @@ package operation import ( "context" "database/sql" - "fmt" "time" "github.com/baking-bad/bcdhub/internal/bcd/consts" @@ -12,7 +11,6 @@ import ( "github.com/baking-bad/bcdhub/internal/models/operation" "github.com/baking-bad/bcdhub/internal/models/types" "github.com/baking-bad/bcdhub/internal/postgres/core" - "github.com/pkg/errors" "github.com/uptrace/bun" ) @@ -26,103 +24,6 @@ func NewStorage(es *core.Postgres) *Storage { return &Storage{es} } -type opgForContract struct { - Counter int64 - Hash []byte - ID int64 -} - -func (storage *Storage) getContractOPG(ctx context.Context, accountID int64, size uint64, filters map[string]interface{}) (response []opgForContract, err error) { - subQuery := storage.DB.NewSelect().Model((*operation.Operation)(nil)).Column("hash", "counter", "id") - - if _, ok := filters["entrypoints"]; !ok { - subQuery.Where("source_id = ? OR destination_id = ?", accountID, accountID) - } else { - subQuery.Where("destination_id = ?", accountID) - } - - if err := prepareOperationFilters(subQuery, filters); err != nil { - return nil, err - } - - query := storage.DB.NewSelect().TableExpr("(?) as foo", subQuery.Order("id desc").Limit(1000)). - ColumnExpr("foo.hash, foo.counter, max(id) as id") - - limit := storage.GetPageSize(int64(size)) - query.GroupExpr("foo.hash, foo.counter").Order("id desc").Limit(limit) - - err = query.Scan(ctx, &response) - return -} - -func prepareOperationFilters(query *bun.SelectQuery, filters map[string]interface{}) error { - for k, v := range filters { - if v != "" { - switch k { - case "from": - query.Where("timestamp >= to_timestamp(?)", v) - case "to": - query.Where("timestamp <= to_timestamp(?)", v) - case "entrypoints": - query.Where("entrypoint IN (?)", bun.In(v)) - case "last_id": - query.Where("id < ?", v) - case "status": - query.Where("status IN (?)", bun.In(v)) - default: - return errors.Errorf("unknown operation filter: %s %v", k, v) - } - } - } - return nil -} - -// GetByContract - -func (storage *Storage) GetByAccount(ctx context.Context, acc account.Account, size uint64, filters map[string]interface{}) (po operation.Pageable, err error) { - opg, err := storage.getContractOPG(ctx, acc.ID, size, filters) - if err != nil { - return - } - if len(opg) == 0 { - return - } - - query := storage.DB.NewSelect().Model(&po.Operations).WhereGroup( - " AND ", func(q *bun.SelectQuery) *bun.SelectQuery { - for i := range opg { - q.WhereGroup(" OR ", func(q *bun.SelectQuery) *bun.SelectQuery { - if opg[i].Hash == nil { - q.Where("operation.hash is null") - } else { - q.Where("operation.hash = ?", opg[i].Hash) - } - return q.Where("operation.counter = ?", opg[i].Counter) - }) - } - return q - }).Relation("Destination").Relation("Source").Relation("Initiator").Relation("Delegate") - - addOperationSorting(query) - - if err = query.Scan(ctx); err != nil { - return - } - - if len(po.Operations) == 0 { - return - } - - lastID := po.Operations[0].ID - for _, op := range po.Operations[1:] { - if op.ID > lastID { - continue - } - lastID = op.ID - } - po.LastID = fmt.Sprintf("%d", lastID) - return -} - // Last - get last operation by `filters` with not empty deffated_storage func (storage *Storage) Last(ctx context.Context, filters map[string]interface{}, lastID int64) (operation.Operation, error) { var ( @@ -193,44 +94,6 @@ func (storage *Storage) Last(ctx context.Context, filters map[string]interface{} return operation.Operation{}, sql.ErrNoRows } -// Get - -func (storage *Storage) Get(ctx context.Context, filters map[string]interface{}, size int64, sort bool) (operations []operation.Operation, err error) { - query := storage.DB.NewSelect(). - Model(&operations). - Relation("Destination", func(q *bun.SelectQuery) *bun.SelectQuery { - return q.Column("address") - }) - - for key, value := range filters { - query.Where("? = ?", bun.Ident(key), value) - } - - if sort { - addOperationSorting(query) - } - - if size > 0 { - query.Limit(storage.GetPageSize(size)) - } - - err = query.Scan(ctx) - return operations, err -} - -// GetByHash - -func (storage *Storage) GetByHash(ctx context.Context, hash []byte) (operations []operation.Operation, err error) { - query := storage.DB.NewSelect().Model((*operation.Operation)(nil)).Where("hash = ?", hash) - addOperationSorting(query) - err = storage.DB.NewSelect().TableExpr("(?) as operation", query). - ColumnExpr("operation.*"). - ColumnExpr("source.address as source__address, source.type as source__type,source.id as source__id"). - ColumnExpr("destination.address as destination__address, destination.type as destination__type, destination.id as destination__id"). - Join("LEFT JOIN accounts as source ON source.id = operation.source_id"). - Join("LEFT JOIN accounts as destination ON destination.id = operation.destination_id"). - Scan(ctx, &operations) - return operations, err -} - // GetByID - func (storage *Storage) GetByID(ctx context.Context, id int64) (result operation.Operation, err error) { err = storage.DB.NewSelect(). @@ -370,22 +233,33 @@ func (storage *Storage) OPG(ctx context.Context, address string, size, lastID in return result, nil } +// GetByHash - +func (storage *Storage) GetByHash(ctx context.Context, hash []byte) (operations []operation.Operation, err error) { + query := storage.DB.NewSelect().Model((*operation.Operation)(nil)). + Where("hash = ?", hash) + + addOperationSorting(query) + err = storage.DB.NewSelect().TableExpr("(?) as operation", query). + ColumnExpr("operation.*"). + ColumnExpr("source.address as source__address, source.type as source__type,source.id as source__id"). + ColumnExpr("destination.address as destination__address, destination.type as destination__type, destination.id as destination__id"). + Join("LEFT JOIN accounts as source ON source.id = operation.source_id"). + Join("LEFT JOIN accounts as destination ON destination.id = operation.destination_id"). + Scan(ctx, &operations) + return operations, err +} + // GetByHashAndCounter - func (storage *Storage) GetByHashAndCounter(ctx context.Context, hash []byte, counter int64) (operations []operation.Operation, err error) { - err = storage.DB.NewSelect().Model(&operations). - Where("hash = ?", hash). - Where("counter = ?", counter). - Relation("Destination").Relation("Source").Relation("Initiator").Relation("Delegate"). - Order("id asc"). - Scan(ctx) - return -} + query := storage.DB.NewSelect().Model(&operations) -// GetImplicitOperation - -func (storage *Storage) GetImplicitOperation(ctx context.Context, counter int64) (op operation.Operation, err error) { - err = storage.DB.NewSelect().Model(&op). - Where("hash is null"). - Where("counter = ?", counter). + if hash == nil { + query = query.Where("hash is null") + } else { + query = query.Where("hash = ?", hash) + } + + err = query.Where("counter = ?", counter). Relation("Destination").Relation("Source").Relation("Initiator").Relation("Delegate"). Order("id asc"). Scan(ctx) @@ -416,7 +290,8 @@ func (storage *Storage) ListEvents(ctx context.Context, accountID int64, size, o func (storage *Storage) EventsCount(ctx context.Context, accountID int64) (int, error) { return storage.DB.NewSelect().Model((*operation.Operation)(nil)). Where("source_id = ?", accountID). - Where("kind = 7").Count(ctx) + Where("kind = 7"). + Count(ctx) } // Origination - diff --git a/internal/postgres/tests/operations_test.go b/internal/postgres/tests/operations_test.go index bcefb88a9..7483038b4 100644 --- a/internal/postgres/tests/operations_test.go +++ b/internal/postgres/tests/operations_test.go @@ -4,46 +4,10 @@ import ( "context" "time" - "github.com/baking-bad/bcdhub/internal/models/account" "github.com/baking-bad/bcdhub/internal/models/types" "github.com/baking-bad/bcdhub/internal/testsuite" ) -func (s *StorageTestSuite) TestOperationsGetByAccount() { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - - operations, err := s.operations.GetByAccount(ctx, account.Account{ - Address: "KT18sWFGnjvobw9BiHrm9bjpWr3AFAAVas9w", - ID: 88, - Type: types.AccountTypeContract, - }, 10, nil) - s.Require().NoError(err) - s.Require().Len(operations.Operations, 2) - s.Require().EqualValues(operations.LastID, "58") - - operation := operations.Operations[0] - s.Require().EqualValues(67, operation.ID) - s.Require().EqualValues(0, operation.ContentIndex) - s.Require().EqualValues(37, operation.Level) - s.Require().EqualValues(540, operation.Counter) - s.Require().EqualValues(518, operation.Fee) - s.Require().EqualValues(2155, operation.GasLimit) - s.Require().EqualValues(0, operation.StorageLimit) - s.Require().EqualValues(0, operation.Amount) - s.Require().EqualValues(2054659, operation.ConsumedGas) - s.Require().EqualValues(87, operation.StorageSize) - s.Require().EqualValues(92, operation.InitiatorID) - s.Require().EqualValues(92, operation.SourceID) - s.Require().EqualValues(88, operation.DestinationID) - s.Require().EqualValues(types.OperationStatusApplied, operation.Status) - s.Require().EqualValues(types.OperationKindTransaction, operation.Kind) - s.Require().EqualValues("@entrypoint_0", operation.Entrypoint.String()) - s.Require().NotEmpty(operation.Parameters) - s.Require().NotEmpty(operation.DeffatedStorage) - s.Require().Equal(testsuite.MustHexDecode("a47ce950e17c7f06af8e9e992ae10ad2b7aca0cf8a72c0ce451684f673f20324"), operation.Hash) -} - func (s *StorageTestSuite) TestOperationsLast() { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() @@ -74,39 +38,6 @@ func (s *StorageTestSuite) TestOperationsLast() { s.Require().Equal(testsuite.MustHexDecode("a47ce950e17c7f06af8e9e992ae10ad2b7aca0cf8a72c0ce451684f673f20324"), operation.Hash) } -func (s *StorageTestSuite) TestOperationsGet() { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - - operations, err := s.operations.Get(ctx, map[string]interface{}{ - "destination_id": 88, - }, 10, true) - s.Require().NoError(err) - s.Require().Len(operations, 2) - - operation := operations[0] - - s.Require().EqualValues(67, operation.ID) - s.Require().EqualValues(0, operation.ContentIndex) - s.Require().EqualValues(37, operation.Level) - s.Require().EqualValues(540, operation.Counter) - s.Require().EqualValues(518, operation.Fee) - s.Require().EqualValues(2155, operation.GasLimit) - s.Require().EqualValues(0, operation.StorageLimit) - s.Require().EqualValues(0, operation.Amount) - s.Require().EqualValues(2054659, operation.ConsumedGas) - s.Require().EqualValues(87, operation.StorageSize) - s.Require().EqualValues(92, operation.InitiatorID) - s.Require().EqualValues(92, operation.SourceID) - s.Require().EqualValues(88, operation.DestinationID) - s.Require().EqualValues(types.OperationStatusApplied, operation.Status) - s.Require().EqualValues(types.OperationKindTransaction, operation.Kind) - s.Require().EqualValues("@entrypoint_0", operation.Entrypoint.String()) - s.Require().NotEmpty(operation.Parameters) - s.Require().NotEmpty(operation.DeffatedStorage) - s.Require().Equal(testsuite.MustHexDecode("a47ce950e17c7f06af8e9e992ae10ad2b7aca0cf8a72c0ce451684f673f20324"), operation.Hash) -} - func (s *StorageTestSuite) TestOperationsGetByHash() { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() @@ -224,8 +155,11 @@ func (s *StorageTestSuite) TestOperationGetImplicitOperation() { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - operation, err := s.operations.GetImplicitOperation(ctx, 2) + operations, err := s.operations.GetByHashAndCounter(ctx, nil, 2) s.Require().NoError(err) + s.Require().Len(operations, 1) + + operation := operations[0] s.Require().EqualValues(1, operation.ID) s.Require().EqualValues(0, operation.ContentIndex)