-
Notifications
You must be signed in to change notification settings - Fork 223
Tests/gossip #515
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
base: develop
Are you sure you want to change the base?
Tests/gossip #515
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package emitter | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/Fantom-foundation/lachesis-base/emitter/ancestor" | ||
| "github.com/Fantom-foundation/lachesis-base/hash" | ||
| "github.com/Fantom-foundation/lachesis-base/inter/idx" | ||
| "github.com/Fantom-foundation/lachesis-base/inter/pos" | ||
| "github.com/Fantom-foundation/lachesis-base/kvdb/memorydb" | ||
| "github.com/golang/mock/gomock" | ||
|
|
||
| "github.com/Fantom-foundation/go-opera/gossip/emitter/mock" | ||
| "github.com/Fantom-foundation/go-opera/integration/makefakegenesis" | ||
| "github.com/Fantom-foundation/go-opera/inter" | ||
| "github.com/Fantom-foundation/go-opera/opera" | ||
| "github.com/Fantom-foundation/go-opera/vecmt" | ||
| ) | ||
|
|
||
| func TestParents(t *testing.T) { | ||
| cfg := DefaultConfig() | ||
| gValidators := makefakegenesis.GetFakeValidators(3) | ||
| vv := pos.NewBuilder() | ||
| for _, v := range gValidators { | ||
| vv.Set(v.ID, pos.Weight(1)) | ||
| } | ||
| validators := vv.Build() | ||
| cfg.Validator.ID = gValidators[0].ID | ||
|
|
||
| ctrl := gomock.NewController(t) | ||
| external := mock.NewMockExternal(ctrl) | ||
| txPool := mock.NewMockTxPool(ctrl) | ||
| signer := mock.NewMockSigner(ctrl) | ||
| txSigner := mock.NewMockTxSigner(ctrl) | ||
|
|
||
| external.EXPECT().Lock(). | ||
| AnyTimes() | ||
| external.EXPECT().Unlock(). | ||
| AnyTimes() | ||
| external.EXPECT().DagIndex(). | ||
| Return(func() *vecmt.Index { | ||
| vi := vecmt.NewIndex(func(err error) { panic(err) }, vecmt.LiteConfig()) | ||
| vi.Reset(validators, memorydb.New(), nil) | ||
| return vi | ||
| }()). | ||
| AnyTimes() | ||
| external.EXPECT().IsSynced(). | ||
| Return(true). | ||
| AnyTimes() | ||
| external.EXPECT().PeersNum(). | ||
| Return(int(3)). | ||
| AnyTimes() | ||
| external.EXPECT().StateDB(). | ||
| Return(nil). | ||
| AnyTimes() | ||
|
|
||
| em := NewEmitter(cfg, World{ | ||
| External: external, | ||
| TxPool: txPool, | ||
| Signer: signer, | ||
| TxSigner: txSigner, | ||
| }) | ||
|
|
||
| t.Run("init", func(t *testing.T) { | ||
| external.EXPECT().GetRules(). | ||
| Return(opera.FakeNetRules()). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetEpochValidators(). | ||
| Return(validators, idx.Epoch(1)). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetLastEvent(idx.Epoch(1), cfg.Validator.ID). | ||
| Return((*hash.Event)(nil)). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetLastEvent(idx.Epoch(2), cfg.Validator.ID). | ||
| Return(new(hash.Event)). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetLastEvent(idx.Epoch(2), gValidators[1].ID). | ||
| Return((*hash.Event)(nil)). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetHeads(idx.Epoch(1)). | ||
| Return(hash.Events{}). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetHeads(idx.Epoch(2)). | ||
| Return(hash.Events{}). | ||
| AnyTimes() | ||
|
|
||
| external.EXPECT().GetGenesisTime(). | ||
| Return(inter.Timestamp(uint64(time.Now().UnixNano()))). | ||
| AnyTimes() | ||
|
|
||
| em.init() | ||
| }) | ||
|
|
||
| t.Run("build strategies 0 events", func(t *testing.T) { | ||
| em.buildSearchStrategies(idx.Event(0)) | ||
| }) | ||
|
|
||
| t.Run("build strategies 1 event", func(t *testing.T) { | ||
| em.buildSearchStrategies(idx.Event(1)) | ||
| }) | ||
|
|
||
| t.Run("build strategies 4 event", func(t *testing.T) { | ||
| em.buildSearchStrategies(idx.Event(4)) | ||
| }) | ||
|
|
||
| t.Run("build strategies with fcIndexer", func(t *testing.T) { | ||
| gValidator := makefakegenesis.GetFakeValidators(1) | ||
| vvNew := pos.NewBuilder() | ||
| vvNew.Set(gValidator[0].ID, pos.Weight(1)) | ||
| newValidators := vvNew.Build() | ||
|
|
||
| em.quorumIndexer = nil | ||
| em.fcIndexer = ancestor.NewFCIndexer(newValidators, em.world.DagIndex(), em.config.Validator.ID) | ||
|
|
||
| em.buildSearchStrategies(idx.Event(4)) | ||
| }) | ||
|
|
||
| t.Run("choose parent not selfParent", func(t *testing.T) { | ||
| em.chooseParents(idx.Epoch(1), em.config.Validator.ID) | ||
|
||
| }) | ||
|
|
||
| t.Run("choose parent selfParent", func(t *testing.T) { | ||
| em.chooseParents(idx.Epoch(2), em.config.Validator.ID) | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| package evmstore | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/stretchr/testify/assert" | ||
|
||
|
|
||
| "github.com/Fantom-foundation/lachesis-base/kvdb/memorydb" | ||
| ) | ||
|
|
||
|
|
@@ -15,3 +20,14 @@ func nonCachedStore() *Store { | |
|
|
||
| return NewStore(memorydb.NewProducer(""), cfg) | ||
| } | ||
|
|
||
| func TestStoreSetTx(t *testing.T) { | ||
| store := cachedStore() | ||
|
|
||
| tx := types.NewTx(&types.LegacyTx{Data: []byte("test")}) | ||
|
|
||
| store.SetTx(tx.Hash(), tx) | ||
|
|
||
| txFromStore := store.GetTx(tx.Hash()) | ||
| assert.Equal(t, tx.Data(), txFromStore.Data()) | ||
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if the returned value is equal to expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done