2023-06-14 12:43:34 +00:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
2023-06-23 12:42:55 +00:00
|
|
|
"testing"
|
2023-06-14 12:43:34 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum"
|
2023-06-23 12:42:55 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
2023-06-14 12:43:34 +00:00
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
plugeth "github.com/openrelayxyz/plugeth-utils/core"
|
|
|
|
)
|
2023-06-14 12:43:34 +00:00
|
|
|
|
|
|
|
type Backend struct {
|
2023-06-23 12:42:55 +00:00
|
|
|
*MockBackend
|
|
|
|
downloader Downloader
|
2023-06-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
type Downloader struct {
|
|
|
|
ethereum.SyncProgress
|
2023-06-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
var _ plugeth.Backend = &Backend{}
|
|
|
|
var _ plugeth.Downloader = &Downloader{}
|
2023-06-14 12:43:34 +00:00
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
func NewBackend(t *testing.T, progress ethereum.SyncProgress) *Backend {
|
|
|
|
ctl := gomock.NewController(t)
|
|
|
|
dler := Downloader{progress}
|
|
|
|
ret := &Backend{
|
|
|
|
MockBackend: NewMockBackend(ctl),
|
|
|
|
downloader: dler,
|
|
|
|
}
|
2023-06-16 09:53:15 +00:00
|
|
|
ret.EXPECT().Downloader().Return(&ret.downloader).AnyTimes()
|
2023-06-23 12:42:55 +00:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Backend) SetCurrentBlock(block uint64) {
|
2023-06-16 09:53:15 +00:00
|
|
|
b.downloader.SyncProgress.CurrentBlock = block
|
2023-06-23 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d Downloader) Progress() plugeth.Progress {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d Downloader) StartingBlock() uint64 { return d.SyncProgress.StartingBlock }
|
|
|
|
func (d Downloader) CurrentBlock() uint64 { return d.SyncProgress.CurrentBlock }
|
|
|
|
func (d Downloader) HighestBlock() uint64 { return d.SyncProgress.HighestBlock }
|
|
|
|
func (d Downloader) PulledStates() uint64 { return d.SyncProgress.PulledStates }
|
|
|
|
func (d Downloader) KnownStates() uint64 { return d.SyncProgress.KnownStates }
|
|
|
|
func (d Downloader) SyncedAccounts() uint64 { return d.SyncProgress.SyncedAccounts }
|
|
|
|
func (d Downloader) SyncedAccountBytes() uint64 { return d.SyncProgress.SyncedAccountBytes }
|
|
|
|
func (d Downloader) SyncedBytecodes() uint64 { return d.SyncProgress.SyncedBytecodes }
|
|
|
|
func (d Downloader) SyncedBytecodeBytes() uint64 { return d.SyncProgress.SyncedBytecodeBytes }
|
|
|
|
func (d Downloader) SyncedStorage() uint64 { return d.SyncProgress.SyncedStorage }
|
|
|
|
func (d Downloader) SyncedStorageBytes() uint64 { return d.SyncProgress.SyncedStorageBytes }
|
|
|
|
func (d Downloader) HealedTrienodes() uint64 { return d.SyncProgress.HealedTrienodes }
|
|
|
|
func (d Downloader) HealedTrienodeBytes() uint64 { return d.SyncProgress.HealedTrienodeBytes }
|
|
|
|
func (d Downloader) HealedBytecodes() uint64 { return d.SyncProgress.HealedBytecodes }
|
|
|
|
func (d Downloader) HealedBytecodeBytes() uint64 { return d.SyncProgress.HealedBytecodeBytes }
|
|
|
|
func (d Downloader) HealingTrienodes() uint64 { return d.SyncProgress.HealingTrienodes }
|
|
|
|
func (d Downloader) HealingBytecode() uint64 { return d.SyncProgress.HealingBytecode }
|
|
|
|
|
|
|
|
func TestBackend(t *testing.T) {
|
|
|
|
b := NewBackend(t, ethereum.SyncProgress{StartingBlock: 42})
|
|
|
|
|
|
|
|
block := b.Downloader().Progress().StartingBlock()
|
|
|
|
if 42 != block {
|
|
|
|
t.Fatalf("wrong StartingBlock; expected %d, got %d", 42, block)
|
|
|
|
}
|
2023-06-14 12:43:34 +00:00
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
b.SetCurrentBlock(420)
|
2023-06-16 09:53:15 +00:00
|
|
|
block = b.Downloader().Progress().CurrentBlock()
|
2023-06-23 12:42:55 +00:00
|
|
|
if 420 != block {
|
2023-06-16 09:53:15 +00:00
|
|
|
t.Fatalf("wrong CurrentBlock; expected %d, got %d", 420, block)
|
2023-06-23 12:42:55 +00:00
|
|
|
}
|
2023-06-14 12:43:34 +00:00
|
|
|
}
|