Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rosetta return generic unknown operation type for future transaction types #9030

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
413 changes: 54 additions & 359 deletions hedera-mirror-rosetta/app/domain/types/constants.go

Large diffs are not rendered by default.

397 changes: 363 additions & 34 deletions hedera-mirror-rosetta/app/domain/types/constants_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hedera-mirror-rosetta/app/persistence/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (tr *transactionRepository) constructTransaction(sameHashTransactions []*tr
operations := make(types.OperationSlice, 0)
result := &types.Transaction{Hash: firstTransaction.getHashString(), Memo: firstTransaction.Memo}
success := types.GetTransactionResult(transactionResultSuccess)
transactionType := types.TransactionTypes[int32(firstTransaction.Type)]
transactionType := types.GetTransactionType(int32(firstTransaction.Type))

for _, transaction := range sameHashTransactions {
cryptoTransfers := make([]hbarTransfer, 0)
Expand Down
76 changes: 76 additions & 0 deletions hedera-mirror-rosetta/app/persistence/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package persistence
import (
"encoding/hex"
"testing"
"time"

"github.com/hashgraph/hedera-mirror-node/hedera-mirror-rosetta/app/domain/types"
"github.com/hashgraph/hedera-mirror-node/hedera-mirror-rosetta/app/errors"
Expand Down Expand Up @@ -434,6 +435,81 @@ func (suite *transactionRepositorySuite) TestFindBetweenDbConnectionError() {
assert.Nil(suite.T(), actual)
}

func (suite *transactionRepositorySuite) TestFindBetweenUnknownTransactionType() {
// given
payer := firstEntityId.EncodedId
transaction := tdomain.NewTransactionBuilder(dbClient, payer, time.Now().UnixNano()).
ItemizedTransfer(domain.ItemizedTransferSlice{
{
Amount: -20,
EntityId: firstEntityId,
},
{
Amount: 20,
EntityId: secondEntityId,
},
}).
Type(32767).
Persist()
// add crypto transfers
consensusTimestamp := transaction.ConsensusTimestamp
tdomain.NewCryptoTransferBuilder(dbClient).Amount(-40).EntityId(payer).Timestamp(consensusTimestamp).Persist()
tdomain.NewCryptoTransferBuilder(dbClient).Amount(15).EntityId(3).Timestamp(consensusTimestamp).Persist()
tdomain.NewCryptoTransferBuilder(dbClient).Amount(5).EntityId(feeCollectorEntityId.EncodedId).Timestamp(consensusTimestamp).Persist()
tdomain.NewCryptoTransferBuilder(dbClient).Amount(20).EntityId(secondEntityId.EncodedId).Timestamp(consensusTimestamp).Persist()

expected := []*types.Transaction{
{
Hash: tools.SafeAddHexPrefix(hex.EncodeToString(transaction.TransactionHash)),
Memo: []byte{},
Operations: types.OperationSlice{
{
AccountId: firstAccountId,
Amount: &types.HbarAmount{Value: -20},
Type: "UNKNOWN",
Status: resultSuccess,
},
{
AccountId: secondAccountId,
Amount: &types.HbarAmount{Value: 20},
Index: 1,
Type: "UNKNOWN",
Status: resultSuccess,
},
{
AccountId: types.NewAccountIdFromEntityId(domain.MustDecodeEntityId(3)),
Amount: &types.HbarAmount{Value: 15},
Index: 2,
Type: types.OperationTypeFee,
Status: resultSuccess,
},
{
AccountId: feeCollectorAccountId,
Amount: &types.HbarAmount{Value: 5},
Index: 3,
Type: types.OperationTypeFee,
Status: resultSuccess,
},
{
AccountId: firstAccountId,
Amount: &types.HbarAmount{Value: -20},
Index: 4,
Type: types.OperationTypeFee,
Status: resultSuccess,
},
},
},
}
t := NewTransactionRepository(dbClient)

// when
actual, err := t.FindBetween(defaultContext, consensusTimestamp, consensusTimestamp)

// then
assert.Nil(suite.T(), err)
assert.ElementsMatch(suite.T(), expected, actual)
}

func (suite *transactionRepositorySuite) TestFindByHashInBlock() {
// given
expected := suite.setupDb()
Expand Down
4 changes: 2 additions & 2 deletions hedera-mirror-rosetta/app/services/block_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func expectedTransaction(accountId types.AccountId, entityId *domain.EntityId, h
Operations: []*rTypes.Operation{
{
OperationIdentifier: &rTypes.OperationIdentifier{Index: 0},
Type: types.TransactionTypes[14],
Type: types.GetTransactionType(14),
Status: &statusSuccess,
Account: accountId.ToRosetta(),
Amount: hbarAmount.ToRosetta(),
Expand All @@ -124,7 +124,7 @@ func makeTransaction(entityId *domain.EntityId, hash string) *types.Transaction
AccountId: account,
Amount: &hbarAmount,
Status: statusSuccess,
Type: types.TransactionTypes[14],
Type: types.GetTransactionType(14),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-rosetta/app/services/network_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewNetworkAPIService(
network *rTypes.NetworkIdentifier,
version *rTypes.Version,
) server.NetworkAPIServicer {
operationTypes := tools.GetStringValuesFromInt32StringMap(types.TransactionTypes)
operationTypes := tools.GetStringValuesFromInt32StringMap(types.GetTransactionTypes())
operationTypes = append(operationTypes, types.OperationTypeFee)
return &networkAPIService{
BaseService: baseService,
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-rosetta/app/services/network_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type offlineNetworkServiceSuite struct {
}

func (suite *offlineNetworkServiceSuite) SetupSuite() {
suite.operationTypes = tools.GetStringValuesFromInt32StringMap(types.TransactionTypes)
suite.operationTypes = tools.GetStringValuesFromInt32StringMap(types.GetTransactionTypes())
suite.operationTypes = append(suite.operationTypes, types.OperationTypeFee)
}

Expand Down
9 changes: 2 additions & 7 deletions hedera-mirror-rosetta/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/coinbase/rosetta-sdk-go v0.8.5
github.com/coinbase/rosetta-sdk-go/types v1.0.0
github.com/cucumber/godog v0.14.1
github.com/ethereum/go-ethereum v1.14.7
github.com/ethereum/go-ethereum v1.14.8
github.com/go-playground/validator/v10 v10.22.0
github.com/hashgraph/hedera-protobufs-go v0.2.1-0.20240704081952-395063202d11
github.com/hashgraph/hedera-sdk-go/v2 v2.43.0
Expand Down Expand Up @@ -74,8 +74,7 @@ require (
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
Expand Down Expand Up @@ -135,7 +134,3 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/btcsuite/btcd/btcec/v2 => github.com/btcsuite/btcd/btcec/v2 v2.3.3 // remove when go-ethereum upgrades to be compatible with >= v2.3.4

replace golang.org/x/image/tiff => golang.org/x/image/tiff v0.16.0
Loading
Loading