mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-25 13:56:35 +00:00
37ecf51d13
There is a quirk related to ordering: we store accounts in such an order that is expected by multi-signature verification script. This was done to speed up transaction/block signing which is done quite frequently in tests. This commit allows to provide accounts in any order and to extract a single signer from multi-signer based on this order. Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
48 lines
1 KiB
Go
48 lines
1 KiB
Go
package neotest
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSingleSigner(t *testing.T) {
|
|
a, err := wallet.NewAccount()
|
|
require.NoError(t, err)
|
|
|
|
s := NewSingleSigner(a)
|
|
require.Equal(t, s.ScriptHash(), s.Account().Contract.ScriptHash())
|
|
}
|
|
|
|
func TestMultiSigner(t *testing.T) {
|
|
const size = 4
|
|
|
|
pubs := make(keys.PublicKeys, size)
|
|
accs := make([]*wallet.Account, size)
|
|
for i := range accs {
|
|
a, err := wallet.NewAccount()
|
|
require.NoError(t, err)
|
|
|
|
accs[i] = a
|
|
pubs[i] = a.PrivateKey().PublicKey()
|
|
}
|
|
|
|
sort.Sort(pubs)
|
|
m := smartcontract.GetDefaultHonestNodeCount(size)
|
|
for i := range accs {
|
|
require.NoError(t, accs[i].ConvertMultisig(m, pubs))
|
|
}
|
|
|
|
s := NewMultiSigner(accs...)
|
|
for i := range pubs {
|
|
for j := range accs {
|
|
if pub := accs[j].PrivateKey().PublicKey(); pub.Equal(pubs[i]) {
|
|
require.Equal(t, pub, s.Single(i).Account().PrivateKey().PublicKey())
|
|
}
|
|
}
|
|
}
|
|
}
|