2022-10-06 19:06:03 +00:00
|
|
|
package devnetutils
|
2022-09-30 20:04:34 +00:00
|
|
|
|
2022-11-03 02:45:36 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
2022-09-30 20:04:34 +00:00
|
|
|
|
|
|
|
func TestUniqueIDFromEnode(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input string
|
|
|
|
expectedRes string
|
|
|
|
shouldError bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
expectedRes: "",
|
|
|
|
shouldError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "enode://11c368e7a2775951d66ff155a982844ccd5219d10b53e310001e1e40c6a4e76c2f6e42f39acc1e4015cd3b7428765125214d89b07ca5fa2c19ac94746fc360b0@127.0.0.1:63380?discport=0",
|
|
|
|
expectedRes: "enode://11c368e7a2775951d66ff155a982844ccd5219d10b53e310001e1e40c6a4e76c2f6e42f39acc1e4015cd3b7428765125214d89b07ca5fa2c19ac94746fc360b0@127.0.0.1:63380",
|
|
|
|
shouldError: false,
|
|
|
|
},
|
2023-06-04 19:53:05 +00:00
|
|
|
{
|
|
|
|
input: "enode://11c368e7a2775951d66ff155a982844ccd5219d10b53e310001e1e40c6a4e76c2f6e42f39acc1e4015cd3b7428765125214d89b07ca5fa2c19ac94746fc360b0@127.0.0.1:63380",
|
|
|
|
expectedRes: "enode://11c368e7a2775951d66ff155a982844ccd5219d10b53e310001e1e40c6a4e76c2f6e42f39acc1e4015cd3b7428765125214d89b07ca5fa2c19ac94746fc360b0@127.0.0.1:63380",
|
|
|
|
shouldError: false,
|
|
|
|
},
|
2022-09-30 20:04:34 +00:00
|
|
|
{
|
|
|
|
input: "enode://11c368e7a2775951d66ff155a982844ccd5219d10b53e310001e1e40c6a4e76c2f6e42f39acc1e4015cd3b7428765125214d89b07ca5fa2c19ac94746fc360b0@127.0.0.1:63380discport=0",
|
|
|
|
expectedRes: "",
|
|
|
|
shouldError: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
got, err := UniqueIDFromEnode(testCase.input)
|
|
|
|
if testCase.shouldError && err == nil {
|
|
|
|
t.Errorf("expected error to happen, got no error")
|
|
|
|
}
|
|
|
|
if !testCase.shouldError && err != nil {
|
|
|
|
t.Errorf("expected no error, got %s", err)
|
|
|
|
}
|
2022-11-03 02:45:36 +00:00
|
|
|
require.EqualValues(t, got, testCase.expectedRes)
|
2022-09-30 20:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-30 12:54:09 +00:00
|
|
|
|
2022-11-03 02:45:36 +00:00
|
|
|
func TestNamespaceAndSubMethodFromMethod(t *testing.T) {
|
|
|
|
expectedError := fmt.Errorf("invalid string to split")
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
method string
|
|
|
|
expectedNamespace string
|
|
|
|
expectedSubMethod string
|
|
|
|
shouldError bool
|
|
|
|
expectedError error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"eth_logs",
|
|
|
|
"eth",
|
|
|
|
"logs",
|
|
|
|
false,
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"ethNewHeads",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
true,
|
|
|
|
expectedError,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
true,
|
|
|
|
expectedError,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
namespace, subMethod, err := NamespaceAndSubMethodFromMethod(testCase.method)
|
|
|
|
require.EqualValues(t, testCase.expectedNamespace, namespace)
|
|
|
|
require.EqualValues(t, testCase.expectedSubMethod, subMethod)
|
|
|
|
require.EqualValues(t, testCase.expectedError, err)
|
|
|
|
if testCase.shouldError {
|
|
|
|
require.Errorf(t, testCase.expectedError, expectedError.Error())
|
2022-10-30 12:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-03 02:45:36 +00:00
|
|
|
|
2023-01-10 17:43:58 +00:00
|
|
|
func TestGenerateTopic(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
signature string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"random string", "0x0d9d89437ff2d48ce95779dc9457bc48287b75a573eddbf50954efac5a97c4b9"},
|
|
|
|
{"SubscriptionEvent()", "0x67abc7edb0ab50964ef0e90541d39366b9c69f6f714520f2ff4570059ee8ad80"},
|
|
|
|
{"", "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
got := GenerateTopic(testCase.signature)
|
|
|
|
require.EqualValues(t, testCase.expected, fmt.Sprintf("%s", got[0]))
|
|
|
|
}
|
|
|
|
}
|