mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Add tests
This commit is contained in:
		
							parent
							
								
									f92d812f3c
								
							
						
					
					
						commit
						80dba6e757
					
				
					 1 changed files with 63 additions and 0 deletions
				
			
		
							
								
								
									
										63
									
								
								src/config/config_test.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/config/config_test.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,63 @@
 | 
			
		|||
package config
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
  "bytes"
 | 
			
		||||
  "encoding/hex"
 | 
			
		||||
  "testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestConfig_Keys(t *testing.T) {
 | 
			
		||||
  var nodeConfig NodeConfig
 | 
			
		||||
 | 
			
		||||
  if nodeConfig.PublicKey != "" {
 | 
			
		||||
    t.Fatal("public key is not empty by default")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if nodeConfig.PrivateKey != "" {
 | 
			
		||||
    t.Fatal("private key is not empty by default")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  nodeConfig.NewKeys()
 | 
			
		||||
 | 
			
		||||
  publicKey1, err := hex.DecodeString(nodeConfig.PublicKey)
 | 
			
		||||
 | 
			
		||||
  if err != nil {
 | 
			
		||||
    t.Fatal("can not decode generated public key")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if len(publicKey1) == 0 {
 | 
			
		||||
    t.Fatal("empty public key generated")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  privateKey1, err := hex.DecodeString(nodeConfig.PrivateKey)
 | 
			
		||||
 | 
			
		||||
  if err != nil {
 | 
			
		||||
    t.Fatal("can not decode generated private key")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if len(privateKey1) == 0 {
 | 
			
		||||
    t.Fatal("empty private key generated")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  nodeConfig.NewKeys()
 | 
			
		||||
 | 
			
		||||
  publicKey2, err := hex.DecodeString(nodeConfig.PublicKey)
 | 
			
		||||
 | 
			
		||||
  if err != nil {
 | 
			
		||||
    t.Fatal("can not decode generated public key")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if bytes.Equal(publicKey2, publicKey1) {
 | 
			
		||||
    t.Fatal("same public key generated")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  privateKey2, err := hex.DecodeString(nodeConfig.PrivateKey)
 | 
			
		||||
 | 
			
		||||
  if err != nil {
 | 
			
		||||
    t.Fatal("can not decode generated private key")
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if bytes.Equal(privateKey2, privateKey1) {
 | 
			
		||||
    t.Fatal("same private key generated")
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue