mirror of https://github.com/poanetwork/gecko.git
91 lines
2.7 KiB
Go
91 lines
2.7 KiB
Go
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package common
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/ava-labs/gecko/ids"
|
|
)
|
|
|
|
func TestRequests(t *testing.T) {
|
|
req := Requests{}
|
|
|
|
length := req.Len()
|
|
assert.Equal(t, 0, length, "should have had no outstanding requests")
|
|
|
|
_, removed := req.Remove(ids.ShortEmpty, 0)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
removed = req.RemoveAny(ids.Empty)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
constains := req.Contains(ids.Empty)
|
|
assert.False(t, constains, "shouldn't contain this request")
|
|
|
|
req.Add(ids.ShortEmpty, 0, ids.Empty)
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 1, length, "should have had one outstanding request")
|
|
|
|
_, removed = req.Remove(ids.ShortEmpty, 1)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
_, removed = req.Remove(ids.NewShortID([20]byte{1}), 0)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
constains = req.Contains(ids.Empty)
|
|
assert.True(t, constains, "should contain this request")
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 1, length, "should have had one outstanding request")
|
|
|
|
req.Add(ids.ShortEmpty, 10, ids.Empty.Prefix(0))
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 2, length, "should have had two outstanding requests")
|
|
|
|
_, removed = req.Remove(ids.ShortEmpty, 1)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
_, removed = req.Remove(ids.NewShortID([20]byte{1}), 0)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
constains = req.Contains(ids.Empty)
|
|
assert.True(t, constains, "should contain this request")
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 2, length, "should have had two outstanding requests")
|
|
|
|
removedID, removed := req.Remove(ids.ShortEmpty, 0)
|
|
assert.True(t, removedID.Equals(ids.Empty), "should have removed the requested ID")
|
|
assert.True(t, removed, "should have removed the request")
|
|
|
|
removedID, removed = req.Remove(ids.ShortEmpty, 10)
|
|
assert.True(t, removedID.Equals(ids.Empty.Prefix(0)), "should have removed the requested ID")
|
|
assert.True(t, removed, "should have removed the request")
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 0, length, "should have had no outstanding requests")
|
|
|
|
req.Add(ids.ShortEmpty, 0, ids.Empty)
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 1, length, "should have had one outstanding request")
|
|
|
|
removed = req.RemoveAny(ids.Empty)
|
|
assert.True(t, removed, "should have removed the request")
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 0, length, "should have had no outstanding requests")
|
|
|
|
removed = req.RemoveAny(ids.Empty)
|
|
assert.False(t, removed, "shouldn't have removed the request")
|
|
|
|
length = req.Len()
|
|
assert.Equal(t, 0, length, "should have had no outstanding requests")
|
|
}
|