-
Notifications
You must be signed in to change notification settings - Fork 18
Extend generic channel tests #223
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
Closed
matthiasgeihs
wants to merge
6
commits into
hyperledger-labs:dev
from
perun-network:219-extend-generic-channel-tests
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51df795
:fire: [channel,backend/sim/channel] Remove set backend test
matthiasgeihs 4a39c8d
:bug: [backend/eth/channel] Fix state app decoding
matthiasgeihs d4e6206
:white_check_mark: [channel/test] Add DecodeAsset test
matthiasgeihs bf134c2
:white_check_mark: [channel/test,backend/eth/channel] Generic funder …
matthiasgeihs f717185
:white_check_mark: [channel/test,backend/eth/channel] Generic adjudic…
matthiasgeihs 6de987a
:white_check_mark: [channel/test,backend/eth/channel] Generic subscri…
matthiasgeihs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2021 - See NOTICE file for copyright holders. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package channel_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"perun.network/go-perun/backend/ethereum/channel/test" | ||
"perun.network/go-perun/channel" | ||
channeltest "perun.network/go-perun/channel/test" | ||
pkgtest "perun.network/go-perun/pkg/test" | ||
) | ||
|
||
func TestSubscription(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer cancel() | ||
|
||
rng := pkgtest.Prng(t) | ||
numParts := 2 + rng.Intn(maxNumParts-2) | ||
setup := test.NewSetup(t, rng, numParts, blockInterval) | ||
adjSetup := newAdjudicatorSetup(setup) | ||
adj := adjSetup.Adjudicator() | ||
|
||
opts := []channeltest.RandomOpt{channeltest.WithoutApp(), channeltest.WithIsFinal(false)} | ||
req, subChannels := adjSetup.newAdjudicatorReq(ctx, rng, opts...), []channel.SignedState{} | ||
sub, err := adj.Subscribe(ctx, req.Params.ID()) | ||
require.NoError(t, err, "subscribing") | ||
|
||
subSetup := newSubscriptionSetup(sub, adj, req, subChannels) | ||
channeltest.TestSubscription(ctx, t, subSetup) | ||
} | ||
|
||
type subscriptionSetup struct { | ||
adj channel.Adjudicator | ||
sub *testSubscription | ||
req *channel.AdjudicatorReq | ||
subChannels []channel.SignedState | ||
} | ||
|
||
func newSubscriptionSetup( | ||
sub channel.AdjudicatorSubscription, | ||
adj channel.Adjudicator, | ||
req *channel.AdjudicatorReq, | ||
subChannels []channel.SignedState, | ||
) *subscriptionSetup { | ||
return &subscriptionSetup{ | ||
sub: &testSubscription{ | ||
emitProgressed: false, | ||
req: req, | ||
AdjudicatorSubscription: sub, | ||
}, | ||
adj: adj, | ||
req: req, | ||
subChannels: subChannels, | ||
} | ||
} | ||
|
||
type testSubscription struct { | ||
channel.AdjudicatorSubscription | ||
emitProgressed bool | ||
req *channel.AdjudicatorReq | ||
} | ||
|
||
// Next emulates app channel functionality because app channels are not supported yet. | ||
func (s *testSubscription) Next() channel.AdjudicatorEvent { | ||
if s.emitProgressed { | ||
ggwpez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s.emitProgressed = false | ||
return channel.NewProgressedEvent(s.req.Tx.ID, &channel.ElapsedTimeout{}, s.req.Tx.State, s.req.Idx) | ||
} | ||
return s.AdjudicatorSubscription.Next() | ||
} | ||
|
||
func (s *subscriptionSetup) Subscription() channel.AdjudicatorSubscription { | ||
return s.sub | ||
} | ||
|
||
// EmitRegistered operates the adjudicator so that a registered event should be emitted. | ||
func (s *subscriptionSetup) EmitRegistered(ctx context.Context) (channel.Params, channel.State) { | ||
err := s.adj.Register(ctx, *s.req, s.subChannels) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return *s.req.Params, *s.req.Tx.State | ||
} | ||
|
||
// EmitProgressed emulates app channel functionality because app channels are not supported yet. | ||
func (s *subscriptionSetup) EmitProgressed(ctx context.Context) (channel.Params, channel.State) { | ||
s.sub.emitProgressed = true | ||
return *s.req.Params, *s.req.Tx.State | ||
} | ||
|
||
// EmitRegistered operates the adjudicator so that a concluded event should be emitted. | ||
func (s *subscriptionSetup) EmitConcluded(ctx context.Context) channel.Params { | ||
err := s.adj.Withdraw(ctx, *s.req, channeltest.MakeStateMapFromSignedStates(s.subChannels...)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return *s.req.Params | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.