mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 23:55:11 +00:00
cli: move cosigners parsing to a separate function
We have a lot of common code which is shared between `smartcontract` and `wallet` cli packages. It's convinient to keep it in a separate helper package in order to avoid functional cli packages dependencies.
This commit is contained in:
parent
8407ae057c
commit
2ab420ed18
4 changed files with 111 additions and 87 deletions
54
cli/cmdargs/parser_test.go
Normal file
54
cli/cmdargs/parser_test.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package cmdargs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseCosigner(t *testing.T) {
|
||||
acc := util.Uint160{1, 3, 5, 7}
|
||||
testCases := map[string]transaction.Signer{
|
||||
acc.StringLE(): {
|
||||
Account: acc,
|
||||
Scopes: transaction.CalledByEntry,
|
||||
},
|
||||
"0x" + acc.StringLE(): {
|
||||
Account: acc,
|
||||
Scopes: transaction.CalledByEntry,
|
||||
},
|
||||
acc.StringLE() + ":Global": {
|
||||
Account: acc,
|
||||
Scopes: transaction.Global,
|
||||
},
|
||||
acc.StringLE() + ":CalledByEntry": {
|
||||
Account: acc,
|
||||
Scopes: transaction.CalledByEntry,
|
||||
},
|
||||
acc.StringLE() + ":None": {
|
||||
Account: acc,
|
||||
Scopes: transaction.None,
|
||||
},
|
||||
acc.StringLE() + ":CalledByEntry,CustomContracts": {
|
||||
Account: acc,
|
||||
Scopes: transaction.CalledByEntry | transaction.CustomContracts,
|
||||
},
|
||||
}
|
||||
for s, expected := range testCases {
|
||||
actual, err := parseCosigner(s)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
errorCases := []string{
|
||||
acc.StringLE() + "0",
|
||||
acc.StringLE() + ":Unknown",
|
||||
acc.StringLE() + ":Global,CustomContracts",
|
||||
acc.StringLE() + ":Global,None",
|
||||
}
|
||||
for _, s := range errorCases {
|
||||
_, err := parseCosigner(s)
|
||||
require.Error(t, err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue