Skip to content

Commit

Permalink
adm: never use GetContractStateByID(1) to retrieve NNS hash
Browse files Browse the repository at this point in the history
And use a bit more of NNS wrapper.

Notice that this changes "alphabet X" to "alphabetX" in dump output, but I
consider this to be an improvement (since that's the contract name).

It also deoptimizes some carefully crafted code to extract a number of names in
one call. Likely it's not a performance issue you care about and it's actually
somewhat broken in that it assumes one result per invocation (but you can get
zero or more than one).

Many more things can be improved, but let's start with this.

Refs. #2826.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Apr 27, 2024
1 parent df262cc commit aadc5e0
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 161 deletions.
31 changes: 8 additions & 23 deletions cmd/neofs-adm/internal/modules/morph/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"math/big"

"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
Expand All @@ -19,7 +18,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neofs-contract/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -42,7 +41,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag)
dumpAlphabet, _ = cmd.Flags().GetBool(dumpBalancesAlphabetFlag)
dumpProxy, _ = cmd.Flags().GetBool(dumpBalancesProxyFlag)
nnsCs *state.Contract
nnsReader *nns.ContractReader

Check warning on line 44 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L44

Added line #L44 was not covered by tests
nmHash util.Uint160
)

Expand All @@ -54,12 +53,13 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
inv := invoker.New(c, nil)

if dumpStorage || dumpAlphabet || dumpProxy {
nnsCs, err = c.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c)

Check warning on line 56 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L56

Added line #L56 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract info: %w", err)
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 58 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L58

Added line #L58 was not covered by tests
}
nnsReader = nns.NewReader(inv, nnsHash)

Check warning on line 60 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L60

Added line #L60 was not covered by tests

nmHash, err = nnsResolveHash(inv, nnsCs.Hash, netmapContract+".neofs")
nmHash, err = nnsReader.ResolveFSContract(nns.NameNetmap)

Check warning on line 62 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L62

Added line #L62 was not covered by tests
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
}

if dumpProxy {
h, err := nnsResolveHash(inv, nnsCs.Hash, proxyContract+".neofs")
h, err := nnsReader.ResolveFSContract(nns.NameProxy)

Check warning on line 112 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L112

Added line #L112 was not covered by tests
if err != nil {
return fmt.Errorf("can't get hash of the proxy contract: %w", err)
}
Expand All @@ -124,23 +124,8 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
if dumpAlphabet {
alphaList := make([]accBalancePair, len(irList))

b := smartcontract.NewBuilder()
for i := range alphaList {
b.InvokeMethod(nnsCs.Hash, "resolve", getAlphabetNNSDomain(i), int64(nns.TXT))
}

script, err := b.Script()
if err != nil {
return fmt.Errorf("resolving alphabet hashes script: %w", err)
}

alphaRes, err := c.InvokeScript(script, nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}

for i := range alphaList {
h, err := parseNNSResolveResult(alphaRes.Stack[i])
h, err := nnsReader.ResolveFSContract(getAlphabetNNSDomain(i))

Check warning on line 128 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L128

Added line #L128 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch the alphabet contract #%d hash: %w", i, err)
}
Expand Down
15 changes: 9 additions & 6 deletions cmd/neofs-adm/internal/modules/morph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -28,12 +29,13 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {

inv := invoker.New(c, nil)

cs, err := c.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c)

Check warning on line 32 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L32

Added line #L32 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract info: %w", err)
return fmt.Errorf("can't find NNS hash: %w", err)

Check warning on line 34 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L34

Added line #L34 was not covered by tests
}
nnsReader := nns.NewReader(inv, nnsHash)

Check warning on line 36 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L36

Added line #L36 was not covered by tests

nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".neofs")
nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap)

Check warning on line 38 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L38

Added line #L38 was not covered by tests
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
Expand Down Expand Up @@ -102,12 +104,13 @@ func setConfigCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("can't initialize context: %w", err)
}

cs, err := wCtx.Client.GetContractStateByID(1)
nnsHash, err := nns.InferHash(wCtx.Client)

Check warning on line 107 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L107

Added line #L107 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract info: %w", err)
return err

Check warning on line 109 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L109

Added line #L109 was not covered by tests
}
nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash)

Check warning on line 111 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L111

Added line #L111 was not covered by tests

nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".neofs")
nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap)

Check warning on line 113 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L113

Added line #L113 was not covered by tests
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
Expand Down
18 changes: 11 additions & 7 deletions cmd/neofs-adm/internal/modules/morph/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -27,13 +28,15 @@ func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker, c Client
ch, err = util.Uint160DecodeStringLE(s)
}
if err != nil {
nnsCs, err := c.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c)

Check warning on line 31 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L31

Added line #L31 was not covered by tests
if err != nil {
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
return ch, fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 33 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L33

Added line #L33 was not covered by tests
}
ch, err = nnsResolveHash(inv, nnsCs.Hash, containerContract+".neofs")
nnsReader := nns.NewReader(inv, nnsHash)

Check warning on line 35 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L35

Added line #L35 was not covered by tests

ch, err = nnsReader.ResolveFSContract(nns.NameContainer)

Check warning on line 37 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L37

Added line #L37 was not covered by tests
if err != nil {
return util.Uint160{}, err
return ch, fmt.Errorf("can't fetch container contract hash: %w", err)

Check warning on line 39 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L39

Added line #L39 was not covered by tests
}
}
return ch, nil
Expand Down Expand Up @@ -168,12 +171,13 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
}
defer wCtx.close()

nnsCs, err := wCtx.Client.GetContractStateByID(1)
nnsHash, err := nns.InferHash(wCtx.Client)

Check warning on line 174 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L174

Added line #L174 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract state: %w", err)
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 176 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L176

Added line #L176 was not covered by tests
}
nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash)

Check warning on line 178 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L178

Added line #L178 was not covered by tests

ch, err := nnsResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, containerContract+".neofs")
ch, err := nnsReader.ResolveFSContract(nns.NameContainer)

Check warning on line 180 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L180

Added line #L180 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch container contract hash: %w", err)
}
Expand Down
28 changes: 14 additions & 14 deletions cmd/neofs-adm/internal/modules/morph/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neofs-contract/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -76,9 +76,9 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
return err
}

nnsCs, err := c.Client.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c.Client)

Check warning on line 79 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L79

Added line #L79 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch NNS contract state: %w", err)
return fmt.Errorf("can't fetch NNS contract hash: %w", err)

Check warning on line 81 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L81

Added line #L81 was not covered by tests
}

callHash := management.Hash
Expand All @@ -87,7 +87,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
domain := ctrName + "." + zone
isUpdate, _ := cmd.Flags().GetBool(updateFlag)
if isUpdate {
cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsCs.Hash, domain)
cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsHash, domain)

Check warning on line 90 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L90

Added line #L90 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch contract hash from NNS: %w", err)
}
Expand All @@ -113,28 +113,28 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
if !isUpdate {
bw := io.NewBufBinWriter()
emit.Instruction(bw.BinWriter, opcode.INITSSLOT, []byte{1})
emit.AppCall(bw.BinWriter, nnsCs.Hash, "getPrice", callflag.All)
emit.AppCall(bw.BinWriter, nnsHash, "getPrice", callflag.All)

Check warning on line 116 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L116

Added line #L116 was not covered by tests
emit.Opcodes(bw.BinWriter, opcode.STSFLD0)
emit.AppCall(bw.BinWriter, nnsCs.Hash, "setPrice", callflag.All, 1)
emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, 1)

Check warning on line 118 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L118

Added line #L118 was not covered by tests

start := bw.Len()
needRecord := false

ok, err := c.nnsRootRegistered(nnsCs.Hash, zone)
ok, err := c.nnsRootRegistered(nnsHash, zone)

Check warning on line 123 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L123

Added line #L123 was not covered by tests
if err != nil {
return err
} else if !ok {
needRecord = true

emit.AppCall(bw.BinWriter, nnsCs.Hash, "registerTLD", callflag.All,
emit.AppCall(bw.BinWriter, nnsHash, "registerTLD", callflag.All,

Check warning on line 129 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L129

Added line #L129 was not covered by tests
zone,
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All,

Check warning on line 132 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L132

Added line #L132 was not covered by tests
domain, c.CommitteeAcc.Contract.ScriptHash(),
"ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
} else {
s, ok, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain)
s, ok, err := c.nnsRegisterDomainScript(nnsHash, cs.Hash, domain)

Check warning on line 137 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L137

Added line #L137 was not covered by tests
if err != nil {
return err
}
Expand All @@ -144,17 +144,17 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
}
}
if needRecord {
emit.AppCall(bw.BinWriter, nnsCs.Hash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
domain, int64(nns.TXT), address.Uint160ToString(cs.Hash))
emit.AppCall(bw.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, nns.TXT)
emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All,
domain, nns.TXT, address.Uint160ToString(cs.Hash))

Check warning on line 149 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L147-L149

Added lines #L147 - L149 were not covered by tests
}

if bw.Err != nil {
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))
} else if bw.Len() != start {
w.WriteBytes(bw.Bytes())
emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK)
emit.AppCallNoArgs(w.BinWriter, nnsCs.Hash, "setPrice", callflag.All)
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)

Check warning on line 157 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L157

Added line #L157 was not covered by tests

if needRecord {
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
Expand Down
63 changes: 14 additions & 49 deletions cmd/neofs-adm/internal/modules/morph/dump_hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neofs-contract/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -39,76 +39,41 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't create N3 client: %w", err)
}

cs, err := c.GetContractStateByID(1)
inv := invoker.New(c, nil)
nnsHash, err := nns.InferHash(c)

Check warning on line 43 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L42-L43

Added lines #L42 - L43 were not covered by tests
if err != nil {
return err
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 45 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L45

Added line #L45 was not covered by tests
}
nnsReader := nns.NewReader(inv, nnsHash)

Check warning on line 47 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L47

Added line #L47 was not covered by tests

zone, _ := cmd.Flags().GetString(customZoneFlag)
if zone != "" {
return dumpCustomZoneHashes(cmd, cs.Hash, zone, c)
return dumpCustomZoneHashes(cmd, nnsHash, zone, c)

Check warning on line 51 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L51

Added line #L51 was not covered by tests
}

infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}}
infos := []contractDumpInfo{{name: nnsContract, hash: nnsHash}}

Check warning on line 54 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L54

Added line #L54 was not covered by tests

irSize := 0
for ; irSize < lastGlagoliticLetter; irSize++ {
ok, err := nnsIsAvailable(c, cs.Hash, getAlphabetNNSDomain(irSize))
ok, err := nnsReader.IsAvailable(getAlphabetNNSDomain(irSize) + "." + nns.ContractTLD)

Check warning on line 58 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L58

Added line #L58 was not covered by tests
if err != nil {
return err
} else if ok {
break
}
}

b := smartcontract.NewBuilder()

if irSize != 0 {
b.Reset()
for i := 0; i < irSize; i++ {
b.InvokeMethod(cs.Hash, "resolve", getAlphabetNNSDomain(i), int64(nns.TXT))
}

script, err := b.Script()
if err != nil {
return fmt.Errorf("resolving alphabet hashes script: %w", err)
}

alphaRes, err := c.InvokeScript(script, nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}

for i := 0; i < irSize; i++ {
info := contractDumpInfo{name: fmt.Sprintf("alphabet %d", i)}
if h, err := parseNNSResolveResult(alphaRes.Stack[i]); err == nil {
info.hash = h
}
infos = append(infos, info)
}
var contracts = make([]string, 0, irSize+len(contractList))
for i := 0; i < irSize; i++ {
contracts = append(contracts, getAlphabetNNSDomain(i))

Check warning on line 68 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L66-L68

Added lines #L66 - L68 were not covered by tests
}

for _, ctrName := range contractList {
b.Reset()
b.InvokeMethod(cs.Hash, "resolve", ctrName+".neofs", int64(nns.TXT))

script, err := b.Script()
h, err := nnsReader.ResolveFSContract(ctrName)

Check warning on line 72 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L72

Added line #L72 was not covered by tests
if err != nil {
return fmt.Errorf("resolving neofs contract hashes script: %w", err)
}

res, err := c.InvokeScript(script, nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}

info := contractDumpInfo{name: ctrName}
if len(res.Stack) != 0 {
if h, err := parseNNSResolveResult(res.Stack[0]); err == nil {
info.hash = h
}
return fmt.Errorf("can't resolve %s contract: %w", ctrName, err)

Check warning on line 74 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L74

Added line #L74 was not covered by tests
}
infos = append(infos, info)
infos = append(infos, contractDumpInfo{name: ctrName, hash: h})

Check warning on line 76 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L76

Added line #L76 was not covered by tests
}

fillContractVersion(cmd, c, infos)
Expand Down
10 changes: 5 additions & 5 deletions cmd/neofs-adm/internal/modules/morph/dump_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -28,12 +28,12 @@ func dumpNames(cmd *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("can't create N3 client: %w", err)
}
cs, err := c.GetContractStateByID(1) // NNS.
nnsHash, err := nns.InferHash(c)

Check warning on line 31 in cmd/neofs-adm/internal/modules/morph/dump_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_names.go#L31

Added line #L31 was not covered by tests
if err != nil {
return err
}
var n11r = nep11.NewNonDivisibleReader(invoker.New(c, nil), cs.Hash)
tokIter, err := n11r.Tokens()
var nnsReader = nns.NewReader(invoker.New(c, nil), nnsHash)
tokIter, err := nnsReader.Tokens()

Check warning on line 36 in cmd/neofs-adm/internal/modules/morph/dump_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_names.go#L35-L36

Added lines #L35 - L36 were not covered by tests
if err != nil {
return err
}
Expand All @@ -48,7 +48,7 @@ func dumpNames(cmd *cobra.Command, _ []string) error {
if zone != "" && !strings.HasSuffix(name, "."+zone) {
continue
}
props, err := n11r.Properties(toks[i])
props, err := nnsReader.Properties(toks[i])

Check warning on line 51 in cmd/neofs-adm/internal/modules/morph/dump_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_names.go#L51

Added line #L51 was not covered by tests
if err != nil {
cmd.PrintErrf("Error getting properties for %s: %v\n", name, err)
continue
Expand Down
Loading

0 comments on commit aadc5e0

Please sign in to comment.