Skip to content

Commit

Permalink
feat(multiledger): Add egoistic argument in setupClient to test corre…
Browse files Browse the repository at this point in the history
…ctness of egoisticPart and EgoisticChains.

Signed-off-by: Sophia Koehler <[email protected]>
  • Loading branch information
iljabvh authored and sophia1ch committed Mar 26, 2024
1 parent 06cea29 commit 318905c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions client/test/multiledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func SetupMultiLedgerTest(t *testing.T, testDuration time.Duration) ctest.MultiL
bus := wire.NewLocalBus()

// Setup clients.
c1 := setupClient(t, rng, l1, l2, bus)
c2 := setupClient(t, rng, l1, l2, bus)
c1 := setupClient(t, rng, l1, l2, bus, true)
c2 := setupClient(t, rng, l1, l2, bus, false)

// Fund accounts.
l1.simSetup.SimBackend.FundAddress(ctx, wallet.AsEthAddr(c1.WalletAddress))
Expand Down Expand Up @@ -126,7 +126,7 @@ func setupLedger(ctx context.Context, t *testing.T, rng *rand.Rand, chainID *big
}
}

func setupClient(t *testing.T, rng *rand.Rand, l1, l2 testLedger, bus wire.Bus) ctest.MultiLedgerClient {
func setupClient(t *testing.T, rng *rand.Rand, l1, l2 testLedger, bus wire.Bus, egoistic bool) ctest.MultiLedgerClient {
t.Helper()
require := require.New(t)

Expand Down Expand Up @@ -154,6 +154,17 @@ func setupClient(t *testing.T, rng *rand.Rand, l1, l2 testLedger, bus wire.Bus)
multiFunder := multi.NewFunder()
funderL1 := ethchannel.NewFunder(cb1)
funderL2 := ethchannel.NewFunder(cb2)
if egoistic {
egoisticPart := make([]bool, 2)
egoisticPart[1] = true
funderL2.SetEgoisticPart(1, 2)
require.Equal(egoisticPart, funderL2.EgoisticPart)

egoisticChains := make(map[multi.LedgerIDMapKey]bool)
egoisticChains[funderL2.ChainID().MapKey()] = true
multiFunder.SetEgoisticChain(funderL2.ChainID(), true)
require.Equal(egoisticChains, multiFunder.EgoisticChains)
}
registered := funderL1.RegisterAsset(*l1.asset, ethchannel.NewETHDepositor(defaultETHGasLimit), acc.Account)
require.True(registered)
registered = funderL1.RegisterAsset(*l2.asset, ethchannel.NewNoOpDepositor(), acc.Account)
Expand Down
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.11.1-0.20240312125059-3811fdb76baf
perun.network/go-perun v0.11.1-0.20240326094100-011cfdf0ea51
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 @@ -645,8 +645,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.11.1-0.20240312125059-3811fdb76baf h1:eTmgN9p2Uo48c+8Jiya67wnRakZEBoXlG3fWOSXlPw0=
perun.network/go-perun v0.11.1-0.20240312125059-3811fdb76baf/go.mod h1:VfCebjZTnFrQRcjbkK1s1l+H71MKW7jodpFQBdP7tRQ=
perun.network/go-perun v0.11.1-0.20240326094100-011cfdf0ea51 h1:fIM4nKc6OKkBX/gJrCTMMFmxeoFTE1DAerndDW/njVc=
perun.network/go-perun v0.11.1-0.20240326094100-011cfdf0ea51/go.mod h1:VfCebjZTnFrQRcjbkK1s1l+H71MKW7jodpFQBdP7tRQ=
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=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down

0 comments on commit 318905c

Please sign in to comment.