-
Notifications
You must be signed in to change notification settings - Fork 669
/
test_generator.go
34 lines (27 loc) · 964 Bytes
/
test_generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ids
import "sync/atomic"
var offset = uint64(0)
// GenerateTestID returns a new ID that should only be used for testing
func GenerateTestID() ID {
return Empty.Prefix(atomic.AddUint64(&offset, 1))
}
// GenerateTestShortID returns a new ID that should only be used for testing
func GenerateTestShortID() ShortID {
newID := GenerateTestID()
newShortID, _ := ToShortID(newID[:20])
return newShortID
}
// GenerateTestNodeID returns a new ID that should only be used for testing
func GenerateTestNodeID() NodeID {
return NodeID(GenerateTestShortID())
}
// BuildTestNodeID is an utility to build NodeID from bytes in UTs
// It must not be used in production code. In production code we should
// use ToNodeID, which performs proper length checking.
func BuildTestNodeID(src []byte) NodeID {
res := NodeID{}
copy(res[:], src)
return res
}