mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* Ran gopls modernize to fix everything go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... * Override rules_go provided dependency for golang.org/x/tools to v0.38.0. To update this, checked out rules_go, then ran `bazel run //go/tools/releaser -- upgrade-dep -mirror=false org_golang_x_tools` and copied the patches. * Fix buildtag violations and ignore buildtag violations in external * Introduce modernize analyzer package. * Add modernize "any" analyzer. * Fix violations of any analyzer * Add modernize "appendclipped" analyzer. * Fix violations of appendclipped * Add modernize "bloop" analyzer. * Add modernize "fmtappendf" analyzer. * Add modernize "forvar" analyzer. * Add modernize "mapsloop" analyzer. * Add modernize "minmax" analyzer. * Fix violations of minmax analyzer * Add modernize "omitzero" analyzer. * Add modernize "rangeint" analyzer. * Fix violations of rangeint. * Add modernize "reflecttypefor" analyzer. * Fix violations of reflecttypefor analyzer. * Add modernize "slicescontains" analyzer. * Add modernize "slicessort" analyzer. * Add modernize "slicesdelete" analyzer. This is disabled by default for now. See https://go.dev/issue/73686. * Add modernize "stringscutprefix" analyzer. * Add modernize "stringsbuilder" analyzer. * Fix violations of stringsbuilder analyzer. * Add modernize "stringsseq" analyzer. * Add modernize "testingcontext" analyzer. * Add modernize "waitgroup" analyzer. * Changelog fragment * gofmt * gazelle * Add modernize "newexpr" analyzer. * Disable newexpr until go1.26 * Add more details in WORKSPACE on how to update the override * @nalepae feedback on min() * gofmt * Fix violations of forvar
93 lines
3.0 KiB
Go
93 lines
3.0 KiB
Go
package local
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/OffchainLabs/prysm/v7/async/event"
|
|
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
|
"github.com/OffchainLabs/prysm/v7/testing/assert"
|
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
|
mock "github.com/OffchainLabs/prysm/v7/validator/accounts/testing"
|
|
"github.com/google/uuid"
|
|
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
|
|
)
|
|
|
|
func TestLocalKeymanager_reloadAccountsFromKeystore_MismatchedNumKeys(t *testing.T) {
|
|
password := "Passw03rdz293**%#2"
|
|
wallet := &mock.Wallet{
|
|
Files: make(map[string]map[string][]byte),
|
|
AccountPasswords: make(map[string]string),
|
|
WalletPassword: password,
|
|
}
|
|
dr := &Keymanager{
|
|
wallet: wallet,
|
|
}
|
|
accountsStore := &accountStore{
|
|
PrivateKeys: [][]byte{[]byte("hello")},
|
|
PublicKeys: [][]byte{[]byte("hi"), []byte("world")},
|
|
}
|
|
encodedStore, err := json.MarshalIndent(accountsStore, "", "\t")
|
|
require.NoError(t, err)
|
|
encryptor := keystorev4.New()
|
|
cryptoFields, err := encryptor.Encrypt(encodedStore, dr.wallet.Password())
|
|
require.NoError(t, err)
|
|
id, err := uuid.NewRandom()
|
|
require.NoError(t, err)
|
|
keystore := &AccountsKeystoreRepresentation{
|
|
Crypto: cryptoFields,
|
|
ID: id.String(),
|
|
Version: encryptor.Version(),
|
|
Name: encryptor.Name(),
|
|
}
|
|
err = dr.reloadAccountsFromKeystore(keystore)
|
|
assert.ErrorContains(t, "do not match", err)
|
|
}
|
|
|
|
func TestLocalKeymanager_reloadAccountsFromKeystore(t *testing.T) {
|
|
password := "Passw03rdz293**%#2"
|
|
wallet := &mock.Wallet{
|
|
Files: make(map[string]map[string][]byte),
|
|
AccountPasswords: make(map[string]string),
|
|
WalletPassword: password,
|
|
}
|
|
dr := &Keymanager{
|
|
wallet: wallet,
|
|
accountsChangedFeed: new(event.Feed),
|
|
}
|
|
|
|
numAccounts := 20
|
|
privKeys := make([][]byte, numAccounts)
|
|
pubKeys := make([][]byte, numAccounts)
|
|
for i := range numAccounts {
|
|
privKey, err := bls.RandKey()
|
|
require.NoError(t, err)
|
|
privKeys[i] = privKey.Marshal()
|
|
pubKeys[i] = privKey.PublicKey().Marshal()
|
|
}
|
|
|
|
accountsStore, err := dr.CreateAccountsKeystore(t.Context(), privKeys, pubKeys)
|
|
require.NoError(t, err)
|
|
require.NoError(t, dr.reloadAccountsFromKeystore(accountsStore))
|
|
|
|
// Check that the public keys were added to the public keys cache.
|
|
for i, keyBytes := range pubKeys {
|
|
require.Equal(t, bytesutil.ToBytes48(keyBytes), orderedPublicKeys[i])
|
|
}
|
|
|
|
// Check that the secret keys were added to the secret keys cache.
|
|
lock.RLock()
|
|
defer lock.RUnlock()
|
|
for i, keyBytes := range privKeys {
|
|
privKey, ok := secretKeysCache[bytesutil.ToBytes48(pubKeys[i])]
|
|
require.Equal(t, true, ok)
|
|
require.Equal(t, bytesutil.ToBytes48(keyBytes), bytesutil.ToBytes48(privKey.Marshal()))
|
|
}
|
|
|
|
// Check the key was added to the global accounts store.
|
|
require.Equal(t, numAccounts, len(dr.accountsStore.PublicKeys))
|
|
require.Equal(t, numAccounts, len(dr.accountsStore.PrivateKeys))
|
|
assert.DeepEqual(t, dr.accountsStore.PublicKeys[0], pubKeys[0])
|
|
}
|