mirror of https://github.com/status-im/go-waku.git
feat: add pubsub topic to Index pb (#200)
* feat: add pubsub topic to Index pb * fix: flaky test
This commit is contained in:
parent
2817d71fea
commit
b820d797c8
|
@ -92,13 +92,14 @@ func NewDBStore(log *zap.SugaredLogger, options ...DBOption) (*DBStore, error) {
|
|||
|
||||
func (d *DBStore) createTable() error {
|
||||
sqlStmt := `CREATE TABLE IF NOT EXISTS message (
|
||||
id BLOB PRIMARY KEY,
|
||||
id BLOB,
|
||||
receiverTimestamp INTEGER NOT NULL,
|
||||
senderTimestamp INTEGER NOT NULL,
|
||||
contentTopic BLOB NOT NULL,
|
||||
pubsubTopic BLOB NOT NULL,
|
||||
payload BLOB,
|
||||
version INTEGER NOT NULL DEFAULT 0
|
||||
version INTEGER NOT NULL DEFAULT 0,
|
||||
CONSTRAINT messageIndex PRIMARY KEY (senderTimestamp, id, pubsubTopic)
|
||||
) WITHOUT ROWID;`
|
||||
_, err := d.db.Exec(sqlStmt)
|
||||
if err != nil {
|
||||
|
|
|
@ -76,6 +76,7 @@ type Index struct {
|
|||
Digest []byte `protobuf:"bytes,1,opt,name=digest,proto3" json:"digest,omitempty"`
|
||||
ReceiverTime int64 `protobuf:"zigzag64,2,opt,name=receiverTime,proto3" json:"receiverTime,omitempty"`
|
||||
SenderTime int64 `protobuf:"zigzag64,3,opt,name=senderTime,proto3" json:"senderTime,omitempty"`
|
||||
PubsubTopic string `protobuf:"bytes,4,opt,name=pubsubTopic,proto3" json:"pubsubTopic,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -135,6 +136,13 @@ func (m *Index) GetSenderTime() int64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (m *Index) GetPubsubTopic() string {
|
||||
if m != nil {
|
||||
return m.PubsubTopic
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type PagingInfo struct {
|
||||
PageSize uint64 `protobuf:"varint,1,opt,name=pageSize,proto3" json:"pageSize,omitempty"`
|
||||
Cursor *Index `protobuf:"bytes,2,opt,name=cursor,proto3" json:"cursor,omitempty"`
|
||||
|
@ -465,41 +473,41 @@ func init() {
|
|||
func init() { proto.RegisterFile("waku_store.proto", fileDescriptor_ca6891f77a46e680) }
|
||||
|
||||
var fileDescriptor_ca6891f77a46e680 = []byte{
|
||||
// 534 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0xdf, 0x6a, 0x13, 0x4f,
|
||||
0x14, 0xc7, 0x3b, 0xf9, 0xd7, 0xec, 0x49, 0x7e, 0xe9, 0xfe, 0x8e, 0x20, 0x6b, 0xd1, 0x10, 0x17,
|
||||
0x2c, 0x01, 0x61, 0x0b, 0x29, 0x08, 0x5e, 0xa6, 0x49, 0x8b, 0x41, 0x4d, 0xea, 0xb4, 0xda, 0xcb,
|
||||
0xb0, 0xd9, 0x3d, 0x86, 0xa1, 0x76, 0x77, 0x3b, 0xb3, 0xab, 0xd6, 0x6b, 0x1f, 0xc2, 0x77, 0xf0,
|
||||
0x3d, 0xc4, 0x4b, 0xc1, 0x17, 0x90, 0xf8, 0x22, 0xb2, 0x93, 0xc9, 0x5f, 0x04, 0x2f, 0xcf, 0xf7,
|
||||
0x7c, 0x36, 0xdf, 0xef, 0x39, 0x67, 0x02, 0xf6, 0x07, 0xff, 0x2a, 0x1b, 0xab, 0x34, 0x96, 0xe4,
|
||||
0x25, 0x32, 0x4e, 0x63, 0x2c, 0x24, 0x93, 0x7d, 0xd4, 0xea, 0x35, 0x29, 0xe5, 0x4f, 0x8d, 0xee,
|
||||
0x06, 0x50, 0x1e, 0x44, 0x21, 0x7d, 0xc4, 0xbb, 0x50, 0x09, 0xc5, 0x94, 0x54, 0xea, 0xb0, 0x16,
|
||||
0x6b, 0xd7, 0xb9, 0xa9, 0xd0, 0x85, 0xba, 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 0x94, 0x53, 0x6c, 0x15, 0xdb, 0xb5, 0xce, 0xff, 0xf9, 0x30, 0x1b,
|
||||
0x09, 0xf8, 0x16, 0x88, 0x1e, 0x40, 0xb2, 0x9c, 0xd6, 0x29, 0xe9, 0x4d, 0x35, 0x36, 0x77, 0xc0,
|
||||
0xd7, 0x08, 0xbc, 0x0f, 0x96, 0x4a, 0x7d, 0x99, 0xea, 0xfb, 0x94, 0xf5, 0x7d, 0x56, 0x02, 0x3a,
|
||||
0xb0, 0x4b, 0x51, 0xa8, 0x7b, 0x15, 0xdd, 0x5b, 0x94, 0xee, 0x37, 0x06, 0x7b, 0x66, 0x2a, 0x4e,
|
||||
0x2a, 0x89, 0x23, 0x45, 0xf8, 0x18, 0xaa, 0xe6, 0x09, 0x29, 0xa7, 0xa0, 0x03, 0xef, 0xe5, 0xce,
|
||||
0x97, 0xfe, 0x55, 0xf6, 0x72, 0xae, 0xf3, 0x25, 0xb0, 0x15, 0xb4, 0xf8, 0xcf, 0xa0, 0x87, 0x50,
|
||||
0x26, 0x29, 0x63, 0xa9, 0x67, 0x6a, 0x74, 0xee, 0xe5, 0xe8, 0x56, 0x00, 0xef, 0x24, 0x07, 0xf8,
|
||||
0x9c, 0x73, 0x1f, 0x41, 0x59, 0xd7, 0x58, 0x85, 0xd2, 0x70, 0x34, 0x3c, 0xb1, 0x77, 0x10, 0xa1,
|
||||
0x31, 0x18, 0xbe, 0xe9, 0xbe, 0x18, 0xf4, 0xc7, 0xbd, 0xd7, 0xfc, 0x7c, 0xc4, 0x6d, 0xe6, 0x7e,
|
||||
0x66, 0x00, 0x8b, 0xdf, 0x39, 0xeb, 0xe1, 0x03, 0x00, 0x49, 0x37, 0x19, 0xa9, 0x74, 0x2c, 0x42,
|
||||
0x73, 0x4f, 0xcb, 0x28, 0x83, 0x10, 0x0f, 0xa0, 0x7c, 0x93, 0x1f, 0xd1, 0xbc, 0x41, 0x7b, 0x2d,
|
||||
0x85, 0x3e, 0x2e, 0x9f, 0xb7, 0xf1, 0x10, 0xaa, 0xd2, 0xa4, 0x32, 0xb3, 0xdd, 0xf9, 0x4b, 0x60,
|
||||
0xbe, 0x84, 0x8e, 0xed, 0xef, 0xb3, 0x26, 0xfb, 0x31, 0x6b, 0xb2, 0x5f, 0xb3, 0x26, 0xfb, 0xf2,
|
||||
0xbb, 0xb9, 0x33, 0xa9, 0xe8, 0xbf, 0xe1, 0xd1, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x14, 0x8f,
|
||||
0x84, 0xdf, 0xb2, 0x03, 0x00, 0x00,
|
||||
// 543 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0xdf, 0x6e, 0xd3, 0x4c,
|
||||
0x10, 0xc5, 0xbb, 0x49, 0x93, 0xc6, 0x93, 0x7c, 0xa9, 0xbf, 0x41, 0x42, 0xa6, 0x82, 0x28, 0x58,
|
||||
0xa2, 0x8a, 0x84, 0xe4, 0x4a, 0xa9, 0x84, 0xc4, 0x65, 0x9a, 0xb4, 0x22, 0x02, 0x92, 0xb2, 0x2d,
|
||||
0xf4, 0x32, 0x72, 0xec, 0x21, 0x5a, 0x95, 0xda, 0xee, 0xae, 0x0d, 0x94, 0x6b, 0x78, 0x07, 0xde,
|
||||
0x81, 0xf7, 0x40, 0x5c, 0x22, 0xf1, 0x02, 0x28, 0xbc, 0x08, 0xf2, 0x66, 0xf3, 0x17, 0x24, 0x2e,
|
||||
0xe7, 0xcc, 0x91, 0xe7, 0x77, 0x66, 0xd6, 0x60, 0xbf, 0xf3, 0x2f, 0xb3, 0x91, 0x4a, 0x63, 0x49,
|
||||
0x5e, 0x22, 0xe3, 0x34, 0xc6, 0x42, 0x32, 0xde, 0x43, 0xad, 0x5e, 0x91, 0x52, 0xfe, 0xc4, 0xe8,
|
||||
0xee, 0x27, 0x06, 0xa5, 0x7e, 0x14, 0xd2, 0x7b, 0xbc, 0x0d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xfb, 0x83, 0x41, 0xed, 0x89, 0xc8, 0x8f, 0x72, 0xf3,
|
||||
0x22, 0x23, 0x79, 0xb3, 0xb9, 0x95, 0xc2, 0x1f, 0x5b, 0xc1, 0xc7, 0x50, 0x0f, 0x56, 0xe7, 0x28,
|
||||
0xa7, 0xd8, 0x2c, 0xb6, 0xaa, 0xed, 0xff, 0xf3, 0x30, 0x6b, 0x04, 0x7c, 0xc3, 0x88, 0x1e, 0x40,
|
||||
0xb2, 0x48, 0xab, 0x37, 0x5e, 0x6d, 0xd7, 0xd7, 0x77, 0xc0, 0x57, 0x1c, 0x78, 0x17, 0x2c, 0x95,
|
||||
0xfa, 0x32, 0xd5, 0x17, 0x2c, 0xe9, 0x0b, 0x2e, 0x05, 0x74, 0x60, 0x87, 0xa2, 0x50, 0xf7, 0xca,
|
||||
0xba, 0x37, 0x2f, 0xdd, 0xaf, 0x0c, 0x76, 0x4d, 0x2a, 0x4e, 0x2a, 0x89, 0x23, 0x45, 0xf8, 0x10,
|
||||
0x2a, 0xe6, 0x95, 0x29, 0xa7, 0xa0, 0x81, 0x77, 0xf3, 0xc9, 0x17, 0xfe, 0x65, 0xf6, 0x7c, 0xa6,
|
||||
0xf3, 0x85, 0x61, 0x03, 0xb4, 0xf8, 0x4f, 0xd0, 0x03, 0x28, 0x91, 0x94, 0xb1, 0xd4, 0x99, 0xea,
|
||||
0xed, 0x3b, 0xb9, 0x75, 0x03, 0xc0, 0x3b, 0xce, 0x0d, 0x7c, 0xe6, 0x73, 0x1f, 0x40, 0x49, 0xd7,
|
||||
0x58, 0x81, 0xed, 0xc1, 0x70, 0x70, 0x6c, 0x6f, 0x21, 0x42, 0xbd, 0x3f, 0x78, 0xd5, 0x79, 0xd6,
|
||||
0xef, 0x8d, 0xba, 0x2f, 0xf9, 0xd9, 0x90, 0xdb, 0xcc, 0xfd, 0xc8, 0x00, 0xe6, 0xdf, 0x39, 0xed,
|
||||
0xe2, 0x3d, 0x00, 0x49, 0xd7, 0x19, 0xa9, 0x74, 0x24, 0x42, 0x73, 0x4f, 0xcb, 0x28, 0xfd, 0x10,
|
||||
0xf7, 0xa1, 0x74, 0x9d, 0x1f, 0xd1, 0xbc, 0x41, 0x7b, 0x85, 0x42, 0x1f, 0x97, 0xcf, 0xda, 0x78,
|
||||
0x00, 0x15, 0x69, 0xa8, 0x4c, 0xb6, 0x5b, 0x7f, 0x01, 0xe6, 0x0b, 0xd3, 0x91, 0xfd, 0x6d, 0xda,
|
||||
0x60, 0xdf, 0xa7, 0x0d, 0xf6, 0x73, 0xda, 0x60, 0x9f, 0x7f, 0x35, 0xb6, 0xc6, 0x65, 0xfd, 0xa7,
|
||||
0x1e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x33, 0xe0, 0xf4, 0x43, 0xd5, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Index) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -526,6 +534,13 @@ func (m *Index) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
i -= len(m.XXX_unrecognized)
|
||||
copy(dAtA[i:], m.XXX_unrecognized)
|
||||
}
|
||||
if len(m.PubsubTopic) > 0 {
|
||||
i -= len(m.PubsubTopic)
|
||||
copy(dAtA[i:], m.PubsubTopic)
|
||||
i = encodeVarintWakuStore(dAtA, i, uint64(len(m.PubsubTopic)))
|
||||
i--
|
||||
dAtA[i] = 0x22
|
||||
}
|
||||
if m.SenderTime != 0 {
|
||||
i = encodeVarintWakuStore(dAtA, i, uint64((uint64(m.SenderTime)<<1)^uint64((m.SenderTime>>63))))
|
||||
i--
|
||||
|
@ -842,6 +857,10 @@ func (m *Index) Size() (n int) {
|
|||
if m.SenderTime != 0 {
|
||||
n += 1 + sozWakuStore(uint64(m.SenderTime))
|
||||
}
|
||||
l = len(m.PubsubTopic)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovWakuStore(uint64(l))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
}
|
||||
|
@ -1078,6 +1097,38 @@ func (m *Index) Unmarshal(dAtA []byte) error {
|
|||
}
|
||||
v = (v >> 1) ^ uint64((int64(v&1)<<63)>>63)
|
||||
m.SenderTime = int64(v)
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PubsubTopic", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowWakuStore
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthWakuStore
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthWakuStore
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.PubsubTopic = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipWakuStore(dAtA[iNdEx:])
|
||||
|
|
|
@ -8,6 +8,7 @@ message Index {
|
|||
bytes digest = 1;
|
||||
sint64 receiverTime = 2;
|
||||
sint64 senderTime = 3;
|
||||
string pubsubTopic = 4;
|
||||
}
|
||||
|
||||
message PagingInfo {
|
||||
|
|
|
@ -2,8 +2,8 @@ package store
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
|
@ -48,11 +48,13 @@ func TestResume(t *testing.T) {
|
|||
contentTopic = "2"
|
||||
}
|
||||
|
||||
wakuMessage := tests.CreateWakuMessage(contentTopic, (time.Duration(i) * time.Second).Nanoseconds())
|
||||
wakuMessage := tests.CreateWakuMessage(contentTopic, int64(i+1))
|
||||
msg := protocol.NewEnvelope(wakuMessage, "test")
|
||||
_ = s1.storeMessage(msg)
|
||||
}
|
||||
|
||||
fmt.Println(s1.messageQueue.messages[9].msg.Timestamp, s1.messageQueue.messages[9].msg.ContentTopic, "????????????????")
|
||||
|
||||
host2, err := libp2p.New(ctx, libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -380,6 +381,7 @@ func computeIndex(env *protocol.Envelope) (*pb.Index, error) {
|
|||
Digest: env.Hash(),
|
||||
ReceiverTime: utils.GetUnixEpoch(),
|
||||
SenderTime: env.Message().Timestamp,
|
||||
PubsubTopic: env.PubsubTopic(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -390,18 +392,35 @@ func indexComparison(x, y *pb.Index) int {
|
|||
// returns 1 if x > y
|
||||
|
||||
var timecmp int = 0
|
||||
if x.SenderTime > y.SenderTime {
|
||||
timecmp = 1
|
||||
} else if x.SenderTime < y.SenderTime {
|
||||
timecmp = -1
|
||||
}
|
||||
|
||||
digestcm := bytes.Compare(x.Digest, y.Digest)
|
||||
if x.SenderTime != 0 && y.SenderTime != 0 {
|
||||
if x.SenderTime > y.SenderTime {
|
||||
timecmp = 1
|
||||
} else if x.SenderTime < y.SenderTime {
|
||||
timecmp = -1
|
||||
}
|
||||
}
|
||||
if timecmp != 0 {
|
||||
return timecmp // timestamp has a higher priority for comparison
|
||||
}
|
||||
|
||||
return digestcm
|
||||
digestcm := bytes.Compare(x.Digest, y.Digest)
|
||||
if digestcm != 0 {
|
||||
return digestcm
|
||||
}
|
||||
|
||||
pubsubTopicCmp := strings.Compare(x.PubsubTopic, y.PubsubTopic)
|
||||
if pubsubTopicCmp != 0 {
|
||||
return pubsubTopicCmp
|
||||
}
|
||||
|
||||
// receiverTimestamp (a fallback only if senderTimestamp unset on either side, and all other fields unequal)
|
||||
if x.ReceiverTime > y.ReceiverTime {
|
||||
timecmp = 1
|
||||
} else if x.ReceiverTime < y.ReceiverTime {
|
||||
timecmp = -1
|
||||
}
|
||||
return timecmp
|
||||
}
|
||||
|
||||
func indexedWakuMessageComparison(x, y IndexedWakuMessage) int {
|
||||
|
@ -416,7 +435,7 @@ func findIndex(msgList []IndexedWakuMessage, index *pb.Index) int {
|
|||
// returns the position of an IndexedWakuMessage in msgList whose index value matches the given index
|
||||
// returns -1 if no match is found
|
||||
for i, indexedWakuMessage := range msgList {
|
||||
if bytes.Equal(indexedWakuMessage.index.Digest, index.Digest) && indexedWakuMessage.index.ReceiverTime == index.ReceiverTime {
|
||||
if bytes.Equal(indexedWakuMessage.index.Digest, index.Digest) && indexedWakuMessage.index.SenderTime == index.SenderTime && indexedWakuMessage.index.PubsubTopic == index.PubsubTopic {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
@ -615,6 +634,7 @@ func (store *WakuStore) Next(ctx context.Context, r *Result) (*Result, error) {
|
|||
Digest: r.cursor.Digest,
|
||||
ReceiverTime: r.cursor.ReceiverTime,
|
||||
SenderTime: r.cursor.SenderTime,
|
||||
PubsubTopic: r.cursor.PubsubTopic,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -48,37 +48,50 @@ func TestIndexComparison(t *testing.T) {
|
|||
ReceiverTime: 2,
|
||||
SenderTime: 1,
|
||||
Digest: []byte{1},
|
||||
PubsubTopic: "abc",
|
||||
}
|
||||
|
||||
index2 := &pb.Index{
|
||||
ReceiverTime: 2,
|
||||
SenderTime: 1,
|
||||
Digest: []byte{2},
|
||||
PubsubTopic: "abc",
|
||||
}
|
||||
|
||||
index3 := &pb.Index{
|
||||
ReceiverTime: 1,
|
||||
SenderTime: 2,
|
||||
Digest: []byte{3},
|
||||
PubsubTopic: "abc",
|
||||
}
|
||||
|
||||
index4 := &pb.Index{
|
||||
ReceiverTime: 1,
|
||||
SenderTime: 2,
|
||||
Digest: []byte{3},
|
||||
PubsubTopic: "def",
|
||||
}
|
||||
|
||||
iwm1 := IndexedWakuMessage{index: index1}
|
||||
iwm2 := IndexedWakuMessage{index: index2}
|
||||
iwm3 := IndexedWakuMessage{index: index3}
|
||||
iwm4 := IndexedWakuMessage{index: index4}
|
||||
|
||||
require.Equal(t, 0, indexComparison(index1, index1))
|
||||
require.Equal(t, -1, indexComparison(index1, index2))
|
||||
require.Equal(t, 1, indexComparison(index2, index1))
|
||||
require.Equal(t, -1, indexComparison(index1, index3))
|
||||
require.Equal(t, 1, indexComparison(index3, index1))
|
||||
require.Equal(t, -1, indexComparison(index3, index4))
|
||||
|
||||
require.Equal(t, 0, indexedWakuMessageComparison(iwm1, iwm1))
|
||||
require.Equal(t, -1, indexedWakuMessageComparison(iwm1, iwm2))
|
||||
require.Equal(t, 1, indexedWakuMessageComparison(iwm2, iwm1))
|
||||
require.Equal(t, -1, indexedWakuMessageComparison(iwm1, iwm3))
|
||||
require.Equal(t, 1, indexedWakuMessageComparison(iwm3, iwm1))
|
||||
require.Equal(t, -1, indexedWakuMessageComparison(iwm3, iwm4))
|
||||
|
||||
sortingList := []IndexedWakuMessage{iwm3, iwm1, iwm2}
|
||||
sortingList := []IndexedWakuMessage{iwm3, iwm1, iwm2, iwm4}
|
||||
sort.Slice(sortingList, func(i, j int) bool {
|
||||
return indexedWakuMessageComparison(sortingList[i], sortingList[j]) == -1
|
||||
})
|
||||
|
@ -86,6 +99,8 @@ func TestIndexComparison(t *testing.T) {
|
|||
require.Equal(t, iwm1, sortingList[0])
|
||||
require.Equal(t, iwm2, sortingList[1])
|
||||
require.Equal(t, iwm3, sortingList[2])
|
||||
require.Equal(t, iwm4, sortingList[3])
|
||||
|
||||
}
|
||||
|
||||
func createSampleList(s int) []IndexedWakuMessage {
|
||||
|
@ -99,6 +114,7 @@ func createSampleList(s int) []IndexedWakuMessage {
|
|||
ReceiverTime: int64(i),
|
||||
SenderTime: int64(i),
|
||||
Digest: []byte{1},
|
||||
PubsubTopic: "abc",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue