Skip to content

Commit

Permalink
fix tests that rely on GenesisID
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Oct 25, 2023
1 parent d7ee837 commit 5db8ed6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion components/mocks/mockNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
// MockNetwork is a dummy network that doesn't do anything
type MockNetwork struct {
network.GossipNode
GenesisID string
}

// Broadcast - unused function
Expand Down Expand Up @@ -108,5 +109,8 @@ func (network *MockNetwork) GetHTTPRequestConnection(request *http.Request) (con

// GetGenesisID - empty implementation
func (network *MockNetwork) GetGenesisID() string {
return "mocknet"
if network.GenesisID == "" {
return "mocknet"
}
return network.GenesisID
}
4 changes: 2 additions & 2 deletions network/wsNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ func (wn *WebsocketNetwork) Start() {
}
}
}
// if the network has a public address, use that as the name for connection deduplication
if wn.config.PublicAddress != "" {
// if the network has a public address or a libp2p peer ID, use that as the name for connection deduplication
if wn.config.PublicAddress != "" || (wn.peerID != "" && wn.peerIDSigner != nil) {
wn.RegisterHandlers(identityHandlers)
}
if wn.identityScheme == nil {
Expand Down
13 changes: 10 additions & 3 deletions rpcs/blockService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func TestRedirectFallbackArchiver(t *testing.T) {

net1 := &httpTestPeerSource{}
net2 := &httpTestPeerSource{}
net1.GenesisID = "test-genesis-ID"
net2.GenesisID = "test-genesis-ID"

config := config.GetDefaultLocal()
// Need to enable block service fallbacks
Expand Down Expand Up @@ -253,6 +255,8 @@ func TestRedirectFallbackEndpoints(t *testing.T) {

net1 := &httpTestPeerSource{}
net2 := &httpTestPeerSource{}
net1.GenesisID = "test-genesis-ID"
net2.GenesisID = "test-genesis-ID"

nodeA := &basicRPCNode{}
nodeB := &basicRPCNode{}
Expand All @@ -265,8 +269,8 @@ func TestRedirectFallbackEndpoints(t *testing.T) {
// Set the first to a bad address, the second to self, and the third to the one that has the block.
// If RR is right, should succeed.
config.BlockServiceCustomFallbackEndpoints = fmt.Sprintf("://badaddress,%s,%s", nodeA.rootURL(), nodeB.rootURL())
bs1 := MakeBlockService(log, config, ledger1, net1, "{genesisID}")
bs2 := MakeBlockService(log, config, ledger2, net2, "{genesisID}")
bs1 := MakeBlockService(log, config, ledger1, net1, "test-genesis-ID")
bs2 := MakeBlockService(log, config, ledger2, net2, "test-genesis-ID")

nodeA.RegisterHTTPHandler(BlockServiceBlockPath, bs1)
nodeB.RegisterHTTPHandler(BlockServiceBlockPath, bs2)
Expand Down Expand Up @@ -316,6 +320,8 @@ func TestRedirectOnFullCapacity(t *testing.T) {

net1 := &httpTestPeerSource{}
net2 := &httpTestPeerSource{}
net1.GenesisID = "test-genesis-ID"
net2.GenesisID = "test-genesis-ID"

config := config.GetDefaultLocal()
// Need to enable block service fallbacks
Expand Down Expand Up @@ -494,12 +500,13 @@ func TestRedirectExceptions(t *testing.T) {
addBlock(t, ledger1)

net1 := &httpTestPeerSource{}
net1.GenesisID = "test-genesis-ID"

config := config.GetDefaultLocal()
// Need to enable block service fallbacks
config.EnableBlockServiceFallbackToArchiver = true

bs1 := MakeBlockService(log, config, ledger1, net1, "{genesisID}")
bs1 := MakeBlockService(log, config, ledger1, net1, "test-genesis-ID")

nodeA := &basicRPCNode{}

Expand Down
8 changes: 2 additions & 6 deletions rpcs/txSyncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"math/rand"
"net/http"
"net/rpc"
"strings"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -170,9 +169,6 @@ type mockClientAggregator struct {
func (mca *mockClientAggregator) GetPeers(options ...network.PeerOption) []network.Peer {
return mca.peers
}
func (mca *mockClientAggregator) SubstituteGenesisID(rawURL string) string {
return strings.Replace(rawURL, "{genesisID}", "test genesisID", -1)
}

const numberOfPeers = 10

Expand Down Expand Up @@ -283,7 +279,7 @@ func TestSync(t *testing.T) {

runner := mockRunner{failWithNil: false, failWithError: false, txgroups: pool.PendingTxGroups()[len(pool.PendingTxGroups())-1:], done: make(chan *rpc.Call)}
client := mockRPCClient{client: &runner, rootURL: nodeAURL, log: logging.TestingLog(t)}
clientAgg := mockClientAggregator{peers: []network.Peer{&client}}
clientAgg := mockClientAggregator{peers: []network.Peer{&client}, MockNetwork: mocks.MockNetwork{GenesisID: "test genesisID"}}
handler := mockHandler{}
syncerPool := makeMockPendingTxAggregate(3)
syncer := MakeTxSyncer(syncerPool, &clientAgg, &handler, testSyncInterval, testSyncTimeout, config.GetDefaultLocal().TxSyncServeResponseSize)
Expand Down Expand Up @@ -322,7 +318,7 @@ func TestStartAndStop(t *testing.T) {

runner := mockRunner{failWithNil: false, failWithError: false, txgroups: pool.PendingTxGroups()[len(pool.PendingTxGroups())-1:], done: make(chan *rpc.Call)}
client := mockRPCClient{client: &runner, rootURL: nodeAURL, log: logging.TestingLog(t)}
clientAgg := mockClientAggregator{peers: []network.Peer{&client}}
clientAgg := mockClientAggregator{peers: []network.Peer{&client}, MockNetwork: mocks.MockNetwork{GenesisID: "test genesisID"}}
handler := mockHandler{}

syncerPool := makeMockPendingTxAggregate(0)
Expand Down

0 comments on commit 5db8ed6

Please sign in to comment.