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

Added additional fields for revert event #95

Merged
merged 1 commit into from
May 28, 2024
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
10 changes: 6 additions & 4 deletions data/outport.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ type BlockEvents struct {

// RevertBlock holds revert event data
type RevertBlock struct {
Hash string `json:"hash"`
Nonce uint64 `json:"nonce"`
Round uint64 `json:"round"`
Epoch uint32 `json:"epoch"`
Hash string `json:"hash"`
Nonce uint64 `json:"nonce"`
Round uint64 `json:"round"`
Epoch uint32 `json:"epoch"`
ShardID uint32 `json:"shardId"`
TimeStamp uint64 `json:"timestamp"`
}

// FinalizedBlock holds finalized block data
Expand Down
10 changes: 6 additions & 4 deletions process/preprocess/eventsPreProcessorV1.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ func (d *eventsPreProcessorV1) RevertIndexedBlock(marshalledData []byte) error {
}

revertData := &data.RevertBlock{
Hash: hex.EncodeToString(blockData.GetHeaderHash()),
Nonce: header.GetNonce(),
Round: header.GetRound(),
Epoch: header.GetEpoch(),
Hash: hex.EncodeToString(blockData.GetHeaderHash()),
Nonce: header.GetNonce(),
Round: header.GetRound(),
Epoch: header.GetEpoch(),
ShardID: blockData.GetShardID(),
TimeStamp: header.GetTimeStamp(),
}

d.facade.HandleRevertEvents(*revertData)
Expand Down
38 changes: 36 additions & 2 deletions process/preprocess/eventsPreProcessorV1_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package preprocess_test

import (
"encoding/hex"
"encoding/json"
"errors"
"testing"
Expand Down Expand Up @@ -138,22 +139,55 @@ func TestPreProcessorV1_RevertIndexerBlock(t *testing.T) {
t.Run("should work", func(t *testing.T) {
t.Parallel()

shardID := uint32(2)
nonce := uint64(11)
round := uint64(12)
epoch := uint32(3)
timestamp := uint64(1234)
headerHash := []byte("headerHash1")

b := &block.Header{
Nonce: 1,
Nonce: nonce,
Round: round,
Epoch: epoch,
TimeStamp: timestamp,
}
blockBytes, _ := json.Marshal(b)

blockData := &outport.BlockData{
HeaderBytes: blockBytes,
HeaderHash: headerHash,
HeaderType: "Header",
ShardID: shardID,
}

dp, err := preprocess.NewEventsPreProcessorV1(createMockEventsDataPreProcessorArgs())
expRevertBlock := data.RevertBlock{
Hash: hex.EncodeToString(headerHash),
Nonce: nonce,
Round: round,
Epoch: epoch,
ShardID: shardID,
TimeStamp: timestamp,
}

args := createMockEventsDataPreProcessorArgs()

revertCalled := false
args.Facade = &mocks.FacadeStub{
HandleRevertEventsCalled: func(events data.RevertBlock) {
revertCalled = true
require.Equal(t, expRevertBlock, events)
},
}

dp, err := preprocess.NewEventsPreProcessorV1(args)
require.Nil(t, err)

marshalledBlock, _ := json.Marshal(blockData)
err = dp.RevertIndexedBlock(marshalledBlock)
require.Nil(t, err)

require.True(t, revertCalled)
})
}

Expand Down
Loading