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",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "manifest, m",
|
||||
Usage: "Read contract manifest (*.manifest.json) file",
|
||||
Name: "manifest, m",
|
||||
Required: true,
|
||||
Usage: "Read contract manifest (*.manifest.json) file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "out, o",
|
||||
Usage: "Output of the compiled contract",
|
||||
Name: "out, o",
|
||||
Required: true,
|
||||
Usage: "Output of the compiled wrapper",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "hash",
|
||||
Usage: "Smart-contract hash",
|
||||
Name: "hash",
|
||||
Required: true,
|
||||
Usage: "Smart-contract hash",
|
||||
},
|
||||
}
|
||||
|
||||
var generateWrapperCmd = cli.Command{
|
||||
Name: "generate-wrapper",
|
||||
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: ``,
|
||||
Action: contractGenerateWrapper,
|
||||
Flags: generatorFlags,
|
||||
|
@ -44,7 +47,7 @@ var generateWrapperCmd = cli.Command{
|
|||
var generateRPCWrapperCmd = cli.Command{
|
||||
Name: "generate-rpcwrapper",
|
||||
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,
|
||||
Flags: generatorFlags,
|
||||
}
|
||||
|
|
|
@ -415,18 +415,18 @@ func TestGenerate_Errors(t *testing.T) {
|
|||
require.True(t, strings.Contains(err.Error(), msg), "got: %v", err)
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
manifestFile := filepath.Join(t.TempDir(), "invalid.json")
|
||||
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) {
|
||||
manifestFile := filepath.Join(t.TempDir(), "invalid.json")
|
||||
|
@ -434,7 +434,7 @@ func TestGenerate_Errors(t *testing.T) {
|
|||
rawManifest, err := json.Marshal(m)
|
||||
require.NoError(t, err)
|
||||
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")
|
||||
|
@ -452,7 +452,7 @@ func TestGenerate_Errors(t *testing.T) {
|
|||
t.Run("missing config", func(t *testing.T) {
|
||||
checkError(t, "can't read config file",
|
||||
"--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) {
|
||||
rawCfg := `package: wrapper
|
||||
|
@ -464,6 +464,6 @@ callflags:
|
|||
|
||||
checkError(t, "can't parse config file",
|
||||
"--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(),
|
||||
"--config", cfgPath)
|
||||
"--config", cfgPath, "--out", "zzz")
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue