mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
Add tests
This commit is contained in:
parent
341c1ec7d7
commit
34d5d4c245
1 changed files with 47 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
package address
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/ed25519"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
@ -58,13 +59,56 @@ func TestAddress_AddrForKey(t *testing.T) {
|
|||
251, 141, 171, 8, 170, 152, 227, 5, 82, 138, 184, 79, 65, 158, 110, 251,
|
||||
}
|
||||
|
||||
gotAddress := AddrForKey(publicKey)
|
||||
|
||||
expectedAddress := Address{
|
||||
2, 0, 132, 138, 96, 79, 187, 126, 67, 132, 101, 219, 141, 182, 104, 149,
|
||||
}
|
||||
|
||||
if *gotAddress != expectedAddress {
|
||||
if *AddrForKey(publicKey) != expectedAddress {
|
||||
t.Fatal("invalid address returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddress_SubnetForKey(t *testing.T) {
|
||||
publicKey := ed25519.PublicKey{
|
||||
189, 186, 207, 216, 34, 64, 222, 61, 205, 18, 57, 36, 203, 181, 82, 86,
|
||||
251, 141, 171, 8, 170, 152, 227, 5, 82, 138, 184, 79, 65, 158, 110, 251,
|
||||
}
|
||||
|
||||
expectedSubnet := Subnet{3, 0, 132, 138, 96, 79, 187, 126}
|
||||
|
||||
if *SubnetForKey(publicKey) != expectedSubnet {
|
||||
t.Fatal("invalid subnet returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddress_Address_GetKey(t *testing.T) {
|
||||
address := Address{
|
||||
2, 0, 132, 138, 96, 79, 187, 126, 67, 132, 101, 219, 141, 182, 104, 149,
|
||||
}
|
||||
|
||||
expectedPublicKey := ed25519.PublicKey{
|
||||
189, 186, 207, 216, 34, 64, 222, 61,
|
||||
205, 18, 57, 36, 203, 181, 127, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255,
|
||||
}
|
||||
|
||||
if !bytes.Equal(address.GetKey(), expectedPublicKey) {
|
||||
t.Fatal("invalid public key returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddress_Subnet_GetKey(t *testing.T) {
|
||||
subnet := Subnet{3, 0, 132, 138, 96, 79, 187, 126}
|
||||
|
||||
expectedPublicKey := ed25519.PublicKey{
|
||||
189, 186, 207, 216, 34, 64, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255,
|
||||
}
|
||||
|
||||
if !bytes.Equal(subnet.GetKey(), expectedPublicKey) {
|
||||
t.Fatal("invalid public key returned")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue