QOL Fixes for Rosetta (#3418)

* [rosetta] Make nonsensical native tx construction error

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Refactor native constant names to match value

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Remove hex address comparison

This is done since the hex address in the metadata is more of a
QOL feature, all that matters is the b32 address.

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Fix error message for incorrect signed tx parse

* Add check for sender address when parsing unsigned tx

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Make bad signature error message clearer

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Add shard ID check when combining transactions

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Add shard ID check for tx Hash & Submission

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Fix invalid signature type err msg

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Add shard check for tx parse

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Add check for shard ID when creating Tx payload

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
pull/3420/head
Daniel Van Der Maden 4 years ago committed by GitHub
parent 9018d10bc9
commit 1336e063ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      rosetta/common/operations.go
  2. 4
      rosetta/common/operations_test.go
  3. 16
      rosetta/services/construction_check.go
  4. 8
      rosetta/services/construction_check_test.go
  5. 20
      rosetta/services/construction_create.go
  6. 18
      rosetta/services/construction_parse.go
  7. 11
      rosetta/services/construction_submit.go
  8. 4
      rosetta/services/tx_construction.go
  9. 22
      rosetta/services/tx_construction_test.go
  10. 2
      rosetta/services/tx_format.go
  11. 6
      rosetta/services/tx_format_test.go
  12. 4
      rosetta/services/tx_operation.go
  13. 6
      rosetta/services/tx_operation_components.go
  14. 30
      rosetta/services/tx_operation_components_test.go
  15. 6
      rosetta/services/tx_operation_test.go

@ -15,11 +15,11 @@ const (
// ExpendGasOperation is an operation that only affects the native currency. // ExpendGasOperation is an operation that only affects the native currency.
ExpendGasOperation = "Gas" ExpendGasOperation = "Gas"
// TransferNativeOperation is an operation that only affects the native currency. // NativeTransferOperation is an operation that only affects the native currency.
TransferNativeOperation = "NativeTransfer" NativeTransferOperation = "NativeTransfer"
// CrossShardTransferNativeOperation is an operation that only affects the native currency. // NativeCrossShardTransferOperation is an operation that only affects the native currency.
CrossShardTransferNativeOperation = "NativeCrossShardTransfer" NativeCrossShardTransferOperation = "NativeCrossShardTransfer"
// ContractCreationOperation is an operation that only affects the native currency. // ContractCreationOperation is an operation that only affects the native currency.
ContractCreationOperation = "ContractCreation" ContractCreationOperation = "ContractCreation"
@ -41,8 +41,8 @@ var (
// PlainOperationTypes .. // PlainOperationTypes ..
PlainOperationTypes = []string{ PlainOperationTypes = []string{
ExpendGasOperation, ExpendGasOperation,
TransferNativeOperation, NativeTransferOperation,
CrossShardTransferNativeOperation, NativeCrossShardTransferOperation,
ContractCreationOperation, ContractCreationOperation,
GenesisFundsOperation, GenesisFundsOperation,
PreStakingBlockRewardOperation, PreStakingBlockRewardOperation,

@ -50,8 +50,8 @@ func TestPlainOperationTypes(t *testing.T) {
plainOperationTypes := PlainOperationTypes plainOperationTypes := PlainOperationTypes
referenceOperationTypes := []string{ referenceOperationTypes := []string{
ExpendGasOperation, ExpendGasOperation,
TransferNativeOperation, NativeTransferOperation,
CrossShardTransferNativeOperation, NativeCrossShardTransferOperation,
ContractCreationOperation, ContractCreationOperation,
GenesisFundsOperation, GenesisFundsOperation,
PreStakingBlockRewardOperation, PreStakingBlockRewardOperation,

@ -76,6 +76,17 @@ func (s *ConstructAPI) ConstructionPreprocess(
"message": "sender address is not found for given operations", "message": "sender address is not found for given operations",
}) })
} }
if txMetadata.ToShardID != nil && txMetadata.FromShardID != nil &&
components.Type != common.NativeCrossShardTransferOperation && *txMetadata.ToShardID != *txMetadata.FromShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "given from & to shard are different for a native same shard transfer",
})
}
if request.SuggestedFeeMultiplier != nil && *request.SuggestedFeeMultiplier < 1 {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "given gas price multiplier must be at least 1",
})
}
options, err := types.MarshalMap(ConstructMetadataOptions{ options, err := types.MarshalMap(ConstructMetadataOptions{
TransactionMetadata: txMetadata, TransactionMetadata: txMetadata,
@ -87,6 +98,11 @@ func (s *ConstructAPI) ConstructionPreprocess(
"message": err.Error(), "message": err.Error(),
}) })
} }
if _, err := getAddress(components.From); err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": err.Error(),
})
}
return &types.ConstructionPreprocessResponse{ return &types.ConstructionPreprocessResponse{
Options: options, Options: options,
RequiredPublicKeys: []*types.AccountIdentifier{ RequiredPublicKeys: []*types.AccountIdentifier{

@ -28,7 +28,7 @@ func TestConstructMetadataOptions(t *testing.T) {
{ {
Metadata: ConstructMetadataOptions{ Metadata: ConstructMetadataOptions{
TransactionMetadata: refTxMedata, TransactionMetadata: refTxMedata,
OperationType: common.TransferNativeOperation, OperationType: common.NativeTransferOperation,
GasPriceMultiplier: nil, GasPriceMultiplier: nil,
}, },
ExpectError: false, ExpectError: false,
@ -36,7 +36,7 @@ func TestConstructMetadataOptions(t *testing.T) {
{ {
Metadata: ConstructMetadataOptions{ Metadata: ConstructMetadataOptions{
TransactionMetadata: refTxMedata, TransactionMetadata: refTxMedata,
OperationType: common.TransferNativeOperation, OperationType: common.NativeTransferOperation,
GasPriceMultiplier: &refGasPrice, GasPriceMultiplier: &refGasPrice,
}, },
ExpectError: false, ExpectError: false,
@ -44,7 +44,7 @@ func TestConstructMetadataOptions(t *testing.T) {
{ {
Metadata: ConstructMetadataOptions{ Metadata: ConstructMetadataOptions{
TransactionMetadata: nil, TransactionMetadata: nil,
OperationType: common.TransferNativeOperation, OperationType: common.NativeTransferOperation,
GasPriceMultiplier: &refGasPrice, GasPriceMultiplier: &refGasPrice,
}, },
ExpectError: true, ExpectError: true,
@ -52,7 +52,7 @@ func TestConstructMetadataOptions(t *testing.T) {
{ {
Metadata: ConstructMetadataOptions{ Metadata: ConstructMetadataOptions{
TransactionMetadata: nil, TransactionMetadata: nil,
OperationType: common.TransferNativeOperation, OperationType: common.NativeTransferOperation,
GasPriceMultiplier: nil, GasPriceMultiplier: nil,
}, },
ExpectError: true, ExpectError: true,

@ -113,11 +113,18 @@ func (s *ConstructAPI) ConstructionPayloads(
"message": "sender address is not found for given operations", "message": "sender address is not found for given operations",
}) })
} }
if types.Hash(senderID) != types.Hash(components.From) { if senderID.Address != components.From.Address {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "sender account identifier from operations does not match account identifier from public key", "message": "sender account identifier from operations does not match account identifier from public key",
}) })
} }
if metadata.Transaction.FromShardID != nil && *metadata.Transaction.FromShardID != s.hmy.ShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("transaction is for shard %v != shard %v",
*metadata.Transaction.FromShardID, s.hmy.ShardID,
),
})
}
unsignedTx, rosettaError := ConstructTransaction(components, metadata, s.hmy.ShardID) unsignedTx, rosettaError := ConstructTransaction(components, metadata, s.hmy.ShardID)
if rosettaError != nil { if rosettaError != nil {
@ -187,11 +194,16 @@ func (s *ConstructAPI) ConstructionCombine(
"message": "require exactly 1 signature", "message": "require exactly 1 signature",
}) })
} }
if tx.ShardID() != s.hmy.ShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("transaction is for shard %v != shard %v", tx.ShardID(), s.hmy.ShardID),
})
}
sig := request.Signatures[0] sig := request.Signatures[0]
if sig.SignatureType != common.SignatureType { if sig.SignatureType != common.SignatureType {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("invalid transaction type, currently only support %v", common.SignatureType), "message": fmt.Sprintf("invalid signature type, currently only support %v", common.SignatureType),
}) })
} }
sigAddress, rosettaError := getAddressFromPublicKey(sig.PublicKey) sigAddress, rosettaError := getAddressFromPublicKey(sig.PublicKey)
@ -202,7 +214,7 @@ func (s *ConstructAPI) ConstructionCombine(
if rosettaError != nil { if rosettaError != nil {
return nil, rosettaError return nil, rosettaError
} }
if wrappedTransaction.From == nil || types.Hash(wrappedTransaction.From) != types.Hash(sigAccountID) { if wrappedTransaction.From == nil || wrappedTransaction.From.Address != sigAccountID.Address {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "signer public key does not match unsigned transaction's sender", "message": "signer public key does not match unsigned transaction's sender",
}) })
@ -242,7 +254,7 @@ func (s *ConstructAPI) ConstructionCombine(
senderAddress, err := signedTx.SenderAddress() senderAddress, err := signedTx.SenderAddress()
if err != nil { if err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "unable to get sender address with signed transaction").Error(), "message": errors.WithMessage(err, "bad signature payload").Error(),
}) })
} }
if *sigAddress != senderAddress { if *sigAddress != senderAddress {

@ -2,6 +2,7 @@ package services
import ( import (
"context" "context"
"fmt"
"github.com/coinbase/rosetta-sdk-go/types" "github.com/coinbase/rosetta-sdk-go/types"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -21,6 +22,11 @@ func (s *ConstructAPI) ConstructionParse(
if rosettaError != nil { if rosettaError != nil {
return nil, rosettaError return nil, rosettaError
} }
if tx.ShardID() != s.hmy.ShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("transaction is for shard %v != shard %v", tx.ShardID(), s.hmy.ShardID),
})
}
if request.Signed { if request.Signed {
return parseSignedTransaction(ctx, wrappedTransaction, tx) return parseSignedTransaction(ctx, wrappedTransaction, tx)
} }
@ -37,6 +43,12 @@ func parseUnsignedTransaction(
}) })
} }
if _, err := getAddress(wrappedTransaction.From); err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": err.Error(),
})
}
// TODO (dm): implement intended receipt for staking transactions // TODO (dm): implement intended receipt for staking transactions
intendedReceipt := &hmyTypes.Receipt{ intendedReceipt := &hmyTypes.Receipt{
GasUsed: tx.Gas(), GasUsed: tx.Gas(),
@ -52,7 +64,7 @@ func parseUnsignedTransaction(
foundSender := false foundSender := false
operations := formattedTx.Operations operations := formattedTx.Operations
for _, op := range operations { for _, op := range operations {
if types.Hash(op.Account) == types.Hash(tempAccID) { if op.Account.Address == tempAccID.Address {
foundSender = true foundSender = true
op.Account = wrappedTransaction.From op.Account = wrappedTransaction.From
} }
@ -89,14 +101,14 @@ func parseSignedTransaction(
sender, err := tx.SenderAddress() sender, err := tx.SenderAddress()
if err != nil { if err != nil {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": errors.WithMessage(err, "unable to get sender address, invalid signed transaction"), "message": errors.WithMessage(err, "unable to get sender address for signed transaction").Error(),
}) })
} }
senderID, rosettaError := newAccountIdentifier(sender) senderID, rosettaError := newAccountIdentifier(sender)
if rosettaError != nil { if rosettaError != nil {
return nil, rosettaError return nil, rosettaError
} }
if types.Hash(senderID) != types.Hash(wrappedTransaction.From) { if senderID.Address != wrappedTransaction.From.Address {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "wrapped transaction sender/from does not match transaction signer", "message": "wrapped transaction sender/from does not match transaction signer",
}) })

@ -2,6 +2,7 @@ package services
import ( import (
"context" "context"
"fmt"
"github.com/coinbase/rosetta-sdk-go/types" "github.com/coinbase/rosetta-sdk-go/types"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -27,6 +28,11 @@ func (s *ConstructAPI) ConstructionHash(
"message": "nil transaction", "message": "nil transaction",
}) })
} }
if tx.ShardID() != s.hmy.ShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("transaction is for shard %v != shard %v", tx.ShardID(), s.hmy.ShardID),
})
}
return &types.TransactionIdentifierResponse{ return &types.TransactionIdentifierResponse{
TransactionIdentifier: &types.TransactionIdentifier{Hash: tx.Hash().String()}, TransactionIdentifier: &types.TransactionIdentifier{Hash: tx.Hash().String()},
}, nil }, nil
@ -48,6 +54,11 @@ func (s *ConstructAPI) ConstructionSubmit(
"message": "nil wrapped transaction or nil unwrapped transaction", "message": "nil wrapped transaction or nil unwrapped transaction",
}) })
} }
if tx.ShardID() != s.hmy.ShardID {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": fmt.Sprintf("transaction is for shard %v != shard %v", tx.ShardID(), s.hmy.ShardID),
})
}
wrappedSenderAddress, err := getAddress(wrappedTransaction.From) wrappedSenderAddress, err := getAddress(wrappedTransaction.From)
if err != nil { if err != nil {

@ -57,7 +57,7 @@ func ConstructTransaction(
var tx hmyTypes.PoolTransaction var tx hmyTypes.PoolTransaction
switch components.Type { switch components.Type {
case common.CrossShardTransferNativeOperation: case common.NativeCrossShardTransferOperation:
if tx, rosettaError = constructCrossShardTransaction(components, metadata, sourceShardID); rosettaError != nil { if tx, rosettaError = constructCrossShardTransaction(components, metadata, sourceShardID); rosettaError != nil {
return nil, rosettaError return nil, rosettaError
} }
@ -65,7 +65,7 @@ func ConstructTransaction(
if tx, rosettaError = constructContractCreationTransaction(components, metadata, sourceShardID); rosettaError != nil { if tx, rosettaError = constructContractCreationTransaction(components, metadata, sourceShardID); rosettaError != nil {
return nil, rosettaError return nil, rosettaError
} }
case common.TransferNativeOperation: case common.NativeTransferOperation:
if tx, rosettaError = constructPlainTransaction(components, metadata, sourceShardID); rosettaError != nil { if tx, rosettaError = constructPlainTransaction(components, metadata, sourceShardID); rosettaError != nil {
return nil, rosettaError return nil, rosettaError
} }

@ -27,7 +27,7 @@ func TestConstructPlainTransaction(t *testing.T) {
refDataBytes := []byte{0xEE, 0xEE, 0xEE} refDataBytes := []byte{0xEE, 0xEE, 0xEE}
refData := hexutil.Encode(refDataBytes) refData := hexutil.Encode(refDataBytes)
refComponents := &OperationComponents{ refComponents := &OperationComponents{
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
From: refFrom, From: refFrom,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -116,7 +116,7 @@ func TestConstructPlainTransaction(t *testing.T) {
// test invalid receiver // test invalid receiver
_, rosettaError = constructPlainTransaction(&OperationComponents{ _, rosettaError = constructPlainTransaction(&OperationComponents{
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
From: refFrom, From: refFrom,
To: nil, To: nil,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -126,7 +126,7 @@ func TestConstructPlainTransaction(t *testing.T) {
t.Error("expected error") t.Error("expected error")
} }
_, rosettaError = constructPlainTransaction(&OperationComponents{ _, rosettaError = constructPlainTransaction(&OperationComponents{
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
From: refFrom, From: refFrom,
To: &types.AccountIdentifier{ To: &types.AccountIdentifier{
Address: "", Address: "",
@ -140,7 +140,7 @@ func TestConstructPlainTransaction(t *testing.T) {
// test valid nil sender // test valid nil sender
_, rosettaError = constructPlainTransaction(&OperationComponents{ _, rosettaError = constructPlainTransaction(&OperationComponents{
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
From: nil, From: nil,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -179,7 +179,7 @@ func TestConstructCrossShardTransaction(t *testing.T) {
refDataBytes := []byte{0xEE, 0xEE, 0xEE} refDataBytes := []byte{0xEE, 0xEE, 0xEE}
refData := hexutil.Encode(refDataBytes) refData := hexutil.Encode(refDataBytes)
refComponents := &OperationComponents{ refComponents := &OperationComponents{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
From: refFrom, From: refFrom,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -238,7 +238,7 @@ func TestConstructCrossShardTransaction(t *testing.T) {
// test invalid receiver // test invalid receiver
_, rosettaError = constructCrossShardTransaction(&OperationComponents{ _, rosettaError = constructCrossShardTransaction(&OperationComponents{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
From: refFrom, From: refFrom,
To: nil, To: nil,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -248,7 +248,7 @@ func TestConstructCrossShardTransaction(t *testing.T) {
t.Error("expected error") t.Error("expected error")
} }
_, rosettaError = constructCrossShardTransaction(&OperationComponents{ _, rosettaError = constructCrossShardTransaction(&OperationComponents{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
From: refFrom, From: refFrom,
To: &types.AccountIdentifier{ To: &types.AccountIdentifier{
Address: "", Address: "",
@ -262,7 +262,7 @@ func TestConstructCrossShardTransaction(t *testing.T) {
// test valid nil sender // test valid nil sender
_, rosettaError = constructCrossShardTransaction(&OperationComponents{ _, rosettaError = constructCrossShardTransaction(&OperationComponents{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
From: nil, From: nil,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -432,7 +432,7 @@ func TestConstructTransaction(t *testing.T) {
// test valid cross-shard transfer (negative test cases are in TestConstructCrossShardTransaction) // test valid cross-shard transfer (negative test cases are in TestConstructCrossShardTransaction)
generalTx, rosettaError := ConstructTransaction(&OperationComponents{ generalTx, rosettaError := ConstructTransaction(&OperationComponents{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
From: refFrom, From: refFrom,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -485,7 +485,7 @@ func TestConstructTransaction(t *testing.T) {
// test valid transfer (negative test cases are in TestConstructPlainTransaction) // test valid transfer (negative test cases are in TestConstructPlainTransaction)
generalTx, rosettaError = ConstructTransaction(&OperationComponents{ generalTx, rosettaError = ConstructTransaction(&OperationComponents{
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
From: refFrom, From: refFrom,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),
@ -512,7 +512,7 @@ func TestConstructTransaction(t *testing.T) {
// test invalid sender shard // test invalid sender shard
badShard := refShard + refToShard + 1 badShard := refShard + refToShard + 1
_, rosettaError = ConstructTransaction(&OperationComponents{ _, rosettaError = ConstructTransaction(&OperationComponents{
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
From: refFrom, From: refFrom,
To: refTo, To: refTo,
Amount: big.NewInt(12000), Amount: big.NewInt(12000),

@ -137,7 +137,7 @@ func FormatCrossShardReceiverTransaction(
OperationIdentifier: &types.OperationIdentifier{ OperationIdentifier: &types.OperationIdentifier{
Index: 0, // There is no gas expenditure for cross-shard transaction payout Index: 0, // There is no gas expenditure for cross-shard transaction payout
}, },
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Status: common.SuccessOperationStatus.Status, Status: common.SuccessOperationStatus.Status,
Account: receiverAccountID, Account: receiverAccountID,
Amount: &types.Amount{ Amount: &types.Amount{

@ -152,7 +152,7 @@ func testFormatPlainTransaction(
if rosettaTx.Operations[0].Type != common.ExpendGasOperation { if rosettaTx.Operations[0].Type != common.ExpendGasOperation {
t.Error("Expected 1st operation to be gas") t.Error("Expected 1st operation to be gas")
} }
if rosettaTx.Operations[1].Type != common.TransferNativeOperation { if rosettaTx.Operations[1].Type != common.NativeTransferOperation {
t.Error("Expected 2nd operation to transfer related") t.Error("Expected 2nd operation to transfer related")
} }
if rosettaTx.Operations[1].Metadata != nil { if rosettaTx.Operations[1].Metadata != nil {
@ -340,7 +340,7 @@ func testFormatCrossShardSenderTransaction(
if rosettaTx.Operations[0].Type != common.ExpendGasOperation { if rosettaTx.Operations[0].Type != common.ExpendGasOperation {
t.Error("Expected 1st operation to be gas") t.Error("Expected 1st operation to be gas")
} }
if rosettaTx.Operations[1].Type != common.CrossShardTransferNativeOperation { if rosettaTx.Operations[1].Type != common.NativeCrossShardTransferOperation {
t.Error("Expected 2nd operation to cross-shard transfer related") t.Error("Expected 2nd operation to cross-shard transfer related")
} }
if reflect.DeepEqual(rosettaTx.Operations[1].Metadata, map[string]interface{}{}) { if reflect.DeepEqual(rosettaTx.Operations[1].Metadata, map[string]interface{}{}) {
@ -396,7 +396,7 @@ func TestFormatCrossShardReceiverTransaction(t *testing.T) {
OperationIdentifier: &types.OperationIdentifier{ OperationIdentifier: &types.OperationIdentifier{
Index: 0, // There is no gas expenditure for cross-shard payout Index: 0, // There is no gas expenditure for cross-shard payout
}, },
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Status: common.SuccessOperationStatus.Status, Status: common.SuccessOperationStatus.Status,
Account: receiverAccID, Account: receiverAccID,
Amount: &types.Amount{ Amount: &types.Amount{

@ -210,7 +210,7 @@ func newTransferNativeOperations(
receiverAddress := *tx.To() receiverAddress := *tx.To()
// Common elements // Common elements
opType := common.TransferNativeOperation opType := common.NativeTransferOperation
opStatus := common.SuccessOperationStatus.Status opStatus := common.SuccessOperationStatus.Status
if receipt.Status == hmytypes.ReceiptStatusFailed { if receipt.Status == hmytypes.ReceiptStatusFailed {
if len(tx.Data()) > 0 { if len(tx.Data()) > 0 {
@ -309,7 +309,7 @@ func newCrossShardSenderTransferNativeOperations(
RelatedOperations: []*types.OperationIdentifier{ RelatedOperations: []*types.OperationIdentifier{
startingOperationID, startingOperationID,
}, },
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Status: common.SuccessOperationStatus.Status, Status: common.SuccessOperationStatus.Status,
Account: senderAccountID, Account: senderAccountID,
Amount: &types.Amount{ Amount: &types.Amount{

@ -57,7 +57,7 @@ func GetOperationComponents(
return getTransferOperationComponents(operations) return getTransferOperationComponents(operations)
} }
switch operations[0].Type { switch operations[0].Type {
case common.CrossShardTransferNativeOperation: case common.NativeCrossShardTransferOperation:
return getCrossShardOperationComponents(operations[0]) return getCrossShardOperationComponents(operations[0])
case common.ContractCreationOperation: case common.ContractCreationOperation:
return getContractCreationOperationComponents(operations[0]) return getContractCreationOperationComponents(operations[0])
@ -78,7 +78,7 @@ func getTransferOperationComponents(
}) })
} }
op0, op1 := operations[0], operations[1] op0, op1 := operations[0], operations[1]
if op0.Type != common.TransferNativeOperation || op1.Type != common.TransferNativeOperation { if op0.Type != common.NativeTransferOperation || op1.Type != common.NativeTransferOperation {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "invalid operation type(s) for same shard transfer", "message": "invalid operation type(s) for same shard transfer",
}) })
@ -187,7 +187,7 @@ func getCrossShardOperationComponents(
"message": "operation must have account sender/from & receiver/to identifiers for cross shard transfer", "message": "operation must have account sender/from & receiver/to identifiers for cross shard transfer",
}) })
} }
if types.Hash(operation.Account) != types.Hash(components.From) { if operation.Account.Address != components.From.Address {
return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{ return nil, common.NewError(common.InvalidTransactionConstructionError, map[string]interface{}{
"message": "operation account identifier does not match sender/from identifiers for cross shard transfer", "message": "operation account identifier does not match sender/from identifiers for cross shard transfer",
}) })

@ -124,7 +124,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
// test valid operations // test valid operations
refOperation := &types.Operation{ refOperation := &types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: refAmount, Amount: refAmount,
Account: refFrom, Account: refFrom,
Metadata: refMetadataMap, Metadata: refMetadataMap,
@ -148,7 +148,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
// test nil amount // test nil amount
_, rosettaError = getCrossShardOperationComponents(&types.Operation{ _, rosettaError = getCrossShardOperationComponents(&types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: nil, Amount: nil,
Account: refFrom, Account: refFrom,
Metadata: refMetadataMap, Metadata: refMetadataMap,
@ -159,7 +159,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
// test positive amount // test positive amount
_, rosettaError = getCrossShardOperationComponents(&types.Operation{ _, rosettaError = getCrossShardOperationComponents(&types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: &types.Amount{ Amount: &types.Amount{
Value: "12000", Value: "12000",
Currency: &common.NativeCurrency, Currency: &common.NativeCurrency,
@ -173,7 +173,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
// test different/unsupported currency // test different/unsupported currency
_, rosettaError = getCrossShardOperationComponents(&types.Operation{ _, rosettaError = getCrossShardOperationComponents(&types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: &types.Amount{ Amount: &types.Amount{
Value: "-12000", Value: "-12000",
Currency: &types.Currency{ Currency: &types.Currency{
@ -190,7 +190,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
// test nil account // test nil account
_, rosettaError = getCrossShardOperationComponents(&types.Operation{ _, rosettaError = getCrossShardOperationComponents(&types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: refAmount, Amount: refAmount,
Account: nil, Account: nil,
Metadata: refMetadataMap, Metadata: refMetadataMap,
@ -201,7 +201,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
// test no metadata // test no metadata
_, rosettaError = getCrossShardOperationComponents(&types.Operation{ _, rosettaError = getCrossShardOperationComponents(&types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: refAmount, Amount: refAmount,
Account: refFrom, Account: refFrom,
}) })
@ -224,7 +224,7 @@ func TestGetCrossShardOperationComponents(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
_, rosettaError = getCrossShardOperationComponents(&types.Operation{ _, rosettaError = getCrossShardOperationComponents(&types.Operation{
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: refAmount, Amount: refAmount,
Account: refFrom, Account: refFrom,
Metadata: badMetadataMap, Metadata: badMetadataMap,
@ -266,7 +266,7 @@ func TestGetTransferOperationComponents(t *testing.T) {
OperationIdentifier: &types.OperationIdentifier{ OperationIdentifier: &types.OperationIdentifier{
Index: 0, Index: 0,
}, },
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
Amount: refFromAmount, Amount: refFromAmount,
Account: refFrom, Account: refFrom,
}, },
@ -279,7 +279,7 @@ func TestGetTransferOperationComponents(t *testing.T) {
Index: 0, Index: 0,
}, },
}, },
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
Amount: refToAmount, Amount: refToAmount,
Account: refTo, Account: refTo,
}, },
@ -345,20 +345,20 @@ func TestGetTransferOperationComponents(t *testing.T) {
// test invalid operation // test invalid operation
refOperations[0].Type = common.ExpendGasOperation refOperations[0].Type = common.ExpendGasOperation
refOperations[1].Type = common.TransferNativeOperation refOperations[1].Type = common.NativeTransferOperation
_, rosettaError = getTransferOperationComponents(refOperations) _, rosettaError = getTransferOperationComponents(refOperations)
if rosettaError == nil { if rosettaError == nil {
t.Error("expected error") t.Error("expected error")
} }
// test invalid operation sender // test invalid operation sender
refOperations[0].Type = common.TransferNativeOperation refOperations[0].Type = common.NativeTransferOperation
refOperations[1].Type = common.ExpendGasOperation refOperations[1].Type = common.ExpendGasOperation
_, rosettaError = getTransferOperationComponents(refOperations) _, rosettaError = getTransferOperationComponents(refOperations)
if rosettaError == nil { if rosettaError == nil {
t.Error("expected error") t.Error("expected error")
} }
refOperations[1].Type = common.TransferNativeOperation refOperations[1].Type = common.NativeTransferOperation
// test nil amount // test nil amount
refOperations[0].Amount = nil refOperations[0].Amount = nil
@ -517,7 +517,7 @@ func TestGetOperationComponents(t *testing.T) {
OperationIdentifier: &types.OperationIdentifier{ OperationIdentifier: &types.OperationIdentifier{
Index: 0, Index: 0,
}, },
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
Amount: refFromAmount, Amount: refFromAmount,
Account: refFrom, Account: refFrom,
}, },
@ -530,7 +530,7 @@ func TestGetOperationComponents(t *testing.T) {
Index: 0, Index: 0,
}, },
}, },
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
Amount: refToAmount, Amount: refToAmount,
Account: refTo, Account: refTo,
}, },
@ -551,7 +551,7 @@ func TestGetOperationComponents(t *testing.T) {
} }
_, rosettaError = GetOperationComponents([]*types.Operation{ _, rosettaError = GetOperationComponents([]*types.Operation{
{ {
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Amount: refFromAmount, Amount: refFromAmount,
Account: refFrom, Account: refFrom,
Metadata: refMetadataMap, Metadata: refMetadataMap,

@ -368,7 +368,7 @@ func TestNewTransferNativeOperations(t *testing.T) {
Index: startingOpID.Index, Index: startingOpID.Index,
}, },
}, },
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
Status: common.ContractFailureOperationStatus.Status, Status: common.ContractFailureOperationStatus.Status,
Account: senderAccID, Account: senderAccID,
Amount: &types.Amount{ Amount: &types.Amount{
@ -385,7 +385,7 @@ func TestNewTransferNativeOperations(t *testing.T) {
Index: startingOpID.Index + 1, Index: startingOpID.Index + 1,
}, },
}, },
Type: common.TransferNativeOperation, Type: common.NativeTransferOperation,
Status: common.ContractFailureOperationStatus.Status, Status: common.ContractFailureOperationStatus.Status,
Account: receiverAccID, Account: receiverAccID,
Amount: &types.Amount{ Amount: &types.Amount{
@ -461,7 +461,7 @@ func TestNewCrossShardSenderTransferNativeOperations(t *testing.T) {
RelatedOperations: []*types.OperationIdentifier{ RelatedOperations: []*types.OperationIdentifier{
startingOpID, startingOpID,
}, },
Type: common.CrossShardTransferNativeOperation, Type: common.NativeCrossShardTransferOperation,
Status: common.SuccessOperationStatus.Status, Status: common.SuccessOperationStatus.Status,
Account: senderAccID, Account: senderAccID,
Amount: &types.Amount{ Amount: &types.Amount{

Loading…
Cancel
Save