Skip to content

Commit

Permalink
chore: Sort imports, gofmt files
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Koehler <[email protected]>
  • Loading branch information
sophia1ch committed Dec 18, 2024
1 parent 99836d7 commit 408a062
Show file tree
Hide file tree
Showing 97 changed files with 174 additions and 88 deletions.
2 changes: 1 addition & 1 deletion apps/payment/app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestApp_ValidInit(t *testing.T) {
assert.Panics(func() { app.ValidInit(nil, wrongdata) }) //nolint:errcheck

data := &channel.State{Data: Data()}
assert.Nil(app.ValidInit(nil, data))
assert.NoError(app.ValidInit(nil, data))
}

func TestApp_ValidTransition(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions apps/payment/randomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package payment

import (
"math/rand"

"perun.network/go-perun/wallet"

"perun.network/go-perun/channel"
Expand Down
2 changes: 1 addition & 1 deletion apps/payment/resolver_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestData(t *testing.T) {
assert.NotPanics(func() {
data := Data()
_, err := data.MarshalBinary()
assert.Nil(err)
assert.NoError(err)
})

assert.NotPanics(func() {
Expand Down
1 change: 1 addition & 0 deletions backend/sim/channel/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package channel

import (
"math/rand"

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
)
Expand Down
14 changes: 7 additions & 7 deletions backend/sim/wallet/wallet_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func TestSignatureSerialize(t *testing.T) {
s := new(big.Int).SetBytes(sBytes)

sig, err1 := serializeSignature(r, s)
a.Nil(err1, "Serialization should not fail")
a.Equal(curve.Params().BitSize/4, len(sig), "Signature has wrong size")
a.NoError(err1, "Serialization should not fail")
a.Len(sig, curve.Params().BitSize/4, "Signature has wrong size")
R, S, err2 := deserializeSignature(sig)

a.Nil(err2, "Deserialization should not fail")
a.NoError(err2, "Deserialization should not fail")
a.Equal(r, R, "Serialized and deserialized r values should be equal")
a.Equal(s, S, "Serialized and deserialized s values should be equal")
}
Expand Down Expand Up @@ -80,10 +80,10 @@ func TestGenericTests(t *testing.T) {
addrStrLen := addrLen*2 + 2 // hex encoded and prefixed with 0x
str0 := addr0.String()
str1 := addr1.String()
assert.Equal(
t, addrStrLen, len(str0), "First address '%v' has wrong length", str0)
assert.Equal(
t, addrStrLen, len(str1), "Second address '%v' has wrong length", str1)
assert.Len(
t, str0, addrStrLen, "First address '%v' has wrong length", str0)
assert.Len(
t, str1, addrStrLen, "Second address '%v' has wrong length", str1)
assert.NotEqual(
t, str0, str1, "Printed addresses are unlikely to be identical")
}
Expand Down
1 change: 1 addition & 0 deletions channel/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io"
"log"
"math/big"

"perun.network/go-perun/wallet"

"perun.network/go-perun/wire/perunio"
Expand Down
3 changes: 2 additions & 1 deletion channel/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package channel_test
import (
"math/big"
"math/rand"
"perun.network/go-perun/wallet"
"testing"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
3 changes: 2 additions & 1 deletion channel/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package channel

import (
"encoding"
"github.com/pkg/errors"
"io"

"github.com/pkg/errors"

"perun.network/go-perun/wire/perunio"
)

Expand Down
1 change: 1 addition & 0 deletions channel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package channel

import (
"errors"

"perun.network/go-perun/wallet"
)

Expand Down
1 change: 1 addition & 0 deletions channel/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package channel

import (
"fmt"

"perun.network/go-perun/wallet"

"github.com/pkg/errors"
Expand Down
3 changes: 2 additions & 1 deletion channel/errors_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package channel

import (
"errors"
"perun.network/go-perun/wallet"
"testing"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/assert"
)

Expand Down
6 changes: 3 additions & 3 deletions channel/funder_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestAssetFundingError(t *testing.T) {
assert.Equal(Index(2), perr.TimedOutPeers[1])
assert.Equal(Index(3), perr.TimedOutPeers[2])
assert.Equal(Index(4), perr.TimedOutPeers[3])
assert.Equal(4, len(perr.TimedOutPeers))
assert.Equal(perr.Error(), "Funding Error on asset [42] peers: [1], [2], [3], [4], did not fund channel in time")
assert.Len(perr.TimedOutPeers, 4)
assert.Equal("Funding Error on asset [42] peers: [1], [2], [3], [4], did not fund channel in time", perr.Error())
assert.False(IsAssetFundingError(errors.New("not a asset funding error")))
}

Expand All @@ -61,7 +61,7 @@ func TestFundingTimeoutError(t *testing.T) {
assert.Equal(Index(1), perr.Errors[2].TimedOutPeers[0])
assert.Equal(Index(3), perr.Errors[2].TimedOutPeers[1])
assert.Equal(3, len(perr.Errors))
assert.Equal(perr.Error(), "Funding Error on asset [42] peers: [1], [2], did not fund channel in time; Funding Error on asset [1337] peers: [0], [2], did not fund channel in time; Funding Error on asset [7531] peers: [1], [3], did not fund channel in time; ")
assert.Equal("Funding Error on asset [42] peers: [1], [2], did not fund channel in time; Funding Error on asset [1337] peers: [0], [2], did not fund channel in time; Funding Error on asset [7531] peers: [1], [3], did not fund channel in time; ", perr.Error())
// test no funding timeout error
assert.False(IsFundingTimeoutError(errors.New("no FundingTimeoutError")))
// nil input should not return error
Expand Down
3 changes: 2 additions & 1 deletion channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package channel

import (
"fmt"
"github.com/pkg/errors"
stdio "io"

"github.com/pkg/errors"

"perun.network/go-perun/log"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
Expand Down
3 changes: 2 additions & 1 deletion channel/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package channel_test

import (
"perun.network/go-perun/wallet"
"testing"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/require"
"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
Expand Down
1 change: 1 addition & 0 deletions channel/mock_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package channel
import (
"encoding/binary"
"fmt"

"perun.network/go-perun/wallet"

"github.com/pkg/errors"
Expand Down
3 changes: 2 additions & 1 deletion channel/mock_app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package channel

import (
"perun.network/go-perun/wallet"
"testing"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/assert"

wiretest "perun.network/go-perun/wire/test"
Expand Down
1 change: 1 addition & 0 deletions channel/multi/adjudicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package multi
import (
"context"
"fmt"

"perun.network/go-perun/channel"
)

Expand Down
1 change: 1 addition & 0 deletions channel/multi/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package multi

import (
"context"

"perun.network/go-perun/channel"
"perun.network/go-perun/wallet"
)
Expand Down
15 changes: 8 additions & 7 deletions channel/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,25 @@ func sortIDMap(ids IDMap) ([]wallet.BackendID, []ID) {
return sortedIndexes, sortedIDs
}

//nolint:unused
func FromIDKey(k string) IDMap {
buff := bytes.NewBuffer([]byte(k))
reader := bytes.NewReader([]byte(k))
var numElements int32

// Manually decode the number of elements in the map.
if err := binary.Read(buff, binary.BigEndian, &numElements); err != nil {
log.Panicf("could not decode map length in FromIDKey: " + err.Error())
if err := binary.Read(reader, binary.BigEndian, &numElements); err != nil {
log.Panicf("could not decode map length in FromIDKey: %v", err)
}
a := make(map[wallet.BackendID]ID, numElements)
// Decode each key-value pair and insert them into the map.
for i := 0; i < int(numElements); i++ {
var key int32
if err := binary.Read(buff, binary.BigEndian, &key); err != nil {
log.Panicf("could not decode map key in FromIDKey: " + err.Error())
if err := binary.Read(reader, binary.BigEndian, &key); err != nil {
log.Panicf("could not decode map key in FromIDKey: %v", err)
}
id := ID{}
if err := perunio.Decode(buff, &id); err != nil {
log.Panicf("could not decode map[int]ID in FromIDKey: " + err.Error())
if err := perunio.Decode(reader, &id); err != nil {
log.Panicf("could not decode map[int]ID in FromIDKey: %v", err)
}
a[wallet.BackendID(key)] = id
}
Expand Down
3 changes: 2 additions & 1 deletion channel/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package channel_test

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
"perun.network/go-perun/wire/perunio"
Expand Down
1 change: 1 addition & 0 deletions channel/persistence/keyvalue/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func newChannelCache() *channelCache {
}

// channelCache contains all channels.
//
//nolint:unused
type channelCache struct {
mutex stdsync.RWMutex
Expand Down
1 change: 1 addition & 0 deletions channel/persistence/keyvalue/persistedstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package keyvalue

import (
"io"

"perun.network/go-perun/wallet"

"perun.network/go-perun/channel"
Expand Down
3 changes: 2 additions & 1 deletion channel/persistence/keyvalue/persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
"context"
"fmt"
"math"
"perun.network/go-perun/wallet"
"regexp"
"strconv"
"strings"

"perun.network/go-perun/wallet"

"github.com/pkg/errors"

"perun.network/go-perun/channel"
Expand Down
4 changes: 2 additions & 2 deletions channel/persistence/keyvalue/persistrestorer_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package keyvalue

import (
"context"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -31,7 +31,7 @@ import (
)

func TestPersistRestorer_Generic(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "perun-test-kvpersistrestorer-db-*")
tmpdir, err := os.MkdirTemp("", "perun-test-kvpersistrestorer-db-*")
require.NoError(t, err)
lvldb, err := leveldb.LoadDatabase(tmpdir)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions channel/persistence/nonpersister.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package persistence

import (
"context"

"perun.network/go-perun/wallet"

"github.com/pkg/errors"
Expand Down
1 change: 1 addition & 0 deletions channel/persistence/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package persistence
import (
"context"
"io"

"perun.network/go-perun/wallet"

"perun.network/go-perun/channel"
Expand Down
3 changes: 2 additions & 1 deletion channel/persistence/statemachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package persistence_test

import (
"context"
"perun.network/go-perun/wallet"
"testing"
"time"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/require"

"perun.network/go-perun/channel"
Expand Down
1 change: 1 addition & 0 deletions channel/persistence/test/peerchans.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package test
import (
"bytes"
"fmt"

"perun.network/go-perun/wallet"

"perun.network/go-perun/channel"
Expand Down
3 changes: 2 additions & 1 deletion channel/persistence/test/peerchans_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package test

import (
"perun.network/go-perun/wallet"
"testing"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/assert"

"perun.network/go-perun/channel"
Expand Down
3 changes: 2 additions & 1 deletion channel/persistence/test/persistrestorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package test // import "perun.network/go-perun/channel/persistence/test"
import (
"bytes"
"context"
"perun.network/go-perun/wallet"
"sync"
"testing"

"perun.network/go-perun/wallet"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

Expand Down
5 changes: 3 additions & 2 deletions channel/persistence/test/persistrestorertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package test
import (
"context"
"math/rand"
"perun.network/go-perun/wallet"
"testing"

"perun.network/go-perun/wallet"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -197,5 +198,5 @@ peerLoop:

ps, err := pr.ActivePeers(ctx)
require.NoError(t, err)
require.Len(t, ps, 0)
require.Empty(t, ps)
}
1 change: 1 addition & 0 deletions channel/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package channel
import (
"encoding"
"io"

"perun.network/go-perun/wallet"
"perun.network/go-perun/wire"

Expand Down
1 change: 1 addition & 0 deletions channel/test/app_randomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package test

import (
"math/rand"

"perun.network/go-perun/wallet"

"perun.network/go-perun/channel"
Expand Down
Loading

0 comments on commit 408a062

Please sign in to comment.