github.com/Finschia/finschia-sdk@v0.48.1/x/genutil/utils_test.go (about)

     1  package genutil
     2  
     3  import (
     4  	"encoding/json"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/Finschia/ostracon/config"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestExportGenesisFileWithTime(t *testing.T) {
    15  	t.Parallel()
    16  
    17  	fname := filepath.Join(t.TempDir(), "genesis.json")
    18  
    19  	require.NoError(t, ExportGenesisFileWithTime(fname, "test", nil, json.RawMessage(`{"account_owner": "Bob"}`), time.Now()))
    20  }
    21  
    22  func TestInitializeNodeValidatorFilesFromMnemonic(t *testing.T) {
    23  	t.Parallel()
    24  
    25  	cfg := config.TestConfig()
    26  	cfg.RootDir = t.TempDir()
    27  	require.NoError(t, os.MkdirAll(filepath.Join(cfg.RootDir, "config"), 0o755))
    28  
    29  	tests := []struct {
    30  		name     string
    31  		mnemonic string
    32  		expError bool
    33  	}{
    34  		{
    35  			name:     "invalid mnemonic returns error",
    36  			mnemonic: "side video kiss hotel essence",
    37  			expError: true,
    38  		},
    39  		{
    40  			name:     "empty mnemonic does not return error",
    41  			mnemonic: "",
    42  			expError: false,
    43  		},
    44  		{
    45  			name:     "valid mnemonic does not return error",
    46  			mnemonic: "side video kiss hotel essence door angle student degree during vague adjust submit trick globe muscle frozen vacuum artwork million shield bind useful wave",
    47  			expError: false,
    48  		},
    49  	}
    50  
    51  	for _, tt := range tests {
    52  		tt := tt
    53  		t.Run(tt.name, func(t *testing.T) {
    54  			_, _, err := InitializeNodeValidatorFilesFromMnemonic(cfg, tt.mnemonic)
    55  
    56  			if tt.expError {
    57  				require.Error(t, err)
    58  			} else {
    59  				require.NoError(t, err)
    60  			}
    61  		})
    62  	}
    63  }