2021-09-27 17:52:56 +00:00
|
|
|
package discovery
|
|
|
|
|
|
|
|
import (
|
2021-10-01 10:32:15 +00:00
|
|
|
"context"
|
2021-09-27 17:52:56 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEnodeToMultiAddr(t *testing.T) {
|
|
|
|
enr := "enr:-IS4QAmC_o1PMi5DbR4Bh4oHVyQunZblg4bTaottPtBodAhJZvxVlWW-4rXITPNg4mwJ8cW__D9FBDc9N4mdhyMqB-EBgmlkgnY0gmlwhIbRi9KJc2VjcDI1NmsxoQOevTdO6jvv3fRruxguKR-3Ge4bcFsLeAIWEDjrfaigNoN0Y3CCdl8"
|
2021-10-01 10:32:15 +00:00
|
|
|
|
2021-09-27 17:52:56 +00:00
|
|
|
parsedNode := enode.MustParse(enr)
|
|
|
|
expectedMultiAddr := "/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ"
|
2021-10-01 10:32:15 +00:00
|
|
|
actualMultiAddr, err := EnodeToMultiAddr(parsedNode)
|
2021-09-27 17:52:56 +00:00
|
|
|
require.NoError(t, err)
|
2021-10-01 10:32:15 +00:00
|
|
|
require.Equal(t, expectedMultiAddr, actualMultiAddr.String())
|
2021-09-27 17:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestRetrieveNodes uses a live connection, so it could be
|
|
|
|
// flaky, it should though pay for itself and should be fairly stable
|
|
|
|
func TestRetrieveNodes(t *testing.T) {
|
|
|
|
url := "enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"
|
|
|
|
|
2021-10-01 10:32:15 +00:00
|
|
|
nodes, err := RetrieveNodes(context.Background(), url)
|
2021-09-27 17:52:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, nodes)
|
|
|
|
}
|