mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
Merge pull request #2852 from nspcc-dev/required-hash
cli: mark required flags of `generate-*` command
This commit is contained in:
commit
5ad1fcd321
2 changed files with 18 additions and 15 deletions
|
@ -19,23 +19,26 @@ var generatorFlags = []cli.Flag{
|
||||||
Usage: "Configuration file to use",
|
Usage: "Configuration file to use",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "manifest, m",
|
Name: "manifest, m",
|
||||||
Usage: "Read contract manifest (*.manifest.json) file",
|
Required: true,
|
||||||
|
Usage: "Read contract manifest (*.manifest.json) file",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "out, o",
|
Name: "out, o",
|
||||||
Usage: "Output of the compiled contract",
|
Required: true,
|
||||||
|
Usage: "Output of the compiled wrapper",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "hash",
|
Name: "hash",
|
||||||
Usage: "Smart-contract hash",
|
Required: true,
|
||||||
|
Usage: "Smart-contract hash",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var generateWrapperCmd = cli.Command{
|
var generateWrapperCmd = cli.Command{
|
||||||
Name: "generate-wrapper",
|
Name: "generate-wrapper",
|
||||||
Usage: "generate wrapper to use in other contracts",
|
Usage: "generate wrapper to use in other contracts",
|
||||||
UsageText: "neo-go contract generate-wrapper --manifest <file.json> --out <file.go> --hash <hash>",
|
UsageText: "neo-go contract generate-wrapper --manifest <file.json> --out <file.go> --hash <hash> [--config <config>]",
|
||||||
Description: ``,
|
Description: ``,
|
||||||
Action: contractGenerateWrapper,
|
Action: contractGenerateWrapper,
|
||||||
Flags: generatorFlags,
|
Flags: generatorFlags,
|
||||||
|
@ -44,7 +47,7 @@ var generateWrapperCmd = cli.Command{
|
||||||
var generateRPCWrapperCmd = cli.Command{
|
var generateRPCWrapperCmd = cli.Command{
|
||||||
Name: "generate-rpcwrapper",
|
Name: "generate-rpcwrapper",
|
||||||
Usage: "generate RPC wrapper to use for data reads",
|
Usage: "generate RPC wrapper to use for data reads",
|
||||||
UsageText: "neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> --hash <hash>",
|
UsageText: "neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> --hash <hash> [--config <config>]",
|
||||||
Action: contractGenerateRPCWrapper,
|
Action: contractGenerateRPCWrapper,
|
||||||
Flags: generatorFlags,
|
Flags: generatorFlags,
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,18 +415,18 @@ func TestGenerate_Errors(t *testing.T) {
|
||||||
require.True(t, strings.Contains(err.Error(), msg), "got: %v", err)
|
require.True(t, strings.Contains(err.Error(), msg), "got: %v", err)
|
||||||
}
|
}
|
||||||
t.Run("invalid hash", func(t *testing.T) {
|
t.Run("invalid hash", func(t *testing.T) {
|
||||||
checkError(t, "invalid contract hash", "--hash", "xxx")
|
checkError(t, "invalid contract hash", "--hash", "xxx", "--manifest", "yyy", "--out", "zzz")
|
||||||
})
|
})
|
||||||
t.Run("missing manifest argument", func(t *testing.T) {
|
t.Run("missing manifest argument", func(t *testing.T) {
|
||||||
checkError(t, errNoManifestFile.Error(), "--hash", util.Uint160{}.StringLE())
|
checkError(t, "Required flag \"manifest\" not set", "--hash", util.Uint160{}.StringLE(), "--out", "zzz")
|
||||||
})
|
})
|
||||||
t.Run("missing manifest file", func(t *testing.T) {
|
t.Run("missing manifest file", func(t *testing.T) {
|
||||||
checkError(t, "can't read contract manifest", "--manifest", "notexists", "--hash", util.Uint160{}.StringLE())
|
checkError(t, "can't read contract manifest", "--manifest", "notexists", "--hash", util.Uint160{}.StringLE(), "--out", "zzz")
|
||||||
})
|
})
|
||||||
t.Run("empty manifest", func(t *testing.T) {
|
t.Run("empty manifest", func(t *testing.T) {
|
||||||
manifestFile := filepath.Join(t.TempDir(), "invalid.json")
|
manifestFile := filepath.Join(t.TempDir(), "invalid.json")
|
||||||
require.NoError(t, os.WriteFile(manifestFile, []byte("[]"), os.ModePerm))
|
require.NoError(t, os.WriteFile(manifestFile, []byte("[]"), os.ModePerm))
|
||||||
checkError(t, "json: cannot unmarshal array into Go value of type manifest.Manifest", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE())
|
checkError(t, "json: cannot unmarshal array into Go value of type manifest.Manifest", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), "--out", "zzz")
|
||||||
})
|
})
|
||||||
t.Run("invalid manifest", func(t *testing.T) {
|
t.Run("invalid manifest", func(t *testing.T) {
|
||||||
manifestFile := filepath.Join(t.TempDir(), "invalid.json")
|
manifestFile := filepath.Join(t.TempDir(), "invalid.json")
|
||||||
|
@ -434,7 +434,7 @@ func TestGenerate_Errors(t *testing.T) {
|
||||||
rawManifest, err := json.Marshal(m)
|
rawManifest, err := json.Marshal(m)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm))
|
require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm))
|
||||||
checkError(t, "ABI: no methods", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE())
|
checkError(t, "ABI: no methods", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), "--out", "zzz")
|
||||||
})
|
})
|
||||||
|
|
||||||
manifestFile := filepath.Join(t.TempDir(), "manifest.json")
|
manifestFile := filepath.Join(t.TempDir(), "manifest.json")
|
||||||
|
@ -452,7 +452,7 @@ func TestGenerate_Errors(t *testing.T) {
|
||||||
t.Run("missing config", func(t *testing.T) {
|
t.Run("missing config", func(t *testing.T) {
|
||||||
checkError(t, "can't read config file",
|
checkError(t, "can't read config file",
|
||||||
"--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(),
|
"--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(),
|
||||||
"--config", filepath.Join(t.TempDir(), "not.exists.yml"))
|
"--config", filepath.Join(t.TempDir(), "not.exists.yml"), "--out", "zzz")
|
||||||
})
|
})
|
||||||
t.Run("invalid config", func(t *testing.T) {
|
t.Run("invalid config", func(t *testing.T) {
|
||||||
rawCfg := `package: wrapper
|
rawCfg := `package: wrapper
|
||||||
|
@ -464,6 +464,6 @@ callflags:
|
||||||
|
|
||||||
checkError(t, "can't parse config file",
|
checkError(t, "can't parse config file",
|
||||||
"--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(),
|
"--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(),
|
||||||
"--config", cfgPath)
|
"--config", cfgPath, "--out", "zzz")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue