-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package registry | ||
|
||
type Node struct { | ||
Index int | ||
PublicKey []byte | ||
GrpcAddress string | ||
DisabledBlock *uint64 | ||
// Maybe add mTLS cert here | ||
} | ||
|
||
type NodeRegistry interface { | ||
GetNodes() ([]Node, error) | ||
// OnChange() | ||
} | ||
|
||
// TODO: Delete this or move to a test file | ||
|
||
type FixedNodeRegistry struct { | ||
nodes []Node | ||
} | ||
|
||
func NewFixedNodeRegistry(nodes []Node) *FixedNodeRegistry { | ||
return &FixedNodeRegistry{nodes: nodes} | ||
} | ||
|
||
func (r *FixedNodeRegistry) GetNodes() ([]Node, error) { | ||
return r.nodes, nil | ||
} | ||
|
||
func (f *FixedNodeRegistry) AddNode(node Node) { | ||
f.nodes = append(f.nodes, node) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package replication | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/stretchr/testify/require" | ||
"github.com/xmtp/xmtp-node-go/pkg/replication/registry" | ||
test "github.com/xmtp/xmtp-node-go/pkg/testing" | ||
) | ||
|
||
func NewTestServer(t *testing.T, registry registry.NodeRegistry) *Server { | ||
log := test.NewLog(t) | ||
privateKey, err := crypto.GenerateKey() | ||
require.NoError(t, err) | ||
|
||
server, err := New(context.Background(), log, Options{ | ||
PrivateKeyString: hex.EncodeToString(crypto.FromECDSA(privateKey)), | ||
API: ApiOptions{ | ||
Port: 0, | ||
}, | ||
}, registry) | ||
require.NoError(t, err) | ||
|
||
return server | ||
} | ||
|
||
func TestCreateServer(t *testing.T) { | ||
registry := registry.NewFixedNodeRegistry([]registry.Node{}) | ||
server1 := NewTestServer(t, registry) | ||
server2 := NewTestServer(t, registry) | ||
require.NotEqual(t, server1.Addr(), server2.Addr()) | ||
} |