erigon-pulse/cmd/devnet/devnetutils/utils_test.go
Leonard Chinonso bb780a06d3
Tested functionalities for request_generator (#5905)
- Added tests for request_generator in devnet
- Added tests for request_generator in rpctests
2022-10-30 19:54:09 +07:00

84 lines
1.9 KiB
Go

package devnetutils
import "testing"
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,
},
{
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)
}
if got != testCase.expectedRes {
t.Errorf("expected %s, got %s", testCase.expectedRes, got)
}
}
}
func TestParseResponse(t *testing.T) {
type Person struct {
Name string
Age int
}
testCases := []struct {
input interface{}
expected string
}{
{
Person{
Name: "Leonard",
Age: 10,
},
`{"Name":"Leonard","Age":10}`,
},
{
struct {
Person struct {
Name string
Age int
}
WorkID string
}{
Person: Person{
Name: "Uzi",
Age: 23,
},
WorkID: "123456",
},
`{"Person":{"Name":"Uzi","Age":23},"WorkID":"123456"}`,
},
}
for _, testCase := range testCases {
got, _ := ParseResponse(testCase.input)
if got != testCase.expected {
t.Errorf("expected: %v, got %v", testCase.expected, got)
}
}
}