mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-26 19:43:48 +00:00
keys: implement PublicKeys.Copy()
Implement convenient wrapper over explicit allocation and copying.
This commit is contained in:
parent
bbe02ac584
commit
8c18142e8a
4 changed files with 26 additions and 5 deletions
|
@ -1243,9 +1243,7 @@ func (bc *Blockchain) PoolTx(t *transaction.Transaction) error {
|
|||
|
||||
//GetStandByValidators returns validators from the configuration.
|
||||
func (bc *Blockchain) GetStandByValidators() keys.PublicKeys {
|
||||
res := make(keys.PublicKeys, len(bc.sbValidators))
|
||||
copy(res, bc.sbValidators)
|
||||
return res
|
||||
return bc.sbValidators.Copy()
|
||||
}
|
||||
|
||||
// GetValidators returns next block validators.
|
||||
|
|
|
@ -55,6 +55,13 @@ func (keys PublicKeys) Contains(pKey *PublicKey) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// Copy returns copy of keys.
|
||||
func (keys PublicKeys) Copy() PublicKeys {
|
||||
res := make(PublicKeys, len(keys))
|
||||
copy(res, keys)
|
||||
return res
|
||||
}
|
||||
|
||||
// Unique returns set of public keys.
|
||||
func (keys PublicKeys) Unique() PublicKeys {
|
||||
unique := PublicKeys{}
|
||||
|
|
|
@ -37,6 +37,23 @@ func TestEncodeDecodePublicKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPublicKeys_Copy(t *testing.T) {
|
||||
pubs := make(PublicKeys, 5)
|
||||
for i := range pubs {
|
||||
priv, err := NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
pubs[i] = priv.PublicKey()
|
||||
}
|
||||
|
||||
cp := pubs.Copy()
|
||||
priv, err := NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
cp[0] = priv.PublicKey()
|
||||
|
||||
require.NotEqual(t, pubs[0], cp[0])
|
||||
require.Equal(t, pubs[1:], cp[1:])
|
||||
}
|
||||
|
||||
func TestNewPublicKeyFromBytes(t *testing.T) {
|
||||
priv, err := NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -70,8 +70,7 @@ func TestParameterContext_AddSignatureMultisig(t *testing.T) {
|
|||
tx := getContractTx()
|
||||
c := NewParameterContext("Neo.Core.ContractTransaction", tx)
|
||||
privs, pubs := getPrivateKeys(t, 4)
|
||||
pubsCopy := make(keys.PublicKeys, len(pubs))
|
||||
copy(pubsCopy, pubs)
|
||||
pubsCopy := keys.PublicKeys(pubs).Copy()
|
||||
script, err := smartcontract.CreateMultiSigRedeemScript(3, pubsCopy)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
Loading…
Reference in a new issue