mirror of
https://github.com/luxfi/ids.git
synced 2026-10-30 16:22:36 +00:00
35 lines
969 B
Go
35 lines
969 B
Go
// Copyright (C) 2020-2025, Lux Industries 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
|
|
}
|