Skip to content

Commit

Permalink
revert: Remove multiledger test.
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Koehler <[email protected]>
  • Loading branch information
sophia1ch committed Apr 2, 2024
1 parent fdcb4f2 commit 93ff531
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 124 deletions.
8 changes: 0 additions & 8 deletions client/multiledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,3 @@ func TestMultiLedgerDispute(t *testing.T) {
mlt := test.SetupMultiLedgerTest(t, testDuration)
ctest.TestMultiLedgerDispute(ctx, t, mlt, challengeDuration)
}

func TestEgoisticMultiLedger(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testDuration)
defer cancel()

mlt := test.EgoisticTest(t, testDuration)
ctest.TestMultiLedgerDispute(ctx, t, mlt, challengeDuration)
}
116 changes: 0 additions & 116 deletions client/test/multiledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,56 +92,6 @@ func SetupMultiLedgerTest(t *testing.T, testDuration time.Duration) ctest.MultiL
}
}

// EgoisticTest creates a egoistic multi-ledger test setup and tests egoistic functions.
func EgoisticTest(t *testing.T, testDuration time.Duration) ctest.MultiLedgerSetup {
t.Helper()
rng := test.Prng(t)

ctx, cancel := context.WithTimeout(context.Background(), testDuration)
defer cancel()

l1 := setupLedger(ctx, t, rng, big.NewInt(1337)) //nolint:gomnd
l2 := setupLedger(ctx, t, rng, big.NewInt(1338)) //nolint:gomnd
l3 := setupLedger(ctx, t, rng, big.NewInt(134)) //nolint:gomnd

// Setup message bus.
bus := wire.NewLocalBus()

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

// Setup clients.
testEgoisticLedger(t, rng, l1, l2, l3)

// Fund accounts.
l1.simSetup.SimBackend.FundAddress(ctx, wallet.AsEthAddr(c1.WalletAddress))
l1.simSetup.SimBackend.FundAddress(ctx, wallet.AsEthAddr(c2.WalletAddress))
l2.simSetup.SimBackend.FundAddress(ctx, wallet.AsEthAddr(c1.WalletAddress))
l2.simSetup.SimBackend.FundAddress(ctx, wallet.AsEthAddr(c2.WalletAddress))

//nolint:gomnd
return ctest.MultiLedgerSetup{
Client1: c1,
Client2: c2,
Asset1: l1.asset,
Asset2: l2.asset,
InitBalances: channel.Balances{
{EtherToWei(8), EtherToWei(2)}, // Asset 1.
{EtherToWei(2), EtherToWei(8)}, // Asset 2.
},
UpdateBalances1: channel.Balances{
{EtherToWei(5), EtherToWei(5)}, // Asset 1.
{EtherToWei(3), EtherToWei(7)}, // Asset 2.
},
UpdateBalances2: channel.Balances{
{EtherToWei(1), EtherToWei(9)}, // Asset 1.
{EtherToWei(5), EtherToWei(5)}, // Asset 2.
},
BalanceDelta: EtherToWei(0.00012),
}
}

type testLedger struct {
simSetup *chtest.SimSetup
adjudicator common.Address
Expand Down Expand Up @@ -204,7 +154,6 @@ 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)

registered := funderL1.RegisterAsset(*l1.asset, ethchannel.NewETHDepositor(defaultETHGasLimit), acc.Account)
require.True(registered)
registered = funderL1.RegisterAsset(*l2.asset, ethchannel.NewNoOpDepositor(), acc.Account)
Expand Down Expand Up @@ -252,71 +201,6 @@ func setupClient(t *testing.T, rng *rand.Rand, l1, l2 testLedger, bus wire.Bus)
}
}

func testEgoisticLedger(t *testing.T, rng *rand.Rand, l1, l2, l3 testLedger) {
t.Helper()
require := require.New(t)

// Setup wallet and account.
w := wtest.RandomWallet().(*keystore.Wallet)
acc := w.NewRandomAccount(rng).(*keystore.Account)

// Setup contract backends.
signer1 := l1.simSetup.SimBackend.Signer
cb1 := ethchannel.NewContractBackend(
l1.simSetup.CB,
l1.ChainID(),
keystore.NewTransactor(*w, signer1),
l1.simSetup.CB.TxFinalityDepth(),
)
signer2 := l2.simSetup.SimBackend.Signer
cb2 := ethchannel.NewContractBackend(
l2.simSetup.CB,
l2.ChainID(),
keystore.NewTransactor(*w, signer2),
l2.simSetup.CB.TxFinalityDepth(),
)

signer3 := l3.simSetup.SimBackend.Signer
cb3 := ethchannel.NewContractBackend(
l3.simSetup.CB,
l3.ChainID(),
keystore.NewTransactor(*w, signer3),
l3.simSetup.CB.TxFinalityDepth(),
)

// Setup funder.
multiFunder := multi.NewFunder()
funderL1 := ethchannel.NewFunder(cb1)
funderL2 := ethchannel.NewFunder(cb2)
funderL3 := ethchannel.NewFunder(cb3)
signers := 3
egoisticPart := make([]bool, signers)
egoisticPart[1] = true
funderL2.SetEgoisticPart(1, signers)
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)
require.True(registered)
registered = funderL2.RegisterAsset(*l1.asset, ethchannel.NewNoOpDepositor(), acc.Account)
require.True(registered)
registered = funderL2.RegisterAsset(*l2.asset, ethchannel.NewETHDepositor(defaultETHGasLimit), acc.Account)
require.True(registered)
registered = funderL3.RegisterAsset(*l1.asset, ethchannel.NewNoOpDepositor(), acc.Account)
require.True(registered)
registered = funderL3.RegisterAsset(*l2.asset, ethchannel.NewETHDepositor(defaultETHGasLimit), acc.Account)
require.True(registered)
multiFunder.RegisterFunder(l1.ChainID(), funderL1)
multiFunder.RegisterFunder(l2.ChainID(), funderL2)
multiFunder.RegisterFunder(l3.ChainID(), funderL3)
}

// EtherToWei converts eth to wei.
func EtherToWei(eth float64) *big.Int {
weiFloat := new(big.Float).Mul(big.NewFloat(eth), new(big.Float).SetFloat64(params.Ether))
Expand Down

0 comments on commit 93ff531

Please sign in to comment.