mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* overhaul fork schedule management for bpos * Unify log * Radek's comments * Use arg config to determine previous epoch, with regression test * Remove unnecessary NewClock. @potuz feedback * Continuation of previous commit: Remove unnecessary NewClock. @potuz feedback * Remove VerifyBlockHeaderSignatureUsingCurrentFork * cosmetic changes * Remove unnecessary copy. entryWithForkDigest passes by value, not by pointer so it shold be fine * Reuse ErrInvalidTopic from p2p package * Unskip TestServer_GetBeaconConfig * Resolve TODO about forkwatcher in local mode * remove Copy() --------- Co-authored-by: Kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: rkapka <radoslaw.kapka@gmail.com> Co-authored-by: Preston Van Loon <preston@pvl.dev>
106 lines
3.8 KiB
Go
106 lines
3.8 KiB
Go
package sync
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/p2p"
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/p2p/encoder"
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/startup"
|
|
"github.com/OffchainLabs/prysm/v6/config/params"
|
|
"github.com/OffchainLabs/prysm/v6/testing/assert"
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
)
|
|
|
|
func TestSubTopicHandler_CRUD(t *testing.T) {
|
|
h := newSubTopicHandler()
|
|
// Non-existent topic
|
|
assert.Equal(t, false, h.topicExists("junk"))
|
|
assert.Equal(t, false, h.digestExists([4]byte{}))
|
|
|
|
clock := startup.NewClock(time.Now(), [32]byte{})
|
|
digest := params.ForkDigest(clock.CurrentEpoch())
|
|
enc := encoder.SszNetworkEncoder{}
|
|
|
|
// Valid topic added in.
|
|
topic := fmt.Sprintf(p2p.BlockSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
assert.Equal(t, true, h.digestExists(digest))
|
|
assert.Equal(t, 1, len(h.allTopics()))
|
|
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
assert.Equal(t, false, h.digestExists(digest))
|
|
assert.Equal(t, 0, len(h.allTopics()))
|
|
|
|
h = newSubTopicHandler()
|
|
// Multiple Topics added in.
|
|
topic = fmt.Sprintf(p2p.BlockSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.ExitSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.ProposerSlashingSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.AttesterSlashingSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.AggregateAndProofSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.SyncContributionAndProofSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.BlsToExecutionChangeSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.addTopic(topic, new(pubsub.Subscription))
|
|
assert.Equal(t, true, h.topicExists(topic))
|
|
|
|
assert.Equal(t, 7, len(h.allTopics()))
|
|
|
|
// Remove multiple topics
|
|
topic = fmt.Sprintf(p2p.AttesterSlashingSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.ExitSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.ProposerSlashingSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
assert.Equal(t, true, h.digestExists(digest))
|
|
assert.Equal(t, 4, len(h.allTopics()))
|
|
|
|
// Remove remaining topics.
|
|
topic = fmt.Sprintf(p2p.BlockSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.AggregateAndProofSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.SyncContributionAndProofSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
topic = fmt.Sprintf(p2p.BlsToExecutionChangeSubnetTopicFormat, digest) + enc.ProtocolSuffix()
|
|
h.removeTopic(topic)
|
|
assert.Equal(t, false, h.topicExists(topic))
|
|
|
|
assert.Equal(t, false, h.digestExists(digest))
|
|
assert.Equal(t, 0, len(h.allTopics()))
|
|
}
|