-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(serverv2): integrate gRPC (#21038)
Co-authored-by: Marko <marko@baricevic.me> Co-authored-by: marbar3778 <marbar3778@yahoo.com> (cherry picked from commit 8b47141) # Conflicts: # schema/appdata/mux_test.go # server/v2/cometbft/server.go # server/v2/go.mod
- Loading branch information
1 parent
3135f41
commit b4320ee
Showing
11 changed files
with
330 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package appdata | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestListenerMux(t *testing.T) { | ||
t.Run("empty", func(t *testing.T) { | ||
listener := ListenerMux(Listener{}, Listener{}) | ||
|
||
if listener.InitializeModuleData != nil { | ||
t.Error("expected nil") | ||
} | ||
if listener.StartBlock != nil { | ||
t.Error("expected nil") | ||
} | ||
if listener.OnTx != nil { | ||
t.Error("expected nil") | ||
} | ||
if listener.OnEvent != nil { | ||
t.Error("expected nil") | ||
} | ||
if listener.OnKVPair != nil { | ||
t.Error("expected nil") | ||
} | ||
if listener.OnObjectUpdate != nil { | ||
t.Error("expected nil") | ||
} | ||
if listener.Commit != nil { | ||
t.Error("expected nil") | ||
} | ||
}) | ||
|
||
t.Run("all called once", func(t *testing.T) { | ||
var calls []string | ||
onCall := func(name string, i int, _ Packet) { | ||
calls = append(calls, fmt.Sprintf("%s %d", name, i)) | ||
} | ||
|
||
res := ListenerMux(callCollector(1, onCall), callCollector(2, onCall)) | ||
|
||
callAllCallbacksOnces(t, res) | ||
|
||
checkExpectedCallOrder(t, calls, []string{ | ||
"InitializeModuleData 1", | ||
"InitializeModuleData 2", | ||
"StartBlock 1", | ||
"StartBlock 2", | ||
"OnTx 1", | ||
"OnTx 2", | ||
"OnEvent 1", | ||
"OnEvent 2", | ||
"OnKVPair 1", | ||
"OnKVPair 2", | ||
"OnObjectUpdate 1", | ||
"OnObjectUpdate 2", | ||
"Commit 1", | ||
"Commit 2", | ||
}) | ||
}) | ||
} | ||
|
||
func callAllCallbacksOnces(t *testing.T, listener Listener) { | ||
t.Helper() | ||
if err := listener.InitializeModuleData(ModuleInitializationData{}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := listener.StartBlock(StartBlockData{}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := listener.OnTx(TxData{}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := listener.OnEvent(EventData{}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := listener.OnKVPair(KVPairData{}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := listener.OnObjectUpdate(ObjectUpdateData{}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := listener.Commit(CommitData{}); err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func callCollector(i int, onCall func(string, int, Packet)) Listener { | ||
return Listener{ | ||
InitializeModuleData: func(ModuleInitializationData) error { | ||
onCall("InitializeModuleData", i, nil) | ||
return nil | ||
}, | ||
StartBlock: func(StartBlockData) error { | ||
onCall("StartBlock", i, nil) | ||
return nil | ||
}, | ||
OnTx: func(TxData) error { | ||
onCall("OnTx", i, nil) | ||
return nil | ||
}, | ||
OnEvent: func(EventData) error { | ||
onCall("OnEvent", i, nil) | ||
return nil | ||
}, | ||
OnKVPair: func(KVPairData) error { | ||
onCall("OnKVPair", i, nil) | ||
return nil | ||
}, | ||
OnObjectUpdate: func(ObjectUpdateData) error { | ||
onCall("OnObjectUpdate", i, nil) | ||
return nil | ||
}, | ||
Commit: func(CommitData) error { | ||
onCall("Commit", i, nil) | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func checkExpectedCallOrder(t *testing.T, actual, expected []string) { | ||
t.Helper() | ||
if len(actual) != len(expected) { | ||
t.Fatalf("expected %d calls, got %d", len(expected), len(actual)) | ||
} | ||
|
||
for i := range actual { | ||
if actual[i] != expected[i] { | ||
t.Errorf("expected %q, got %q", expected[i], actual[i]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.