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

Prepare 82 virtual channels #114

Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.29
version: v1.40.1

tests:
name: Tests
Expand Down
1 change: 0 additions & 1 deletion backend/ethereum/channel/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
pkgtest "perun.network/go-perun/pkg/test"
)

// nolint: dupl
func TestAdjudicator_MultipleRegisters(t *testing.T) {
t.Run("Register 1 party parallel", func(t *testing.T) { registerMultipleConcurrent(t, 1, true) })
t.Run("Register 2 party parallel", func(t *testing.T) { registerMultipleConcurrent(t, 2, true) })
Expand Down
20 changes: 12 additions & 8 deletions backend/ethereum/channel/withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package channel_test

import (
"context"
"fmt"
"sync"
"testing"
"time"
Expand All @@ -31,15 +32,18 @@ import (
pkgtest "perun.network/go-perun/pkg/test"
)

// nolint: dupl
func TestAdjudicator_MultipleWithdraws_FinalState(t *testing.T) {
t.Run("Withdraw 1 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 1, true) })
t.Run("Withdraw 2 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 2, true) })
t.Run("Withdraw 5 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 5, true) })
t.Run("Withdraw 10 party parallel", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 10, true) })
t.Run("Withdraw 1 party sequential", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 1, false) })
t.Run("Withdraw 2 party sequential", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 2, false) })
t.Run("Withdraw 5 party sequential", func(t *testing.T) { withdrawMultipleConcurrentFinal(t, 5, false) })
testParallel := func(n int) {
t.Run(fmt.Sprintf("Withdraw %d party parallel", n), func(t *testing.T) { withdrawMultipleConcurrentFinal(t, n, true) })
}
testSequential := func(n int) {
t.Run(fmt.Sprintf("Withdraw %d party sequential", n), func(t *testing.T) { withdrawMultipleConcurrentFinal(t, n, false) })
}

for _, n := range []int{1, 2, 5} {
testParallel(n)
testSequential(n)
}
}

func withdrawMultipleConcurrentFinal(t *testing.T, numParts int, parallel bool) {
Expand Down
3 changes: 3 additions & 0 deletions channel/persistence/keyvalue/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type channelCache struct {
peerChannels map[string]map[channel.ID]struct{} // Address -> Set<chID>
}

// nolint: unused
func (c *channelCache) addPeerChannel(addr wire.Address, chID channel.ID) {
c.mutex.Lock()
defer c.mutex.Unlock()
Expand All @@ -53,6 +54,7 @@ func (c *channelCache) addPeerChannel(addr wire.Address, chID channel.ID) {
}
}

// nolint: unused
func (c *channelCache) deleteChannel(id channel.ID) []wire.Address {
c.mutex.Lock()
defer c.mutex.Unlock()
Expand All @@ -71,6 +73,7 @@ func (c *channelCache) deleteChannel(id channel.ID) []wire.Address {
return peers
}

// nolint: unused
func (c *channelCache) clear() {
c.mutex.Lock()
defer c.mutex.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/test/persistrestorertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func GenericPersistRestorerTest(
chIndex := iterIdx
log.Error(subSeed)
seed := pkgtest.Seed("", subSeed, numChans, numPeers, chIndex, ch.ID())
rng := rand.New(rand.NewSource(seed))
rng := rand.New(rand.NewSource(seed)) // nolint: gosec

ch.Init(t, rng)
ch.SignAll(t)
Expand Down
27 changes: 15 additions & 12 deletions client/test/progression.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/stretchr/testify/assert"

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

// ProgressionExecConfig contains config parameters for the progression test.
Expand All @@ -30,22 +31,22 @@ type ProgressionExecConfig struct {

// Watcher is a client that handles adjudicator events.
type Watcher struct {
t *testing.T
log.Logger
registered chan *channel.RegisteredEvent
progressed chan *channel.ProgressedEvent
}

func makeWatcher(t *testing.T) Watcher {
func makeWatcher(log log.Logger) Watcher {
return Watcher{
t: t,
Logger: log,
registered: make(chan *channel.RegisteredEvent),
progressed: make(chan *channel.ProgressedEvent),
}
}

// HandleAdjudicatorEvent is the callback for adjudicator event handling.
func (w *Watcher) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) {
w.t.Logf("HandleAdjudicatorEvent: %v", e)
w.Infof("HandleAdjudicatorEvent: %v", e)
switch e := e.(type) {
case *channel.RegisteredEvent:
w.registered <- e
Expand All @@ -64,9 +65,10 @@ type Paul struct {

// NewPaul creates a new party that executes the Paul protocol.
func NewPaul(t *testing.T, setup RoleSetup) *Paul {
p := NewProposer(setup, t, 1)
return &Paul{
Proposer: *NewProposer(setup, t, 1),
Watcher: makeWatcher(t),
Proposer: *p,
Watcher: makeWatcher(p.log),
}
}

Expand All @@ -83,8 +85,8 @@ func (r *Paul) exec(_cfg ExecConfig, ch *paymentChannel) {
// start watcher
go func() {
r.log.Info("Starting channel watcher.")
assert.NoError(ch.Watch(r))
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
r.log.Debug("Channel watcher returned.")
err := ch.Watch(r)
r.log.Infof("Channel watcher returned: %v", err)
}()

r.waitStage() // wait for setup complete
Expand Down Expand Up @@ -130,9 +132,10 @@ type Paula struct {

// NewPaula creates a new party that executes the Paula protocol.
func NewPaula(t *testing.T, setup RoleSetup) *Paula {
r := NewResponder(setup, t, 1)
return &Paula{
Responder: *NewResponder(setup, t, 1),
Watcher: makeWatcher(t),
Responder: *r,
Watcher: makeWatcher(r.log),
}
}

Expand All @@ -149,8 +152,8 @@ func (r *Paula) exec(_cfg ExecConfig, ch *paymentChannel, _ *acceptNextPropHandl
// start watcher
go func() {
r.log.Info("Starting channel watcher.")
assert.NoError(ch.Watch(r))
r.log.Debug("Channel watcher returned.")
err := ch.Watch(r)
r.log.Infof("Channel watcher returned: %v", err)
}()

r.waitStage() // wait for setup complete
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/prng.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func genRootSeed() (rootSeed int64) {
// function by passing it `t.Name()`.
// Use it in tests with: rng := pkgtest.Prng(t).
func Prng(t interface{ Name() string }, args ...interface{}) *rand.Rand {
return rand.New(rand.NewSource(Seed(t.Name(), args...)))
return rand.New(rand.NewSource(Seed(t.Name(), args...))) // nolint: gosec
}

// Seed generates a seed that is dependent on the rootSeed and the passed
Expand Down