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