Speedup adm tests #1138
2 changed files with 31 additions and 25 deletions
|
@ -65,34 +65,42 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
|
||||||
pubs := make(keys.PublicKeys, size)
|
pubs := make(keys.PublicKeys, size)
|
||||||
passwords := make([]string, size)
|
passwords := make([]string, size)
|
||||||
|
|
||||||
|
var errG errgroup.Group
|
||||||
|
|
||||||
for i := range wallets {
|
for i := range wallets {
|
||||||
password, err := config.GetPassword(v, innerring.GlagoliticLetter(i).String())
|
password, err := config.GetPassword(v, innerring.GlagoliticLetter(i).String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't fetch password: %w", err)
|
return nil, fmt.Errorf("can't fetch password: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
i := i
|
||||||
f, err := os.OpenFile(p, os.O_CREATE, 0o644)
|
errG.Go(func() error {
|
||||||
if err != nil {
|
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||||
return nil, fmt.Errorf("can't create wallet file: %w", err)
|
f, err := os.OpenFile(p, os.O_CREATE, 0o644)
|
||||||
}
|
if err != nil {
|
||||||
if err := f.Close(); err != nil {
|
return fmt.Errorf("can't create wallet file: %w", err)
|
||||||
return nil, fmt.Errorf("can't close wallet file: %w", err)
|
}
|
||||||
}
|
if err := f.Close(); err != nil {
|
||||||
w, err := wallet.NewWallet(p)
|
return fmt.Errorf("can't close wallet file: %w", err)
|
||||||
if err != nil {
|
}
|
||||||
return nil, fmt.Errorf("can't create wallet: %w", err)
|
w, err := wallet.NewWallet(p)
|
||||||
}
|
if err != nil {
|
||||||
if err := w.CreateAccount(constants.SingleAccountName, password); err != nil {
|
return fmt.Errorf("can't create wallet: %w", err)
|
||||||
return nil, fmt.Errorf("can't create account: %w", err)
|
}
|
||||||
}
|
if err := w.CreateAccount(constants.SingleAccountName, password); err != nil {
|
||||||
|
return fmt.Errorf("can't create account: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
passwords[i] = password
|
passwords[i] = password
|
||||||
wallets[i] = w
|
wallets[i] = w
|
||||||
pubs[i] = w.Accounts[0].PrivateKey().PublicKey()
|
pubs[i] = w.Accounts[0].PrivateKey().PublicKey()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var errG errgroup.Group
|
if err := errG.Wait(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Create committee account with N/2+1 multi-signature.
|
// Create committee account with N/2+1 multi-signature.
|
||||||
majCount := smartcontract.GetMajorityHonestNodeCount(size)
|
majCount := smartcontract.GetMajorityHonestNodeCount(size)
|
||||||
|
|
|
@ -23,8 +23,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateAlphabet(t *testing.T) {
|
func TestGenerateAlphabet(t *testing.T) {
|
||||||
const size = 4
|
|
||||||
|
|
||||||
walletDir := t.TempDir()
|
walletDir := t.TempDir()
|
||||||
buf := setupTestTerminal(t)
|
buf := setupTestTerminal(t)
|
||||||
|
|
||||||
|
@ -55,13 +53,13 @@ func TestGenerateAlphabet(t *testing.T) {
|
||||||
t.Run("no password for contract group wallet", func(t *testing.T) {
|
t.Run("no password for contract group wallet", func(t *testing.T) {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
||||||
require.NoError(t, cmd.Flags().Set(commonflags.AlphabetSizeFlag, strconv.FormatUint(size, 10)))
|
require.NoError(t, cmd.Flags().Set(commonflags.AlphabetSizeFlag, "1"))
|
||||||
for i := uint64(0); i < size; i++ {
|
buf.WriteString("pass\r")
|
||||||
buf.WriteString(strconv.FormatUint(i, 10) + "\r")
|
|
||||||
}
|
|
||||||
require.Error(t, AlphabetCreds(cmd, nil))
|
require.Error(t, AlphabetCreds(cmd, nil))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const size = 4
|
||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
v.Set(commonflags.AlphabetWalletsFlag, walletDir)
|
||||||
require.NoError(t, GenerateAlphabetCmd.Flags().Set(commonflags.AlphabetSizeFlag, strconv.FormatUint(size, 10)))
|
require.NoError(t, GenerateAlphabetCmd.Flags().Set(commonflags.AlphabetSizeFlag, strconv.FormatUint(size, 10)))
|
||||||
|
|
Loading…
Reference in a new issue