Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go 1.21 upgrade #403

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ on:
release:

env:
go-version: 1.17
go-version: 1.21

jobs:
check-copyright:
name: Copyright
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4.1.1
with:
fetch-depth: 0
- name: Authors
Expand All @@ -26,23 +26,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4.1.1

- name: Check vanity import
run: .scripts/check-vanity-imports.sh $GITHUB_WORKSPACE

- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.43
version: v1.56.2

- name: Lint proto files
uses: plexsystems/protolint-action@v0.6.0
uses: plexsystems/protolint-action@v0.7.0
with:
configDirectory: .

Expand All @@ -51,14 +51,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4.1.1

- uses: actions/cache@v2
- uses: actions/cache@v4.0.0
with:
path: |
~/.cache/go-build
Expand All @@ -75,14 +75,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4.1.1

- uses: actions/cache@v2
- uses: actions/cache@v4.0.0
with:
path: |
~/.cache/go-build
Expand Down
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ linters:
- gci # We have our own import order.
- goerr113 # We do not strictly require static errors.
- promlinter # Disabled because unstable.
- nosnakecase # We use snake case.
- depguard # We use go modules.
- exhaustruct # We often have uninitialized fields of structs.

# These could be enabled in the future:
- ifshort # we often don't use `if err := …` for readability.
Expand All @@ -36,6 +39,9 @@ linters:
- scopelint
- golint
- interfacer
- varcheck
- structcheck
- deadcode

linters-settings:
cyclop:
Expand Down Expand Up @@ -77,4 +83,4 @@ issues:
# therefore disable the "context must be the first argument" check in tests.
- path: test
linters: [revive]
text: "context-as-argument"
text: "context-as-argument"
7 changes: 4 additions & 3 deletions apps/payment/app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

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

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
Expand All @@ -42,7 +43,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))
require.NoError(t, app.ValidInit(nil, data))
}

func TestApp_ValidTransition(t *testing.T) {
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestApp_ValidTransition(t *testing.T) {
numParticipants := len(tt.from[0])
for i := 0; i < numParticipants; i++ {
// valid self-transition
assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i)))
require.NoError(t, app.ValidTransition(nil, from, from, channel.Index(i)))
}

for _, tto := range tt.tos {
Expand All @@ -107,7 +108,7 @@ func TestApp_ValidTransition(t *testing.T) {
for i := 0; i < numParticipants; i++ {
err := app.ValidTransition(nil, from, to, channel.Index(i))
if i == tto.valid {
assert.NoError(err)
require.NoError(t, err)
} else {
assert.Error(err)
}
Expand Down
3 changes: 2 additions & 1 deletion apps/payment/randomizer_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

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

_ "perun.network/go-perun/backend/sim" // backend init
"perun.network/go-perun/channel"
Expand All @@ -31,7 +32,7 @@ func TestRandomizer(t *testing.T) {
app := r.NewRandomApp(rng)
channel.RegisterApp(app)
regApp, err := channel.Resolve(app.Def())
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, app.Def().Equal(regApp.Def()))
assert.True(t, IsData(r.NewRandomData(rng)))
}
6 changes: 3 additions & 3 deletions apps/payment/resolver_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestResolver(t *testing.T) {
channel.RegisterAppResolver(def.Equal, &Resolver{})

app, err := channel.Resolve(def)
assert.NoError(err)
require.NoError(err)
require.NotNil(app)
assert.True(def.Equal(app.Def()))
}
Expand All @@ -47,13 +47,13 @@ func TestData(t *testing.T) {
assert.NotPanics(func() {
data := Data()
_, err := data.MarshalBinary()
assert.Nil(err)
require.NoError(t, err)
})

assert.NotPanics(func() {
app := new(App)
data := app.NewData()
assert.NoError(data.UnmarshalBinary(nil))
require.NoError(t, data.UnmarshalBinary(nil))
assert.NotNil(data)
assert.True(IsData(data))
})
Expand Down
5 changes: 3 additions & 2 deletions backend/sim/channel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type backend struct{}
var _ channel.Backend = new(backend)

// CalcID calculates a channel's ID by hashing all fields of its parameters.
func (*backend) CalcID(p *channel.Params) (id channel.ID) {
func (*backend) CalcID(p *channel.Params) channel.ID {
var id channel.ID
w := sha256.New()

// Write Parts
Expand All @@ -51,7 +52,7 @@ func (*backend) CalcID(p *channel.Params) (id channel.ID) {
if copy(id[:], w.Sum(nil)) != channel.IDLen {
log.Panic("Could not copy id")
}
return
return id
}

// Sign signs `state`.
Expand Down
16 changes: 10 additions & 6 deletions backend/sim/wallet/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (a *Address) Bytes() []byte {

// byteArray converts an address into a 64-byte array. The returned array
// consists of two 32-byte chunks representing the public key's X and Y values.
func (a *Address) byteArray() (data [addrLen]byte) {
func (a *Address) byteArray() [addrLen]byte {
var data [addrLen]byte
xb := a.X.Bytes()
yb := a.Y.Bytes()

Expand All @@ -89,12 +90,15 @@ func (a *Address) Equal(addr wallet.Address) bool {
return (a.X.Cmp(b.X) == 0) && (a.Y.Cmp(b.Y) == 0)
}

// Cmp checks the ordering of two addresses according to following definition:
// -1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y))
// 0 if (a.X == addr.X) && (a.Y == addr.Y)
// +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y))
// Cmp checks the ordering of two addresses according to the following definition:
//
// -1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y))
// 0 if (a.X == addr.X) && (a.Y == addr.Y)
// +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y))
//
// So the X coordinate is weighted higher.
// Pancis if the passed address is of the wrong type.
//
// It panics if the passed address is of the wrong type.
func (a *Address) Cmp(addr wallet.Address) int {
b, ok := addr.(*Address)
if !ok {
Expand Down
5 changes: 3 additions & 2 deletions backend/sim/wallet/address_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pkgtest "polycry.pt/poly-go/test"

"perun.network/go-perun/wire/test"
Expand All @@ -43,7 +44,7 @@ func TestAddressMarshalling(t *testing.T) {
Y: new(big.Int).SetBytes(dest[elemLen:]),
}
result, err := addr.MarshalBinary()
assert.NoError(t, err, "marshaling address should not error")
require.NoError(t, err, "marshaling address should not error")
assert.Equal(t, result, dest[:])
})

Expand All @@ -59,7 +60,7 @@ func TestAddressMarshalling(t *testing.T) {
Y: new(big.Int).SetBytes(dest[elemLen:]),
}
result, err := addr.MarshalBinary()
assert.NoError(t, err, "marshaling address should not error")
require.NoError(t, err, "marshaling address should not error")
assert.Equal(t, result, dest[:])
})
}
Expand Down
15 changes: 8 additions & 7 deletions backend/sim/wallet/wallet_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

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

"perun.network/go-perun/wallet/test"
pkgtest "polycry.pt/poly-go/test"
Expand All @@ -45,11 +46,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")
require.NoError(t, 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")
require.NoError(t, 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 +81,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
6 changes: 3 additions & 3 deletions backend/sim/wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func TestWallet_AddAccount(t *testing.T) {
acc := wallet.NewRandomAccount(rng)

assert.False(t, w.HasAccount(acc))
assert.NoError(t, w.AddAccount(acc))
require.NoError(t, w.AddAccount(acc))
assert.True(t, w.HasAccount(acc))
assert.Error(t, w.AddAccount(acc))
require.Error(t, w.AddAccount(acc))
}

func TestWallet_Unlock(t *testing.T) {
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestWallet_Unlock(t *testing.T) {

t.Run("unknown unlock", func(t *testing.T) {
acc, err := w.Unlock(wallet.NewRandomAddress(rng))
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, acc)
})
}
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/wire/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (acc *Account) Address() wire.Address {
}

// Sign signs the given message with the account's private key.
func (acc *Account) Sign(msg []byte) ([]byte, error) {
func (acc *Account) Sign(_ []byte) ([]byte, error) {
return []byte("Authenticate"), nil
}

Expand Down
4 changes: 2 additions & 2 deletions backend/sim/wire/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewAddress() *Address {
}

// MarshalBinary marshals the address to binary.
func (a Address) MarshalBinary() (data []byte, err error) {
func (a Address) MarshalBinary() ([]byte, error) {
return a[:], nil
}

Expand Down Expand Up @@ -64,7 +64,7 @@ func (a Address) Cmp(b wire.Address) int {
}

// Verify verifies a signature.
func (a Address) Verify(msg, sig []byte) error {
func (a Address) Verify(_, sig []byte) error {
if !bytes.Equal(sig, []byte("Authenticate")) {
return errors.New("invalid signature")
}
Expand Down
12 changes: 6 additions & 6 deletions channel/adjudicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type (
// If the channel has locked funds into sub-channels, the corresponding
// signed sub-channel states must be provided.
Registerer interface {
Register(context.Context, AdjudicatorReq, []SignedState) error
Register(ctx context.Context, adjReq AdjudicatorReq, signedStates []SignedState) error
}

// Withdrawer is the interface that wraps the Withdraw method.
Expand All @@ -77,7 +77,7 @@ type (
// If the channel has locked funds in sub-channels, the states of the
// corresponding sub-channels need to be supplied additionally.
Withdrawer interface {
Withdraw(context.Context, AdjudicatorReq, StateMap) error
Withdraw(ctx context.Context, adjReq AdjudicatorReq, stateMap StateMap) error
}

// Progresser is the interface that wraps the Progress method.
Expand All @@ -87,7 +87,7 @@ type (
// contain the state, the signatures can be nil, since the old state is
// already registered on the adjudicator.
Progresser interface {
Progress(context.Context, ProgressReq) error
Progress(ctx context.Context, progReq ProgressReq) error
}

// EventSubscriber is the interface that wraps the Subscribe method.
Expand All @@ -98,7 +98,7 @@ type (
// subscription should be closed by calling Close on the subscription after
// the channel is closed.
EventSubscriber interface {
Subscribe(context.Context, ID) (AdjudicatorSubscription, error)
Subscribe(ctx context.Context, ID ID) (AdjudicatorSubscription, error)
}

// An AdjudicatorReq collects all necessary information to make calls to the
Expand Down Expand Up @@ -196,11 +196,11 @@ type (
Timeout interface {
// IsElapsed should return whether the timeout has elapsed at the time of
// the call of this method.
IsElapsed(context.Context) bool
IsElapsed(ctx context.Context) bool

// Wait waits for the timeout to elapse. If the context is canceled, Wait
// should return immediately with the context's error.
Wait(context.Context) error
Wait(ctx context.Context) error
}

// StateMap represents a channel state tree.
Expand Down
Loading
Loading