From b3a1fb134d657c291f866a5ed0dcc39f6a22256c Mon Sep 17 00:00:00 2001 From: Minh Huy Tran Date: Fri, 16 Feb 2024 13:47:13 +0100 Subject: [PATCH] fix(CI): change code to fix CI Signed-off-by: Minh Huy Tran --- channel/test/app_randomizer_internal_test.go | 4 ++-- client/adjudicate.go | 2 +- client/proposal.go | 2 +- client/virtual_channel.go | 3 ++- wallet/test/address.go | 4 ++-- wallet/test/wallet.go | 2 +- wallet/test/walletbench.go | 6 +++--- wire/cache_internal_test.go | 2 +- wire/net/simple/address_test.go | 2 +- wire/net/simple/dialer_internal_test.go | 5 +++-- wire/net/simple/simple_exchange_addr_internal_test.go | 11 ++++++----- wire/perunio/string.go | 2 +- wire/perunio/string_internal_test.go | 2 +- wire/perunio/wire_internal_test.go | 2 +- 14 files changed, 26 insertions(+), 23 deletions(-) diff --git a/channel/test/app_randomizer_internal_test.go b/channel/test/app_randomizer_internal_test.go index 1314f6e7..618c78ea 100644 --- a/channel/test/app_randomizer_internal_test.go +++ b/channel/test/app_randomizer_internal_test.go @@ -28,13 +28,13 @@ func TestAppRandomizerSet(t *testing.T) { assert.NotNil(t, appRandomizer, "appRandomizer should be default initialized") assert.False(t, isAppRandomizerSet, "isAppRandomizerSet should be defaulted to false") - old := appRandomizer + // old := appRandomizer assert.NotPanics(t, func() { SetAppRandomizer(&MockAppRandomizer{}) }, "first SetAppRandomizer() should work") assert.True(t, isAppRandomizerSet, "isAppRandomizerSet should be true") assert.NotNil(t, appRandomizer, "appRandomizer should not be nil") // assert.False(t, old == appRandomizer, "appRandomizer should have changed") - old = appRandomizer + old := appRandomizer assert.Panics(t, func() { SetAppRandomizer(&MockAppRandomizer{}) }, "second SetAppRandomizer() should panic") assert.True(t, isAppRandomizerSet, "isAppRandomizerSet should be true") assert.NotNil(t, appRandomizer, "appRandomizer should not be nil") diff --git a/client/adjudicate.go b/client/adjudicate.go index 31cff043..b607112b 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -270,7 +270,7 @@ func (c *Channel) Settle(ctx context.Context) (err error) { // Withdraw. err = c.withdraw(ctx) if err != nil { - return + return err } // Set phase `Withdrawn`. diff --git a/client/proposal.go b/client/proposal.go index faef295a..6b7455a3 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -396,7 +396,7 @@ func (c *Client) validTwoPartyProposal( multiLedger := multi.IsMultiLedgerAssets(proposal.Base().InitBals.Assets) appChannel := !channel.IsNoApp(proposal.Base().App) if multiLedger && appChannel { - return fmt.Errorf("multi-ledger app channel not supported") + return errors.New("multi-ledger app channel not supported") } peers := c.proposalPeers(proposal) diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 98723caf..c903fc88 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -348,7 +348,8 @@ func (c *Client) matchFundingProposal(ctx context.Context, a, b interface{}) boo } go func() { - err := virtual.watchVirtual() //nolint:contextcheck // The context will be derived from the channel context. + // The context will be derived from the channel context. + err := virtual.watchVirtual() //nolint:contextcheck c.log.Debugf("channel %v: watcher stopped: %v", virtual.ID(), err) }() return true diff --git a/wallet/test/address.go b/wallet/test/address.go index 99b9efde..ff6cb1f8 100644 --- a/wallet/test/address.go +++ b/wallet/test/address.go @@ -34,8 +34,8 @@ func TestAddress(t *testing.T, s *Setup) { //nolint:revive // `test.Test...` stu // Test Address.String. nullString := null.String() addrString := addr.String() - assert.Greater(t, len(nullString), 0) - assert.Greater(t, len(addrString), 0) + assert.NotEmpty(t, len(nullString), 0) + assert.NotEmpty(t, len(addrString), 0) assert.NotEqual(t, addrString, nullString) // Test Address.Equals. diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index 804182ce..83d46907 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -75,7 +75,7 @@ func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive / t.Error("Verification of invalid signature should produce error or return false") } // Expand the signature and check for error - // nolint:gocritic + //nolint:gocritic tampered = append(sig, 0) valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()) if valid && err != nil { diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index 0630769b..5ba272ba 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -30,7 +30,7 @@ func GenericAccountBenchmark(b *testing.B, s *Setup) { func benchAccountSign(b *testing.B, s *Setup) { b.Helper() perunAcc, err := s.Wallet.Unlock(s.AddressInWallet) - require.Nil(b, err) + require.NoError(b, err) for n := 0; n < b.N; n++ { _, err := perunAcc.SignData(s.DataToSign) @@ -56,9 +56,9 @@ func benchBackendVerifySig(b *testing.B, s *Setup) { // We dont want to measure the SignDataWithPW here, just need it for the verification b.StopTimer() perunAcc, err := s.Wallet.Unlock(s.AddressInWallet) - require.Nil(b, err) + require.NoError(b, err) signature, err := perunAcc.SignData(s.DataToSign) - require.Nil(b, err) + require.NoError(b, err) b.StartTimer() for n := 0; n < b.N; n++ { diff --git a/wire/cache_internal_test.go b/wire/cache_internal_test.go index 8d45d6b7..055ec498 100644 --- a/wire/cache_internal_test.go +++ b/wire/cache_internal_test.go @@ -56,7 +56,7 @@ func TestCache(t *testing.T) { assert.Equal(2, c.Size()) empty := c.Messages(func(*Envelope) bool { return false }) - assert.Len(empty, 0) + assert.Empty(empty, 0) c.Release(&isPing) assert.False(c.Put(ping2), "Put into cache with canceled predicate") diff --git a/wire/net/simple/address_test.go b/wire/net/simple/address_test.go index c0297797..7c3a0353 100644 --- a/wire/net/simple/address_test.go +++ b/wire/net/simple/address_test.go @@ -27,6 +27,6 @@ func TestAddress(t *testing.T) { test.TestAddressImplementation(t, func() wire.Address { return simple.NewAddress("") }, func(rng *rand.Rand) wire.Address { - return simple.NewRandomAddress(rng) + return test.NewRandomAddress(rng) }) } diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index 9f32f2cd..a493eb9f 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -33,6 +33,7 @@ import ( "perun.network/go-perun/wire" perunio "perun.network/go-perun/wire/perunio/serializer" + wiretest "perun.network/go-perun/wire/test" ctxtest "polycry.pt/poly-go/context/test" "polycry.pt/poly-go/test" ) @@ -76,7 +77,7 @@ func TestDialer_Dial(t *testing.T) { timeout := 100 * time.Millisecond rng := test.Prng(t) lhost := "127.0.0.1:7357" - laddr := NewRandomAccount(rng).Address() + laddr := wiretest.NewRandomAccount(rng).Address() commonName := "127.0.0.1" sans := []string{"127.0.0.1", "localhost"} @@ -90,7 +91,7 @@ func TestDialer_Dial(t *testing.T) { ser := perunio.Serializer() d := NewTCPDialer(timeout, dConfig) d.Register(laddr, lhost) - daddr := NewRandomAccount(rng).Address() + daddr := wiretest.NewRandomAccount(rng).Address() defer d.Close() t.Run("happy", func(t *testing.T) { diff --git a/wire/net/simple/simple_exchange_addr_internal_test.go b/wire/net/simple/simple_exchange_addr_internal_test.go index 051e27ed..71b9ebb2 100644 --- a/wire/net/simple/simple_exchange_addr_internal_test.go +++ b/wire/net/simple/simple_exchange_addr_internal_test.go @@ -27,6 +27,7 @@ import ( "perun.network/go-perun/wire" wirenet "perun.network/go-perun/wire/net" perunio "perun.network/go-perun/wire/perunio/serializer" + wiretest "perun.network/go-perun/wire/test" ctxtest "polycry.pt/poly-go/context/test" "polycry.pt/poly-go/test" ) @@ -37,7 +38,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := wirenet.ExchangeAddrsPassive(context.Background(), NewRandomAccount(rng), a) + addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccount(rng), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -46,7 +47,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := NewRandomAccount(rng), NewRandomAccount(rng) + account0, account1 := wiretest.NewRandomAccount(rng), wiretest.NewRandomAccount(rng) var wg sync.WaitGroup wg.Add(1) @@ -71,8 +72,8 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - ctxtest.AssertTerminates(t, 2*timeout, func() { - addr, err := wirenet.ExchangeAddrsPassive(ctx, NewRandomAccount(rng), a) + ctxtest.AssertTerminates(t, 20*timeout, func() { + addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccount(rng), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -80,7 +81,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := NewRandomAccount(rng) + acc := wiretest.NewRandomAccount(rng) conn := newMockConn() conn.recvQueue <- newRandomEnvelope(rng, wire.NewPingMsg()) addr, err := wirenet.ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/perunio/string.go b/wire/perunio/string.go index 277bea22..292c0a83 100644 --- a/wire/perunio/string.go +++ b/wire/perunio/string.go @@ -42,7 +42,7 @@ func encodeString(w io.Writer, s string) error { return errors.Wrap(err, "failed to write string") } -// decodeString reads the length as uint16 and the the string itself from the io.Reader. +// decodeString reads the length as uint16 and the string itself from the io.Reader. func decodeString(r io.Reader, s *string) error { var l uint16 if err := binary.Read(r, byteOrder, &l); err != nil { diff --git a/wire/perunio/string_internal_test.go b/wire/perunio/string_internal_test.go index 7df9d020..4310ec9a 100644 --- a/wire/perunio/string_internal_test.go +++ b/wire/perunio/string_internal_test.go @@ -54,7 +54,7 @@ func TestEncodeDecodeString(t *testing.T) { }) t.Run("too long string", func(t *testing.T) { - tooLong := string(append(uint16buf, 42)) // nolint: makezero + tooLong := string(append(uint16buf, 42)) //nolint: makezero var buf bytes.Buffer assert.Error(encodeString(&buf, tooLong)) assert.Zero(buf.Len(), "nothing should have been written to the stream") diff --git a/wire/perunio/wire_internal_test.go b/wire/perunio/wire_internal_test.go index f8c2d001..4d9640a4 100644 --- a/wire/perunio/wire_internal_test.go +++ b/wire/perunio/wire_internal_test.go @@ -85,7 +85,7 @@ func TestEncodeDecode(t *testing.T) { } go func() { - a.Nil(Encode(w, values...), "failed to encode values") + a.NoError(Encode(w, values...), "failed to encode values") }() d := make([]interface{}, len(values))