Skip to content
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 channel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func SetBackend(b Backend, id int) {
// CalcID calculates the CalcID.
func CalcID(p *Params) (ID, error) {
var lastErr error
for _, b := range backend {
id, err := b.CalcID(p)
for i := range p.Parts[0] {
id, err := backend[i].CalcID(p)
if err == nil {
return id, nil
}
Expand Down
6 changes: 3 additions & 3 deletions client/appchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func TestProgression(t *testing.T) {
execConfig := &clienttest.ProgressionExecConfig{
BaseExecConfig: clienttest.MakeBaseExecConfig(
[2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)},
chtest.NewRandomAsset(rng, channel.TestBackendID),
channel.TestBackendID,
[2]*big.Int{big.NewInt(99), big.NewInt(1)},
[]channel.Asset{chtest.NewRandomAsset(rng, channel.TestBackendID)},
[]wallet.BackendID{channel.TestBackendID},
[][2]*big.Int{{big.NewInt(99), big.NewInt(1)}},
client.WithApp(app, channel.NewMockOp(channel.OpValid)),
),
}
Expand Down
6 changes: 3 additions & 3 deletions client/client_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func runAliceBobTest(ctx context.Context, t *testing.T, setup func(*rand.Rand) (
cfg := &ctest.AliceBobExecConfig{
BaseExecConfig: ctest.MakeBaseExecConfig(
[2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)},
chtest.NewRandomAsset(rng, channel.TestBackendID),
channel.TestBackendID,
[2]*big.Int{big.NewInt(100), big.NewInt(100)},
[]channel.Asset{chtest.NewRandomAsset(rng, channel.TestBackendID)},
[]wallet.BackendID{channel.TestBackendID},
[][2]*big.Int{{big.NewInt(100), big.NewInt(100)}},
app,
),
NumPayments: [2]int{2, 2},
Expand Down
6 changes: 3 additions & 3 deletions client/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func TestPaymentDispute(t *testing.T) {
cfg := &ctest.MalloryCarolExecConfig{
BaseExecConfig: ctest.MakeBaseExecConfig(
[2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[mallory].Identity), wire.AddressMapfromAccountMap(setups[carol].Identity)},
chtest.NewRandomAsset(rng, channel.TestBackendID),
channel.TestBackendID,
[2]*big.Int{big.NewInt(100), big.NewInt(1)},
[]channel.Asset{chtest.NewRandomAsset(rng, channel.TestBackendID)},
[]wallet.BackendID{channel.TestBackendID},
[][2]*big.Int{{big.NewInt(100), big.NewInt(1)}},
client.WithoutApp(),
),
NumPayments: [2]int{5, 0},
Expand Down
12 changes: 6 additions & 6 deletions client/subchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func TestSubChannelHappy(t *testing.T) {
cfg := ctest.NewSusieTimExecConfig(
ctest.MakeBaseExecConfig(
[2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)},
chtest.NewRandomAsset(rng, channel.TestBackendID),
channel.TestBackendID,
[2]*big.Int{big.NewInt(100), big.NewInt(100)},
[]channel.Asset{chtest.NewRandomAsset(rng, channel.TestBackendID)},
[]wallet.BackendID{channel.TestBackendID},
[][2]*big.Int{{big.NewInt(100), big.NewInt(100)}},
client.WithoutApp(),
),
[][2]*big.Int{
Expand Down Expand Up @@ -79,9 +79,9 @@ func TestSubChannelDispute(t *testing.T) {

baseCfg := ctest.MakeBaseExecConfig(
[2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)},
chtest.NewRandomAsset(rng, channel.TestBackendID),
channel.TestBackendID,
[2]*big.Int{big.NewInt(100), big.NewInt(100)},
[]channel.Asset{chtest.NewRandomAsset(rng, channel.TestBackendID)},
[]wallet.BackendID{channel.TestBackendID},
[][2]*big.Int{{big.NewInt(100), big.NewInt(100)}},
client.WithoutApp(),
)
cfg := &ctest.DisputeSusieTimExecConfig{
Expand Down
7 changes: 2 additions & 5 deletions client/test/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"math/big"
"time"

"perun.network/go-perun/wallet"

"perun.network/go-perun/channel"
"perun.network/go-perun/client"
"perun.network/go-perun/log"
Expand Down Expand Up @@ -85,11 +83,10 @@ func (ch *paymentChannel) openSubChannel(
cfg ExecConfig,
initBals []*big.Int,
app client.ProposalOpts,
bID wallet.BackendID,
) *paymentChannel {
initAlloc := channel.Allocation{
Assets: []channel.Asset{cfg.Asset()},
Backends: []wallet.BackendID{bID},
Assets: cfg.Asset(),
Backends: cfg.Backend(),
Balances: [][]channel.Bal{{initBals[0], initBals[1]}},
}

Expand Down
38 changes: 22 additions & 16 deletions client/test/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ type (
// ExecConfig contains additional config parameters for the tests.
ExecConfig interface {
Peers() [2]map[wallet.BackendID]wire.Address // must match the RoleSetup.Identity's
Asset() channel.Asset // single Asset to use in this channel
Backend() wallet.BackendID // backend corresponding to asset
InitBals() [2]*big.Int // channel deposit of each role
Asset() []channel.Asset // single Asset to use in this channel
Backend() []wallet.BackendID // backend corresponding to asset
InitBals() [][2]*big.Int // channel deposit of each role
App() client.ProposalOpts // must be either WithApp or WithoutApp
}

// BaseExecConfig contains base config parameters.
BaseExecConfig struct {
peers [2]map[wallet.BackendID]wire.Address // must match the RoleSetup.Identity's
asset channel.Asset // single Asset to use in this channel
backend wallet.BackendID // backend corresponding to asset
initBals [2]*big.Int // channel deposit of each role
asset []channel.Asset // single Asset to use in this channel
backend []wallet.BackendID // backend corresponding to asset
initBals [][2]*big.Int // channel deposit of each role
app client.ProposalOpts // must be either WithApp or WithoutApp
}

Expand Down Expand Up @@ -188,9 +188,9 @@ func ExecuteTwoPartyTest(ctx context.Context, t *testing.T, role [2]Executer, cf
// MakeBaseExecConfig creates a new BaseExecConfig.
func MakeBaseExecConfig(
peers [2]map[wallet.BackendID]wire.Address,
asset channel.Asset,
backend wallet.BackendID,
initBals [2]*big.Int,
asset []channel.Asset,
backend []wallet.BackendID,
initBals [][2]*big.Int,
app client.ProposalOpts,
) BaseExecConfig {
return BaseExecConfig{
Expand All @@ -208,17 +208,17 @@ func (c *BaseExecConfig) Peers() [2]map[wallet.BackendID]wire.Address {
}

// Asset returns the asset.
func (c *BaseExecConfig) Asset() channel.Asset {
func (c *BaseExecConfig) Asset() []channel.Asset {
return c.asset
}

// Backend returns the asset.
func (c *BaseExecConfig) Backend() wallet.BackendID {
func (c *BaseExecConfig) Backend() []wallet.BackendID {
return c.backend
}

// InitBals returns the initial balances.
func (c *BaseExecConfig) InitBals() [2]*big.Int {
func (c *BaseExecConfig) InitBals() [][2]*big.Int {
return c.initBals
}

Expand Down Expand Up @@ -358,13 +358,19 @@ func (r *role) LedgerChannelProposal(rng *rand.Rand, cfg ExecConfig) *client.Led
r.log.Panic("Invalid ExecConfig: App does not specify an app.")
}

peers, asset, bals := cfg.Peers(), cfg.Asset(), cfg.InitBals()
alloc := channel.NewAllocation(len(peers), []wallet.BackendID{cfg.Backend()}, asset)
alloc.SetAssetBalances(asset, bals[:])
peers, assets, bals, backend := cfg.Peers(), cfg.Asset(), cfg.InitBals(), cfg.Backend()
alloc := channel.NewAllocation(len(peers), cfg.Backend(), assets...)
for i := range assets {
alloc.SetAssetBalances(assets[i], bals[i][:])
}

peersList := make(map[wallet.BackendID]wallet.Address)
for i := range backend {
peersList[backend[i]] = r.setup.Wallet[backend[i]].NewRandomAccount(rng).Address()
}
prop, err := client.NewLedgerChannelProposal(
r.challengeDuration,
map[wallet.BackendID]wallet.Address{cfg.Backend(): r.setup.Wallet[cfg.Backend()].NewRandomAccount(rng).Address()},
peersList,
alloc,
peers[:],
client.WithNonceFrom(rng),
Expand Down
2 changes: 1 addition & 1 deletion client/test/subchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *Susie) exec(_cfg ExecConfig, ledgerChannel *paymentChannel) {

// stage 2 - open subchannels
openSubChannel := func(parentChannel *paymentChannel, funds []*big.Int, app client.ProposalOpts) *paymentChannel {
return parentChannel.openSubChannel(rng, cfg, funds, app, cfg.backend)
return parentChannel.openSubChannel(rng, cfg, funds, app)
}

var subChannels []*paymentChannel
Expand Down
2 changes: 1 addition & 1 deletion client/test/subchannel_dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *DisputeSusie) exec(_cfg ExecConfig, ledgerChannel *paymentChannel) {
r.waitStage()

// Stage 2 - Open sub-channel.
subChannel := ledgerChannel.openSubChannel(rng, cfg, cfg.SubChannelFunds[:], client.WithoutApp(), _cfg.Backend())
subChannel := ledgerChannel.openSubChannel(rng, cfg, cfg.SubChannelFunds[:], client.WithoutApp())
subReq0 := client.NewTestChannel(subChannel.Channel).AdjudicatorReq() // Store AdjudicatorReq for version 0
r.waitStage()

Expand Down