fix protocol tests

pull/4351/head
“GheisMohammadi” 2 years ago committed by Casey Gardiner
parent da83110429
commit eb15d13842
  1. 3
      api/service/stagedstreamsync/downloader.go
  2. 4
      api/service/stagedstreamsync/staged_stream_sync.go
  3. 2
      p2p/stream/common/streammanager/interface_test.go
  4. 2
      p2p/stream/common/streammanager/streammanager_test.go
  5. 12
      p2p/stream/protocols/sync/protocol_test.go
  6. 6
      p2p/stream/types/utils.go

@ -32,7 +32,7 @@ type (
downloadC chan struct{} downloadC chan struct{}
closeC chan struct{} closeC chan struct{}
ctx context.Context ctx context.Context
cancel func() cancel context.CancelFunc
config Config config Config
logger zerolog.Logger logger zerolog.Logger
@ -70,6 +70,7 @@ func NewDownloader(host p2p.Host, bc core.BlockChain, config Config) *Downloader
//TODO: use mem db should be in config file //TODO: use mem db should be in config file
stagedSyncInstance, err := CreateStagedSync(ctx, bc, false, sp, config, logger, config.LogProgress) stagedSyncInstance, err := CreateStagedSync(ctx, bc, false, sp, config, logger, config.LogProgress)
if err != nil { if err != nil {
cancel()
return nil return nil
} }

@ -65,7 +65,7 @@ type StagedStreamSync struct {
inserted int inserted int
config Config config Config
logger zerolog.Logger logger zerolog.Logger
status status //TODO: merge this with currentSyncCycle status *status //TODO: merge this with currentSyncCycle
initSync bool // if sets to true, node start long range syncing initSync bool // if sets to true, node start long range syncing
UseMemDB bool UseMemDB bool
@ -294,7 +294,7 @@ func New(ctx context.Context,
db: db, db: db,
protocol: protocol, protocol: protocol,
gbm: nil, gbm: nil,
status: status, status: &status,
inserted: 0, inserted: 0,
config: config, config: config,
logger: logger, logger: logger,

@ -17,7 +17,7 @@ var _ StreamManager = &streamManager{}
var ( var (
myPeerID = makePeerID(0) myPeerID = makePeerID(0)
testProtoID = sttypes.ProtoID("harmony/sync/unitest/0/1.0.0") testProtoID = sttypes.ProtoID("harmony/sync/unitest/0/1.0.0/1")
) )
const ( const (

@ -209,7 +209,7 @@ func TestStreamSet_numStreamsWithMinProtoID(t *testing.T) {
pid1 = testProtoID pid1 = testProtoID
numPid1 = 5 numPid1 = 5
pid2 = sttypes.ProtoID("harmony/sync/unitest/0/1.0.1") pid2 = sttypes.ProtoID("harmony/sync/unitest/0/1.0.1/1")
numPid2 = 10 numPid2 = 10
) )

@ -15,16 +15,18 @@ func TestProtocol_Match(t *testing.T) {
targetID string targetID string
exp bool exp bool
}{ }{
{"harmony/sync/unitest/0/1.0.1", true}, {"harmony/sync/unitest/0/1.0.1/1", true},
{"harmony/sync/unitest/0/1.0.1/0", true},
{"h123456", false}, {"h123456", false},
{"harmony/sync/unitest/0/0.9.9", false}, {"harmony/sync/unitest/0/0.9.9/1", false},
{"harmony/epoch/unitest/0/1.0.1", false}, {"harmony/epoch/unitest/0/1.0.1/1", false},
{"harmony/sync/mainnet/0/1.0.1", false}, {"harmony/sync/mainnet/0/1.0.1/1", false},
{"harmony/sync/unitest/1/1.0.1", false}, {"harmony/sync/unitest/1/1.0.1/1", false},
} }
for i, test := range tests { for i, test := range tests {
p := &Protocol{ p := &Protocol{
beaconNode: true,
config: Config{ config: Config{
Network: "unitest", Network: "unitest",
ShardID: 0, ShardID: 0,

@ -49,8 +49,12 @@ type ProtoSpec struct {
// ToProtoID convert a ProtoSpec to ProtoID. // ToProtoID convert a ProtoSpec to ProtoID.
func (spec ProtoSpec) ToProtoID() ProtoID { func (spec ProtoSpec) ToProtoID() ProtoID {
var versionStr string
if spec.Version != nil {
versionStr = spec.Version.String()
}
s := fmt.Sprintf(ProtoIDFormat, ProtoIDCommonPrefix, spec.Service, s := fmt.Sprintf(ProtoIDFormat, ProtoIDCommonPrefix, spec.Service,
spec.NetworkType, spec.ShardID, spec.Version.String(), bool2int(spec.BeaconNode)) spec.NetworkType, spec.ShardID, versionStr, bool2int(spec.BeaconNode))
return ProtoID(s) return ProtoID(s)
} }

Loading…
Cancel
Save