-
Notifications
You must be signed in to change notification settings - Fork 761
Enable Cubist Signer integration #3965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 14 commits
dd5176e
ed0c5f8
dd99c36
9f61b1c
f106e92
de574a4
a7e895a
15a53f0
cc11cac
eeb3644
47e37fa
505c7fb
0d66c3a
f8837e8
97ffb21
7327d0f
bb56fd5
0b22c0a
d3e2677
193ccd4
bd77f88
5bc1bc0
64f1a1d
b55f05d
e85e815
c8b3714
c46209e
8a4cb7c
99c3a48
e23e982
e408079
c34b691
446b34f
de822f3
80ed485
a6d8add
649447d
d79916b
14c5525
fac9f79
8fa5525
0c15985
15db2ad
58cc0c1
f92d3be
270d59a
60526b1
9791ff8
ba4977a
3283340
d6512c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,29 +4,23 @@ | |
package config | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/ava-labs/avalanchego/chains" | ||
"github.com/ava-labs/avalanchego/config/node" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/proto/pb/signer" | ||
"github.com/ava-labs/avalanchego/snow/consensus/snowball" | ||
"github.com/ava-labs/avalanchego/subnets" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/rpcsigner" | ||
"github.com/ava-labs/avalanchego/utils/perms" | ||
) | ||
|
||
|
@@ -557,63 +551,34 @@ func TestGetSubnetConfigsFromFlags(t *testing.T) { | |
} | ||
} | ||
|
||
type signerServer struct { | ||
signer.UnimplementedSignerServer | ||
} | ||
|
||
func (*signerServer) PublicKey(context.Context, *signer.PublicKeyRequest) (*signer.PublicKeyResponse, error) { | ||
// for tests to pass, this must be the base64 encoding of a 32 byte public key | ||
// but it does not need to be associated with any private key | ||
bytes, err := base64.StdEncoding.DecodeString("j8Ndzc1I6EYWYUWAdhcwpQ1I2xX/i4fdwgJIaxbHlf9yQKMT0jlReiiLYsydgaS1") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &signer.PublicKeyResponse{ | ||
PublicKey: bytes, | ||
}, nil | ||
} | ||
|
||
func TestGetStakingSigner(t *testing.T) { | ||
testKey := "HLimS3vRibTMk9lZD4b+Z+GLuSBShvgbsu0WTLt2Kd4=" | ||
rpcServer := grpc.NewServer() | ||
defer rpcServer.GracefulStop() | ||
|
||
signer.RegisterSignerServer(rpcServer, &signerServer{}) | ||
|
||
listener, err := net.Listen("tcp", "[::1]:0") | ||
require.NoError(t, err) | ||
|
||
go func() { | ||
require.NoError(t, rpcServer.Serve(listener)) | ||
}() | ||
|
||
type config map[string]any | ||
type cfg map[string]any | ||
|
||
tests := []struct { | ||
name string | ||
viperKeys string | ||
config config | ||
expectedSignerType bls.Signer | ||
expectedErr error | ||
name string | ||
viperKeys string | ||
config cfg | ||
expectedSignerConfigType interface{} | ||
expectedErr error | ||
}{ | ||
{ | ||
name: "default-signer", | ||
expectedSignerType: &localsigner.LocalSigner{}, | ||
name: "default-signer", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove the kebab-casing in these test names? Plain strings work fine and there's no reason to format it this way IMO |
||
expectedSignerConfigType: node.SignerPathConfig{}, | ||
}, | ||
{ | ||
name: "ephemeral-signer", | ||
config: config{StakingEphemeralSignerEnabledKey: true}, | ||
expectedSignerType: &localsigner.LocalSigner{}, | ||
name: "ephemeral-signer", | ||
config: cfg{StakingEphemeralSignerEnabledKey: true}, | ||
expectedSignerConfigType: node.EphemeralSignerConfig{}, | ||
}, | ||
{ | ||
name: "content-key", | ||
config: config{StakingSignerKeyContentKey: testKey}, | ||
expectedSignerType: &localsigner.LocalSigner{}, | ||
name: "content-key", | ||
config: cfg{StakingSignerKeyContentKey: testKey}, | ||
expectedSignerConfigType: node.ContentKeyConfig{}, | ||
}, | ||
{ | ||
name: "file-key", | ||
config: config{ | ||
config: cfg{ | ||
StakingSignerKeyPathKey: func() string { | ||
filePath := filepath.Join(t.TempDir(), "signer.key") | ||
bytes, err := base64.StdEncoding.DecodeString(testKey) | ||
|
@@ -622,16 +587,16 @@ func TestGetStakingSigner(t *testing.T) { | |
return filePath | ||
}(), | ||
}, | ||
expectedSignerType: &localsigner.LocalSigner{}, | ||
expectedSignerConfigType: node.SignerPathConfig{}, | ||
}, | ||
{ | ||
name: "rpc-signer", | ||
config: config{StakingRPCSignerKey: listener.Addr().String()}, | ||
expectedSignerType: &rpcsigner.Client{}, | ||
name: "rpc-signer", | ||
config: cfg{StakingRPCSignerKey: "localhost"}, | ||
expectedSignerConfigType: node.RPCSignerConfig{}, | ||
}, | ||
{ | ||
name: "multiple-configurations-set", | ||
config: config{ | ||
config: cfg{ | ||
StakingEphemeralSignerEnabledKey: true, | ||
StakingSignerKeyContentKey: testKey, | ||
}, | ||
|
@@ -651,36 +616,14 @@ func TestGetStakingSigner(t *testing.T) { | |
v.Set(key, value) | ||
} | ||
|
||
config, cleanup, err := GetNodeConfig(context.Background(), v) | ||
defer func() { | ||
if err == nil { | ||
_ = cleanup() | ||
} | ||
}() | ||
config, err := GetNodeConfig(v) | ||
|
||
require.ErrorIs(err, tt.expectedErr) | ||
require.IsType(tt.expectedSignerType, config.StakingSigningKey) | ||
require.IsType(tt.expectedSignerConfigType, config.StakingSignerConfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just do an check on the expected config instead of just a type check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was slightly annoying because of the way temp dirs work in the test suite. Let me know if you think it's better or worse. |
||
}) | ||
} | ||
} | ||
|
||
func TestDefaultConfigInitializationUsesExistingDefaultKey(t *testing.T) { | ||
t.Setenv("HOME", t.TempDir()) | ||
|
||
require := require.New(t) | ||
v := setupViperFlags() | ||
|
||
config1, cleanup1, err := GetNodeConfig(context.Background(), v) | ||
defer func() { _ = cleanup1() }() | ||
require.NoError(err) | ||
|
||
config2, cleanup2, err := GetNodeConfig(context.Background(), v) | ||
defer func() { _ = cleanup2() }() | ||
require.NoError(err) | ||
|
||
require.Equal(config1.StakingSigningKey.PublicKey(), config2.StakingSigningKey.PublicKey()) | ||
} | ||
|
||
// setups config json file and writes content | ||
func setupConfigJSON(t *testing.T, rootPath string, value string) string { | ||
configFilePath := filepath.Join(rootPath, "config.json") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we don't need this type alias