mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-08-25 18:01:07 +00:00
Three bugs the kernel suite never caught, because CI only compiles it. A peer's addresses were comma-joined into one argument, but the library inits that argument as a single multiaddress, so StoreQuery and PingPeer failed against any peer advertising more than one address. StoreQueryResponse could decode neither the Opt[T] wrapper objects the library renders results.Opt as, nor the integer arrays it renders seq[byte] as, so every store reply failed to unmarshal. Both shapes now decode, and the bare value still does. A context without a deadline sent timeoutMs=0, which chronos' withTimeout expires on immediately rather than treating as unbounded. StoreQuery with context.Background() could never have succeeded.
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package kernel
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
// The library parses its peer argument as a single multiaddress, so a peer
|
|
// advertising several addresses must still yield one dialable string.
|
|
func TestPeerAddrSendsOneMultiaddress(t *testing.T) {
|
|
id, err := peer.Decode("16Uiu2HAmVGHwfEi4kiNvuK6xVwGB2WeHoZNU1FgTUgZ8QvxiMqQw")
|
|
if err != nil {
|
|
t.Fatalf("Decode: %v", err)
|
|
}
|
|
|
|
peerInfo := peer.AddrInfo{ID: id, Addrs: []multiaddr.Multiaddr{
|
|
multiaddr.StringCast("/ip4/127.0.0.1/tcp/60000"),
|
|
multiaddr.StringCast("/ip4/10.0.0.1/tcp/60001"),
|
|
}}
|
|
|
|
got, err := peerAddr(peerInfo)
|
|
if err != nil {
|
|
t.Fatalf("peerAddr: %v", err)
|
|
}
|
|
|
|
want := "/ip4/127.0.0.1/tcp/60000/p2p/" + id.String()
|
|
if got != want {
|
|
t.Errorf("peerAddr() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestPeerAddrRejectsAddresslessPeer(t *testing.T) {
|
|
if _, err := peerAddr(peer.AddrInfo{}); err == nil {
|
|
t.Error("peerAddr() on a peer with no addresses returned no error")
|
|
}
|
|
}
|
|
|
|
// Zero milliseconds is not "no timeout": chronos expires immediately on it, so
|
|
// a context without a deadline has to fall back to the request timeout.
|
|
func TestContextTimeoutFallsBackToRequestTimeout(t *testing.T) {
|
|
if got, want := getContextTimeoutMilliseconds(context.Background()),
|
|
int(requestTimeout.Milliseconds()); got != want {
|
|
t.Errorf("getContextTimeoutMilliseconds(Background) = %d, want %d", got, want)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
if got := getContextTimeoutMilliseconds(ctx); got <= 0 || got > 60_000 {
|
|
t.Errorf("getContextTimeoutMilliseconds(1m) = %d, want (0, 60000]", got)
|
|
}
|
|
}
|