Skip to content

Commit

Permalink
fix: fixing Topology file fetcher and related unit test (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
P1sar authored Mar 20, 2023
1 parent 54138a0 commit d619cda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func Run() error {
err = topologyStore.StoreTopology(networkTopology)
panicOnError(err)
}
log.Info().Msgf("Successfully loaded topology %+v", networkTopology)

privBytes, err := crypto.ConfigDecodeKey(configuration.RelayerConfig.MpcConfig.Key)
panicOnError(err)
Expand Down
4 changes: 1 addition & 3 deletions topology/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (ts *TopologyStore) StoreTopology(topology *NetworkTopology) error {
func (ts *TopologyStore) Topology() (*NetworkTopology, error) {
ts.mu.Lock()
defer ts.mu.Unlock()

t := &NetworkTopology{}
tb, err := ioutil.ReadFile(ts.path)
if err != nil {
Expand All @@ -57,6 +56,5 @@ func (ts *TopologyStore) Topology() (*NetworkTopology, error) {
if err != nil {
return nil, err
}

return nil, err
return t, err
}
11 changes: 8 additions & 3 deletions topology/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package topology_test

import (
"os"
"reflect"
"testing"

"github.com/ChainSafe/sygma-relayer/topology"
Expand Down Expand Up @@ -37,19 +38,23 @@ func (s *TopologyStoreTestSuite) Test_RetrieveNonExistentFile_Error() {
}

func (s *TopologyStoreTestSuite) Test_StoreAndRetrieveTopology() {
networkTopology, _ := topology.ProcessRawTopology(&topology.RawTopology{
networkTopology, err := topology.ProcessRawTopology(&topology.RawTopology{
Peers: []topology.RawPeer{
{PeerAddress: "/dns4/relayer2/tcp/9001/p2p/QmeTuMtdpPB7zKDgmobEwSvxodrf5aFVSmBXX3SQJVjJaT"},
{PeerAddress: "/dns4/relayer3/tcp/9002/p2p/QmYAYuLUPNwYEBYJaKHcE7NKjUhiUV8txx2xDXHvcYa1xK"},
{PeerAddress: "/dns4/relayer1/tcp/9000/p2p/QmcvEg7jGvuxdsUFRUiE4VdrL2P1Yeju5L83BsJvvXz7zX"},
},
Threshold: "2",
})
s.Nil(err)
s.NotNil(networkTopology)

err := s.topologyStore.StoreTopology(networkTopology)
err = s.topologyStore.StoreTopology(networkTopology)
s.Nil(err)

storedTopology, err := s.topologyStore.Topology()
s.Nil(err)
s.NotNil(storedTopology)

s.Equal(networkTopology, storedTopology)
s.True(reflect.DeepEqual(networkTopology, storedTopology))
}

0 comments on commit d619cda

Please sign in to comment.