-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(multiledger): Add egoistic argument in setupClient to test correctness of egoisticPart and EgoisticChains. Signed-off-by: Sophia Koehler <[email protected]> * feat(multiledger): Add new test case for egoistic funding. Signed-off-by: Sophia Koehler <[email protected]> * feat(fund): Add fundAll function that funds all funders and returns a list of times, each funder took to finish. feat(TestEgoisticParticipantFunding): Add Test that sets one participant as egoistic, funds and checks if egoistic funder funds last. Signed-off-by: Sophia Koehler <[email protected]> refactor(multiledger): Add comment, rename function. Signed-off-by: Sophia Koehler <[email protected]> refactor(multiledger): Add var for participants length. Signed-off-by: Sophia Koehler <[email protected]> * revert: Remove multiledger test. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Add t.Helper() Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Rearrange arguments in fundAll. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Add comment for FundAll. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Add const for waiting time. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Change to loop. Signed-off-by: Sophia Koehler <[email protected]> Revert "refactor(fund): change to loop." This reverts commit a567031. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): change to loop. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): remove loop, add 2 second wait. Signed-off-by: Sophia Koehler <[email protected]> refactor(funder): rearrange imports. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Add waitgroup. Signed-off-by: Sophia Koehler <[email protected]> refactor(funder_test) refactor(fund): Add concurrent testing. Signed-off-by: Sophia Koehler <[email protected]> refactor(fund): Add comments, delete unnecessary function. Signed-off-by: Sophia Koehler <[email protected]> * chore: Update dates of copyright license Signed-off-by: Sophia Koehler <[email protected]> --------- Signed-off-by: Sophia Koehler <[email protected]> Co-authored-by: Ilja von Hoessle <[email protected]>
- Loading branch information
Showing
4 changed files
with
121 additions
and
4 deletions.
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
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,68 @@ | ||
// Copyright 2024 - 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 test | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/perun-network/perun-eth-backend/channel" | ||
"github.com/stretchr/testify/require" | ||
pchannel "perun.network/go-perun/channel" | ||
) | ||
|
||
// waitTime is the time to wait before funding a channel when the funder is not egoistic. | ||
const waitTime = 2 * time.Second | ||
|
||
// FunderFinishTime is the returned type of FundAll which includes the process time of each funder. | ||
type FunderFinishTime struct { | ||
Index int | ||
Time time.Duration | ||
} | ||
|
||
// FundAll calls fund for all funders simultaneously. | ||
func FundAll(ctx context.Context, t *testing.T, funders []*channel.Funder, reqs []*pchannel.FundingReq, egoisticIndex int) ([]FunderFinishTime, error) { | ||
t.Helper() | ||
finishTimes := make([]FunderFinishTime, len(funders)) | ||
var mutex sync.Mutex | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(len(funders)) | ||
|
||
for i := range funders { | ||
i := i | ||
go func() { | ||
defer wg.Done() | ||
if i != egoisticIndex { | ||
time.Sleep(waitTime) | ||
} | ||
startTime := time.Now() | ||
err := funders[i].Fund(ctx, *reqs[i]) | ||
require.NoError(t, err) | ||
finishTime := time.Now() | ||
mutex.Lock() | ||
finishTimes[i] = FunderFinishTime{ | ||
Index: i, | ||
Time: finishTime.Sub(startTime), | ||
} | ||
mutex.Unlock() | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
return finishTimes, nil | ||
} |
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
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