core, tests/bor: add more tests for state-sync validation (#710)

* core: add get state sync function for tests

* tests/bor: add validation for state sync events post consensus
This commit is contained in:
Manav Darji 2023-02-02 14:21:45 +05:30 committed by GitHub
parent cbbc27c27a
commit a533ffb289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -422,6 +422,10 @@ func (bc *BlockChain) SetStateSync(stateData []*types.StateSyncData) {
bc.stateSyncData = stateData
}
func (bc *BlockChain) GetStateSync() []*types.StateSyncData {
return bc.stateSyncData
}
// SubscribeStateSyncEvent registers a subscription of StateSyncEvent.
func (bc *BlockChain) SubscribeStateSyncEvent(ch chan<- StateSyncEvent) event.Subscription {
return bc.scope.Track(bc.stateSyncFeed.Subscribe(ch))

View file

@ -7,6 +7,7 @@ import (
"context"
"crypto/ecdsa"
"encoding/hex"
"fmt"
"io"
"math/big"
"os"
@ -458,9 +459,21 @@ func TestFetchStateSyncEvents(t *testing.T) {
_bor.SetHeimdallClient(h)
block = buildNextBlock(t, _bor, chain, block, nil, init.genesis.Config.Bor, nil, res.Result.ValidatorSet.Validators)
// Validate the state sync transactions set by consensus
validateStateSyncEvents(t, eventRecords, chain.GetStateSync())
insertNewBlock(t, chain, block)
}
func validateStateSyncEvents(t *testing.T, expected []*clerk.EventRecordWithTime, got []*types.StateSyncData) {
require.Equal(t, len(expected), len(got), "number of state sync events should be equal")
for i := 0; i < len(expected); i++ {
require.Equal(t, expected[i].ID, got[i].ID, fmt.Sprintf("state sync ids should be equal - index: %d, expected: %d, got: %d", i, expected[i].ID, got[i].ID))
}
}
func TestFetchStateSyncEvents_2(t *testing.T) {
init := buildEthereumInstance(t, rawdb.NewMemoryDatabase())
chain := init.ethereum.BlockChain()

View file

@ -360,7 +360,7 @@ func generateFakeStateSyncEvents(sample *clerk.EventRecordWithTime, count int) [
*events[0] = event
for i := 1; i < count; i++ {
event.ID = uint64(i)
event.ID = uint64(i + 1)
event.Time = event.Time.Add(1 * time.Second)
events[i] = &clerk.EventRecordWithTime{}
*events[i] = event