Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano committed May 3, 2024
1 parent 2f4d808 commit acaf83c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client_online.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (c *Client) blockTxs(ctx context.Context, height *int64) (crgtypes.BlockTra
return crgtypes.BlockTransactionsResponse{}, crgerrs.WrapError(crgerrs.ErrOnlineClient, "block results transactions do now match block transactions")
}
// process begin and end block txs
FinalizeBlockTx := &rosettatypes.Transaction{
finalizeBlockTx := &rosettatypes.Transaction{
TransactionIdentifier: &rosettatypes.TransactionIdentifier{Hash: c.converter.ToRosetta().FinalizeBlockTxHash(blockInfo.BlockID.Hash)},
Operations: AddOperationIndexes(
nil,
Expand All @@ -516,7 +516,7 @@ func (c *Client) blockTxs(ctx context.Context, height *int64) (crgtypes.BlockTra

finalTxs := make([]*rosettatypes.Transaction, 0, 1+len(deliverTx))
finalTxs = append(finalTxs, deliverTx...)
finalTxs = append(finalTxs, FinalizeBlockTx)
finalTxs = append(finalTxs, finalizeBlockTx)

return crgtypes.BlockTransactionsResponse{
BlockResponse: c.converter.ToRosetta().BlockResponse(blockInfo),
Expand Down
4 changes: 2 additions & 2 deletions converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ func AddOperationIndexes(msgOps, balanceOps []*rosettatypes.Operation) (finalOps
}

// FinalizeBlockTxHash produces a mock beginblock hash that rosetta can query
// for beginblock operations, it also serves the purpose of representing
// part of the state changes happening at beginblock level (balance ones)
// for finalizeBlock operations, it also serves the purpose of representing
// part of the state changes happening at finalizeblock level (balance ones)
func (c converter) FinalizeBlockTxHash(hash []byte) string {
final := append([]byte{FinalizeBlockHashStart}, hash...)
return fmt.Sprintf("%X", final)
Expand Down
8 changes: 4 additions & 4 deletions converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,23 @@ func (s *ConverterTestSuite) TestOpsAndSigners() {
})
}

func (s *ConverterTestSuite) TestBeginEndBlockAndHashToTxType() {
func (s *ConverterTestSuite) TestFinalizeBlockHashToTxType() {
const deliverTxHex = "5229A67AA008B5C5F1A0AEA77D4DEBE146297A30AAEF01777AF10FAD62DD36AB"

deliverTxBytes, err := hex.DecodeString(deliverTxHex)
s.Require().NoError(err)

endBlockTxHex := s.c.ToRosetta().FinalizeBlockTxHash(deliverTxBytes)
finalizeBlockTxHex := s.c.ToRosetta().FinalizeBlockTxHash(deliverTxBytes)

txType, hash := s.c.ToSDK().HashToTxType(deliverTxBytes)

s.Require().Equal(rosetta.DeliverTxTx, txType)
s.Require().Equal(deliverTxBytes, hash, "deliver tx hash should not change")

endBlockTxBytes, err := hex.DecodeString(endBlockTxHex)
finalizeBlockTxBytes, err := hex.DecodeString(finalizeBlockTxHex)
s.Require().NoError(err)

txType, hash = s.c.ToSDK().HashToTxType(endBlockTxBytes)
txType, hash = s.c.ToSDK().HashToTxType(finalizeBlockTxBytes)
s.Require().Equal(rosetta.FinalizeBlockTx, txType)
s.Require().Equal(deliverTxBytes, hash, "end block tx hash should be equal to a block hash")

Expand Down

0 comments on commit acaf83c

Please sign in to comment.