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

Include virtualchannel test #32

Merged
Merged
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
4 changes: 2 additions & 2 deletions client/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
func TestProgression(t *testing.T) {
rng := pkgtest.Prng(t)

names := [2]string{"Paul", "Paula"}
names := []string{"Paul", "Paula"}
backendSetup := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth)
roleSetups := ctest.MakeRoleSetups(rng, backendSetup, names)
clients := [2]clienttest.Executer{
Expand Down Expand Up @@ -71,7 +71,7 @@ func deployMockApp(t *testing.T, s *test.Setup) wallet.Address {
return ethwallet.AsWalletAddr(addr)
}

func clientAddresses(roleSetups [2]clienttest.RoleSetup) (addresses [2]wire.Address) {
func clientAddresses(roleSetups []clienttest.RoleSetup) (addresses [2]wire.Address) {
for i := 0; i < len(roleSetups); i++ {
addresses[i] = roleSetups[i].Identity.Address()
}
Expand Down
6 changes: 4 additions & 2 deletions client/fund_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ func TestFundRecovery(t *testing.T) {
for i, adj := range setup.Adjs {
adj.Receiver = setup.Accs[i].Account.Address
}
roles := ethclienttest.MakeRoleSetups(rng, setup, [2]string{"Frida", "Fred"})
return roles, setup.Asset
roles := ethclienttest.MakeRoleSetups(rng, setup, []string{"Frida", "Fred"})
var rolesArray [2]ctest.RoleSetup
copy(rolesArray[:], roles)
return rolesArray, setup.Asset
},
)
}
14 changes: 6 additions & 8 deletions client/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ func TestPaymentHappy(t *testing.T) {

const A, B = 0, 1 // Indices of Alice and Bob
var (
name = [2]string{"Alice", "Bob"}
setup [2]clienttest.RoleSetup
role [2]clienttest.Executer
name = [2]string{"Alice", "Bob"}
role [2]clienttest.Executer
)

s := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth)
setup = ctest.MakeRoleSetups(rng, s, name)
setup := ctest.MakeRoleSetups(rng, s, name[:])

role[A] = clienttest.NewAlice(t, setup[A])
role[B] = clienttest.NewBob(t, setup[B])
Expand Down Expand Up @@ -111,13 +110,12 @@ func TestPaymentDispute(t *testing.T) {

const A, B = 0, 1 // Indices of Mallory and Carol
var (
name = [2]string{"Mallory", "Carol"}
setup [2]clienttest.RoleSetup
role [2]clienttest.Executer
name = [2]string{"Mallory", "Carol"}
role [2]clienttest.Executer
)

s := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth)
setup = ctest.MakeRoleSetups(rng, s, name)
setup := ctest.MakeRoleSetups(rng, s, name[:])

role[A] = clienttest.NewMallory(t, setup[A])
role[B] = clienttest.NewCarol(t, setup[B])
Expand Down
4 changes: 2 additions & 2 deletions client/subchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestSubChannelHappy(t *testing.T) {
rng := pkgtest.Prng(t)
const A, B = 0, 1 // Indices of clients.
s := ethchanneltest.NewSetup(t, rng, 2, ethclienttest.BlockInterval, TxFinalityDepth)
setups := ethclienttest.MakeRoleSetups(rng, s, [2]string{"Susie", "Tim"})
setups := ethclienttest.MakeRoleSetups(rng, s, []string{"Susie", "Tim"})
roles := [2]clienttest.Executer{
clienttest.NewSusie(t, setups[A]),
clienttest.NewTim(t, setups[B]),
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestSubChannelDispute(t *testing.T) {

const A, B = 0, 1 // Indices of clients.
s := ethchanneltest.NewSetup(t, rng, 2, ethclienttest.BlockInterval, TxFinalityDepth)
setups := ethclienttest.MakeRoleSetups(rng, s, [2]string{"DisputeSusie", "DisputeTim"})
setups := ethclienttest.MakeRoleSetups(rng, s, []string{"DisputeSusie", "DisputeTim"})
roles := [2]clienttest.Executer{
clienttest.NewDisputeSusie(t, setups[A]),
clienttest.NewDisputeTim(t, setups[B]),
Expand Down
9 changes: 5 additions & 4 deletions client/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ const (
)

// MakeRoleSetups creates a two party client test setup with the provided names.
func MakeRoleSetups(rng *rand.Rand, s *ethctest.Setup, names [2]string) (setup [2]clienttest.RoleSetup) {
func MakeRoleSetups(rng *rand.Rand, s *ethctest.Setup, names []string) []clienttest.RoleSetup {
setups := make([]clienttest.RoleSetup, len(names))
bus := wire.NewLocalBus()
for i := 0; i < len(setup); i++ {
for i := 0; i < len(setups); i++ {
watcher, err := local.NewWatcher(s.Adjs[i])
if err != nil {
panic("Error initializing watcher: " + err.Error())
}
setup[i] = clienttest.RoleSetup{
setups[i] = clienttest.RoleSetup{
Name: names[i],
Identity: wiretest.NewRandomAccount(rng),
Bus: bus,
Expand All @@ -59,5 +60,5 @@ func MakeRoleSetups(rng *rand.Rand, s *ethctest.Setup, names [2]string) (setup [
BalanceReader: s.SimBackend.NewBalanceReader(s.Accs[i].Address()),
}
}
return
return setups
}
86 changes: 86 additions & 0 deletions client/virtualchannel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2022 - 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 client_test

import (
"context"
"math/big"
"math/rand"
"testing"
"time"

channeltest "github.com/perun-network/perun-eth-backend/channel/test"
ethclienttest "github.com/perun-network/perun-eth-backend/client/test"
"perun.network/go-perun/channel"
ctest "perun.network/go-perun/client/test"
"polycry.pt/poly-go/test"
)

func TestVirtualChannelOptimistic(t *testing.T) {
rng := test.Prng(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

ctest.TestVirtualChannelOptimistic(
ctx,
t,
createVirtualChannelSetup(t, rng),
)
}

func TestVirtualChannelDispute(t *testing.T) {
rng := test.Prng(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

ctest.TestVirtualChannelDispute(
ctx,
t,
createVirtualChannelSetup(t, rng),
)
}

func createVirtualChannelSetup(t *testing.T, rng *rand.Rand) ctest.VirtualChannelSetup {
t.Helper()
clients, asset := setupVirtualChannelClients(t, rng)
matthiasgeihs marked this conversation as resolved.
Show resolved Hide resolved
return ctest.VirtualChannelSetup{
ChallengeDuration: challengeDuration,
Clients: clients,
Balances: ctest.VirtualChannelBalances{
InitBalsAliceIngrid: []*big.Int{ethclienttest.EtherToWei(10), ethclienttest.EtherToWei(10)},
InitBalsBobIngrid: []*big.Int{ethclienttest.EtherToWei(10), ethclienttest.EtherToWei(10)},
InitBalsAliceBob: []*big.Int{ethclienttest.EtherToWei(5), ethclienttest.EtherToWei(5)},
VirtualBalsUpdated: []*big.Int{ethclienttest.EtherToWei(2), ethclienttest.EtherToWei(8)},
FinalBalsAlice: []*big.Int{ethclienttest.EtherToWei(7), ethclienttest.EtherToWei(13)},
FinalBalsBob: []*big.Int{ethclienttest.EtherToWei(13), ethclienttest.EtherToWei(7)},
},
BalanceDelta: ethclienttest.EtherToWei(0.001),
Asset: asset,
Rng: rng,
WaitWatcherTimeout: 100 * time.Millisecond,
}
}

func setupVirtualChannelClients(t *testing.T, rng *rand.Rand) ([3]ctest.RoleSetup, channel.Asset) {
t.Helper()
setup := channeltest.NewSetup(t, rng, 3, ethclienttest.BlockInterval, 1)
for i, adj := range setup.Adjs {
adj.Receiver = setup.Accs[i].Account.Address
}
roles := ethclienttest.MakeRoleSetups(rng, setup, []string{"Alice", "Bob", "Ingrid"})
var rolesArray [3]ctest.RoleSetup
copy(rolesArray[:], roles)
return rolesArray, setup.Asset
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
perun.network/go-perun v0.10.4
perun.network/go-perun v0.10.5
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
perun.network/go-perun v0.10.4 h1:uTliGXl2qoIusgovebua9PT1uaSpd9zUHcheNzxRtlA=
perun.network/go-perun v0.10.4/go.mod h1:BGBZC3npkX457u87pjDd0NEIXr1a4dsH4H/YpLdGGe8=
perun.network/go-perun v0.10.5 h1:bIaAoLLh8R+RXdPh+MkCJcbtumsFkNvoVAJwb60JKjg=
perun.network/go-perun v0.10.5/go.mod h1:BGBZC3npkX457u87pjDd0NEIXr1a4dsH4H/YpLdGGe8=
polycry.pt/poly-go v0.0.0-20220222131629-aa4bdbaab60b/go.mod h1:XUBrNtqgEhN3EEOP/5gh7IBd3xVHKidCjXDZfl9+kMU=
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37 h1:iA5GzEa/hHfVlQpimEjPV09NATwHXxSjWNB0VVodtew=
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37/go.mod h1:XUBrNtqgEhN3EEOP/5gh7IBd3xVHKidCjXDZfl9+kMU=
Expand Down