mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 09:14:28 +00:00
96401e734e
* Implement `bls_to_execution_change` API event (cherry picked from commit 1c8a2c580b3664e1238380138dc65c30e238cb11) (cherry picked from commit aabcaac6191cb25048be301ab62e8b391f561d6f) * missing event code (cherry picked from commit daa4fd2b72aeaff16196faa46dca6efd289d9934) * Update beacon-chain/core/feed/operation/events.go Co-authored-by: Nishant Das <nishdas93@gmail.com>
105 lines
3.7 KiB
Go
105 lines
3.7 KiB
Go
package sync
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/encoder"
|
|
"github.com/prysmaticlabs/prysm/v3/network/forks"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
)
|
|
|
|
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{}))
|
|
|
|
digest, err := forks.CreateForkDigest(time.Now(), make([]byte, 32))
|
|
assert.NoError(t, err)
|
|
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()))
|
|
}
|