-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat(wire): add ecdsa authentication to wire #51
Open
NhoxxKienn
wants to merge
8
commits into
hyperledger-labs:main
Choose a base branch
from
perun-network:draft/egoistic-funding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+584
−14
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
be977f6
feat(wire): add ecdsa authentication to wire
NhoxxKienn ae8cd3e
Merge branch 'main' into draft/egoistic-funding
NhoxxKienn 6a03dc2
chore(lint): fix linting
NhoxxKienn 73eef3a
feat: add client wire test
NhoxxKienn 4c96443
chore: update go.mod
NhoxxKienn 99867bb
Merge branch 'main' into draft/egoistic-funding
NhoxxKienn 03ce1db
feat: add self_signed_certificates for client net test
NhoxxKienn 81b5fc8
fix(wire): move wire_test to package wire to prevent init dependency
NhoxxKienn 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 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,181 @@ | ||
// Copyright 2020 - 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" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
ethchannel "github.com/perun-network/perun-eth-backend/channel" | ||
"github.com/perun-network/perun-eth-backend/channel/test" | ||
ctest "github.com/perun-network/perun-eth-backend/client/test" | ||
ethwallet "github.com/perun-network/perun-eth-backend/wallet" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"perun.network/go-perun/channel" | ||
chtest "perun.network/go-perun/channel/test" | ||
"perun.network/go-perun/client" | ||
clienttest "perun.network/go-perun/client/test" | ||
"perun.network/go-perun/log" | ||
"perun.network/go-perun/wire" | ||
pkgtest "polycry.pt/poly-go/test" | ||
) | ||
|
||
func TestNetProgression(t *testing.T) { | ||
rng := pkgtest.Prng(t) | ||
|
||
names := []string{"Paul", "Paula"} | ||
backendSetup := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth) | ||
roleSetups := ctest.MakeNetRoleSetups(t, rng, backendSetup, names) | ||
clients := [2]clienttest.Executer{ | ||
clienttest.NewPaul(t, roleSetups[0]), | ||
clienttest.NewPaula(t, roleSetups[1]), | ||
} | ||
|
||
appAddress := deployMockApp(t, backendSetup) | ||
appAddrBackend := appAddress.(*ethwallet.Address) | ||
appID := ðchannel.AppID{Address: appAddrBackend} | ||
app := channel.NewMockApp(appID) | ||
channel.RegisterApp(app) | ||
|
||
execConfig := &clienttest.ProgressionExecConfig{ | ||
BaseExecConfig: clienttest.MakeBaseExecConfig( | ||
clientAddresses(roleSetups), | ||
backendSetup.Asset, | ||
[2]*big.Int{big.NewInt(99), big.NewInt(1)}, | ||
client.WithApp(app, channel.NewMockOp(channel.OpValid)), | ||
), | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), twoPartyTestTimeout) | ||
defer cancel() | ||
clienttest.ExecuteTwoPartyTest(ctx, t, clients, execConfig) | ||
} | ||
|
||
func TestNetPaymentHappy(t *testing.T) { | ||
log.Info("Starting happy test") | ||
rng := pkgtest.Prng(t) | ||
|
||
const A, B = 0, 1 // Indices of Alice and Bob | ||
var ( | ||
name = [2]string{"Alice", "Bob"} | ||
role [2]clienttest.Executer | ||
) | ||
|
||
s := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth) | ||
setup := ctest.MakeNetRoleSetups(t, rng, s, name[:]) | ||
|
||
role[A] = clienttest.NewAlice(t, setup[A]) | ||
role[B] = clienttest.NewBob(t, setup[B]) | ||
// enable stages synchronization | ||
stages := role[A].EnableStages() | ||
role[B].SetStages(stages) | ||
|
||
execConfig := &clienttest.AliceBobExecConfig{ | ||
BaseExecConfig: clienttest.MakeBaseExecConfig( | ||
[2]wire.Address{setup[A].Identity.Address(), setup[B].Identity.Address()}, | ||
s.Asset, | ||
[2]*big.Int{big.NewInt(100), big.NewInt(100)}, | ||
client.WithApp(chtest.NewRandomAppAndData(rng)), | ||
), | ||
NumPayments: [2]int{2, 2}, | ||
TxAmounts: [2]*big.Int{big.NewInt(5), big.NewInt(3)}, | ||
} | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(2) | ||
for i := 0; i < 2; i++ { | ||
go func(i int) { | ||
defer wg.Done() | ||
log.Infof("Starting %s.Execute", name[i]) | ||
role[i].Execute(execConfig) | ||
}(i) | ||
} | ||
|
||
wg.Wait() | ||
|
||
// Assert correct final balances | ||
aliceToBob := big.NewInt(int64(execConfig.NumPayments[A])*execConfig.TxAmounts[A].Int64() - | ||
int64(execConfig.NumPayments[B])*execConfig.TxAmounts[B].Int64()) | ||
finalBalAlice := new(big.Int).Sub(execConfig.InitBals()[A], aliceToBob) | ||
finalBalBob := new(big.Int).Add(execConfig.InitBals()[B], aliceToBob) | ||
// reset context timeout | ||
ctx, cancel := context.WithTimeout(context.Background(), ctest.DefaultTimeout) | ||
defer cancel() | ||
assertBal := func(addr *ethwallet.Address, bal *big.Int) { | ||
b, err := s.SimBackend.BalanceAt(ctx, common.Address(*addr), nil) | ||
require.NoError(t, err) | ||
assert.Zero(t, bal.Cmp(b), "ETH balance mismatch") | ||
} | ||
|
||
assertBal(s.Recvs[A], finalBalAlice) | ||
assertBal(s.Recvs[B], finalBalBob) | ||
|
||
log.Info("Happy test done") | ||
} | ||
|
||
func TestNetPaymentDispute(t *testing.T) { | ||
log.Info("Starting dispute test") | ||
rng := pkgtest.Prng(t) | ||
|
||
const A, B = 0, 1 // Indices of Mallory and Carol | ||
var ( | ||
name = [2]string{"Mallory", "Carol"} | ||
role [2]clienttest.Executer | ||
) | ||
|
||
s := test.NewSetup(t, rng, 2, ctest.BlockInterval, TxFinalityDepth) | ||
setup := ctest.MakeNetRoleSetups(t, rng, s, name[:]) | ||
|
||
role[A] = clienttest.NewMallory(t, setup[A]) | ||
role[B] = clienttest.NewCarol(t, setup[B]) | ||
|
||
execConfig := &clienttest.MalloryCarolExecConfig{ | ||
BaseExecConfig: clienttest.MakeBaseExecConfig( | ||
[2]wire.Address{setup[A].Identity.Address(), setup[B].Identity.Address()}, | ||
s.Asset, | ||
[2]*big.Int{big.NewInt(100), big.NewInt(1)}, | ||
client.WithoutApp(), | ||
), | ||
NumPayments: [2]int{5, 0}, | ||
TxAmounts: [2]*big.Int{big.NewInt(20), big.NewInt(0)}, | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), twoPartyTestTimeout) | ||
defer cancel() | ||
clienttest.ExecuteTwoPartyTest(ctx, t, role, execConfig) | ||
|
||
// Assert correct final balances | ||
netTransfer := big.NewInt(int64(execConfig.NumPayments[A])*execConfig.TxAmounts[A].Int64() - | ||
int64(execConfig.NumPayments[B])*execConfig.TxAmounts[B].Int64()) | ||
finalBal := [2]*big.Int{ | ||
new(big.Int).Sub(execConfig.InitBals()[A], netTransfer), | ||
new(big.Int).Add(execConfig.InitBals()[B], netTransfer), | ||
} | ||
// reset context timeout | ||
ctx, cancel = context.WithTimeout(context.Background(), ctest.DefaultTimeout) | ||
defer cancel() | ||
for i, bal := range finalBal { | ||
b, err := s.SimBackend.BalanceAt(ctx, common.Address(*s.Recvs[i]), nil) | ||
require.NoError(t, err) | ||
assert.Zero(t, b.Cmp(bal), "ETH balance mismatch") | ||
} | ||
|
||
log.Info("Dispute test done") | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auf lange Sicht wird es vermutlich besser sein eine Funktion zum listener hinzuzufügen (wenn er nicht schon eine hat) um den Port zu bekommen. Einen tcp listener aufzumachen nur um den Port zu bekommen erscheint mir unnötig.
Also effektiv erst die listener erdstellen und dann für jeden listener den Port abfragen (wie es in findFreePorts gemacht wird) + evtl. kleine Anpassung am perun code um diese Funktionalität bereitzustellen.