From a2cb9cbc495be911568ae61adb1779ee88bca027 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sat, 17 Jul 2021 16:00:22 +0300 Subject: [PATCH] [#684] neofs-adm: add labels to multisig accounts Also check that correct multisig is generated. Signed-off-by: Evgenii Stratonikov --- cmd/neofs-adm/internal/modules/morph/generate.go | 16 ++++++++++++---- .../internal/modules/morph/generate_test.go | 8 ++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/generate.go b/cmd/neofs-adm/internal/modules/morph/generate.go index 56b2efc22..09b5d2551 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate.go +++ b/cmd/neofs-adm/internal/modules/morph/generate.go @@ -14,6 +14,12 @@ import ( "github.com/spf13/viper" ) +const ( + singleAccountName = "single" + committeeAccountName = "committee" + consensusAccountName = "consensus" +) + func generateAlphabetCreds(cmd *cobra.Command, args []string) error { // alphabet size is not part of the config size, err := cmd.Flags().GetUint(alphabetSizeFlag) @@ -56,7 +62,7 @@ func initializeWallets(walletDir string, size int) ([]string, error) { if err != nil { return nil, fmt.Errorf("can't create wallet: %w", err) } - if err := w.CreateAccount("single", password); err != nil { + if err := w.CreateAccount(singleAccountName, password); err != nil { return nil, fmt.Errorf("can't create account: %w", err) } @@ -68,7 +74,7 @@ func initializeWallets(walletDir string, size int) ([]string, error) { // Create committee account with N/2+1 multi-signature. majCount := smartcontract.GetMajorityHonestNodeCount(size) for i, w := range wallets { - if err := addMultisigAccount(w, majCount, passwords[i], pubs); err != nil { + if err := addMultisigAccount(w, majCount, committeeAccountName, passwords[i], pubs); err != nil { return nil, fmt.Errorf("can't create committee account: %w", err) } } @@ -76,7 +82,7 @@ func initializeWallets(walletDir string, size int) ([]string, error) { // Create consensus account with 2*N/3+1 multi-signature. bftCount := smartcontract.GetDefaultHonestNodeCount(size) for i, w := range wallets { - if err := addMultisigAccount(w, bftCount, passwords[i], pubs); err != nil { + if err := addMultisigAccount(w, bftCount, consensusAccountName, passwords[i], pubs); err != nil { return nil, fmt.Errorf("can't create consensus account: %w", err) } } @@ -91,8 +97,10 @@ func initializeWallets(walletDir string, size int) ([]string, error) { return passwords, nil } -func addMultisigAccount(w *wallet.Wallet, m int, password string, pubs keys.PublicKeys) error { +func addMultisigAccount(w *wallet.Wallet, m int, name, password string, pubs keys.PublicKeys) error { acc := wallet.NewAccountFromPrivateKey(w.Accounts[0].PrivateKey()) + acc.Label = name + if err := acc.ConvertMultisig(m, pubs); err != nil { return err } diff --git a/cmd/neofs-adm/internal/modules/morph/generate_test.go b/cmd/neofs-adm/internal/modules/morph/generate_test.go index 774415f68..e24dc8cb7 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate_test.go +++ b/cmd/neofs-adm/internal/modules/morph/generate_test.go @@ -66,6 +66,14 @@ func TestGenerateAlphabet(t *testing.T) { for _, a := range w.Accounts { err := a.Decrypt(strconv.FormatUint(i, 10), keys.NEP2ScryptParams()) require.NoError(t, err, "can't decrypt account") + switch a.Label { + case consensusAccountName: + require.Equal(t, size/2+1, len(a.Contract.Parameters)) + case committeeAccountName: + require.Equal(t, size*2/3+1, len(a.Contract.Parameters)) + default: + require.Equal(t, singleAccountName, a.Label) + } } } }