forked from TrueCloudLab/neoneo-go
Merge pull request #2237 from nspcc-dev/convert-base64-address
vmcli: convert base64 string to address in `parse`
This commit is contained in:
commit
48668afa7a
2 changed files with 21 additions and 0 deletions
|
@ -633,6 +633,12 @@ func Parse(args []string) (string, error) {
|
|||
if rawStr, err := base64.StdEncoding.DecodeString(arg); err == nil {
|
||||
buf.WriteString(fmt.Sprintf("Base64 to String\t%s\n", fmt.Sprintf("%q", string(rawStr))))
|
||||
buf.WriteString(fmt.Sprintf("Base64 to BigInteger\t%s\n", bigint.FromBytes(rawStr)))
|
||||
if u, err := util.Uint160DecodeBytesBE(rawStr); err == nil {
|
||||
buf.WriteString(fmt.Sprintf("Base64 to BE ScriptHash\t%s\n", u.StringBE()))
|
||||
buf.WriteString(fmt.Sprintf("Base64 to LE ScriptHash\t%s\n", u.StringLE()))
|
||||
buf.WriteString(fmt.Sprintf("Base64 to Address (BE)\t%s\n", address.Uint160ToString(u)))
|
||||
buf.WriteString(fmt.Sprintf("Base64 to Address (LE)\t%s\n", address.Uint160ToString(u.Reverse())))
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteString(fmt.Sprintf("String to Hex\t%s\n", hex.EncodeToString([]byte(arg))))
|
||||
|
|
|
@ -16,9 +16,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/abiosoft/readline"
|
||||
"github.com/nspcc-dev/neo-go/internal/random"
|
||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -586,6 +588,19 @@ func TestParse(t *testing.T) {
|
|||
e.checkNextLine(t, "String to Hex.*303262333632326266343031376264666533313763353861656435663463373533663230366237646238393630343666613764373734626263346266376638646332")
|
||||
e.checkNextLine(t, "String to Base64.*MDJiMzYyMmJmNDAxN2JkZmUzMTdjNThhZWQ1ZjRjNzUzZjIwNmI3ZGI4OTYwNDZmYTdkNzc0YmJjNGJmN2Y4ZGMy")
|
||||
})
|
||||
t.Run("base64", func(t *testing.T) {
|
||||
e := newTestVMCLI(t)
|
||||
u := random.Uint160()
|
||||
e.runProg(t, "parse "+base64.StdEncoding.EncodeToString(u.BytesBE()))
|
||||
e.checkNextLine(t, "Base64 to String\\s+")
|
||||
e.checkNextLine(t, "Base64 to BigInteger\\s+")
|
||||
e.checkNextLine(t, "Base64 to BE ScriptHash\\s+"+u.StringBE())
|
||||
e.checkNextLine(t, "Base64 to LE ScriptHash\\s+"+u.StringLE())
|
||||
e.checkNextLine(t, "Base64 to Address \\(BE\\)\\s+"+address.Uint160ToString(u))
|
||||
e.checkNextLine(t, "Base64 to Address \\(LE\\)\\s+"+address.Uint160ToString(u.Reverse()))
|
||||
e.checkNextLine(t, "String to Hex\\s+")
|
||||
e.checkNextLine(t, "String to Base64\\s+")
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrintLogo(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue