Skip to content

Commit

Permalink
test(connext): disable connext v1 simtests
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Ranna committed Nov 26, 2020
1 parent 41b05c7 commit dee041d
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 377 deletions.
10 changes: 6 additions & 4 deletions test/simulation/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"errors"
"fmt"
"github.com/ExchangeUnion/xud-simulation/connexttest"
"math/big"
// "github.com/ExchangeUnion/xud-simulation/connexttest"
// "math/big"
"time"

"github.com/roasbeef/btcutil"
Expand Down Expand Up @@ -56,13 +56,14 @@ func (a *actions) init(node *xudtest.HarnessNode) {
// Add currencies.
a.addCurrency(node, "BTC", xudrpc.Currency_LND, "", 8)
a.addCurrency(node, "LTC", xudrpc.Currency_LND, "", 8)
a.addCurrency(node, "ETH", xudrpc.Currency_CONNEXT, connexttest.ETHTokenAddress, 18)
// a.addCurrency(node, "ETH", xudrpc.Currency_CONNEXT, connexttest.ETHTokenAddress, 18)

// Add pairs.
a.addPair(node, "LTC", "BTC")
a.addPair(node, "BTC", "ETH")
// a.addPair(node, "BTC", "ETH")
}

/*
func (a *actions) FundETH(net *xudtest.NetworkHarness, node *xudtest.HarnessNode) {
// Wait for node's connext connection to catch-up.
a.waitConnextReady(node)
Expand All @@ -84,6 +85,7 @@ func (a *actions) FundETH(net *xudtest.NetworkHarness, node *xudtest.HarnessNode
a.assert.Equal(uint64(200000000), ethBal.WalletBalance)
a.assert.Equal(uint64(0), ethBal.ChannelBalance)
}
*/

func (a *actions) waitConnextReady(node *xudtest.HarnessNode) {
isReady := func() bool {
Expand Down
21 changes: 11 additions & 10 deletions test/simulation/docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env bash

if [[ $@ == "connext" || $# == 0 ]]
then
mkdir -p temp
pushd temp
git clone https://github.com/ConnextProject/indra.git
cd indra
git checkout indra-7.3.14
make
popd
fi
# TODO(karl): enable connext V2 simulation tests
# if [[ $@ == "connext" || $# == 0 ]]
# then
# mkdir -p temp
# pushd temp
# git clone https://github.com/ConnextProject/indra.git
# cd indra
# git checkout indra-7.3.14
# make
# popd
# fi

docker-compose build $@
22 changes: 11 additions & 11 deletions test/simulation/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ services:
build: ./docker-lnd
volumes:
- lnd-vol:/app
connext:
build: ./docker-connext
volumes:
- connext-vol:/app
# connext:
# build: ./docker-connext
# volumes:
# - connext-vol:/app
xud:
build: ./docker-xud
volumes:
Expand All @@ -29,26 +29,26 @@ services:
depends_on:
- btcd
- lnd
- connext
# - connext
- xud
- gomod
volumes:
- btcd-vol:/btcd-vol
- lnd-vol:/lnd-vol
- connext-vol:/connext-vol
# - connext-vol:/connext-vol
- xud-vol:/xud-vol
- custom-xud-vol:/custom-xud-vol
- nvm-vol:/nvm-vol
- gomod-vol:/gomod-vol
volumes:
btcd-vol:
lnd-vol:
connext-vol:
# connext-vol:
xud-vol:
custom-xud-vol:
nvm-vol:
gomod-vol:
networks:
default:
external:
name: indra
# networks:
# default:
# external:
# name: indra
14 changes: 7 additions & 7 deletions test/simulation/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# create the temp directories with the current user so it is the owner for permissions
mkdir -p $PWD/temp/logs
mkdir -p $PWD/temp/indra
# mkdir -p $PWD/temp/indra

pushd temp/indra
make start
popd
# pushd temp/indra
# make start
# popd

export DOCKER_CLIENT_TIMEOUT=120
export COMPOSE_HTTP_TIMEOUT=120
Expand All @@ -27,8 +27,8 @@ if [[ $testRetCode != 0 ]]; then
done
fi

pushd temp/indra
make reset
popd
# pushd temp/indra
# make reset
# popd

exit $testRetCode
177 changes: 2 additions & 175 deletions test/simulation/tests-instability.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,28 @@ var instabilityTestCases = []*testCase{
name: "maker crashed after send payment before preimage resolved; incoming: lnd, outgoing: lnd", // replacing Alice
test: testMakerCrashedAfterSendBeforePreimageResolved,
},
{
name: "maker crashed after send payment before preimage resolved; incoming: connext, outgoing: lnd", // replacing Alice
test: testMakerCrashedAfterSendBeforePreimageResolvedConnextIn,
},
{
name: "maker crashed after send payment after preimage resolved; incoming: lnd, outgoing: lnd", // replacing Alice
test: testMakerCrashedAfterSendAfterPreimageResolved,
},
{
name: "maker crashed after send payment after preimage resolved; incoming: connext, outgoing: lnd", // replacing Alice
test: testMakerCrashedAfterSendAfterPreimageResolvedConnextIn,
},
{
name: "maker lnd crashed before order settlement", // replacing Alice
test: testMakerLndCrashedBeforeSettlement,
},
{
name: "maker connext client crashed before order settlement", // replacing Alice
test: testMakerConnextClientCrashedBeforeSettlement,
},
{
name: "maker crashed after send payment with delayed settlement; incoming: lnd, outgoing: lnd", // replacing Alice + Bob
test: testMakerCrashedAfterSendDelayedSettlement,
},
{
name: "maker crashed after send payment with delayed settlement; incoming: connext, outgoing: lnd", // replacing Alice + Bob
test: testMakerCrashedAfterSendDelayedSettlementConnextIn,
},
{
name: "maker crashed after send payment with delayed settlement; incoming: lnd, outgoing: connext", // replacing Alice + Bob
test: testMakerCrashedAfterSendDelayedSettlementConnextOut,
},
}

func testMakerCrashedAfterSendBeforePreimageResolved(net *xudtest.NetworkHarness, ht *harnessTest) {
testMakerCrashedDuringSwap(net, ht, []string{"CUSTOM_SCENARIO=INSTABILITY::MAKER_CRASH_AFTER_SEND_BEFORE_PREIMAGE_RESOLVED"})
}

func testMakerCrashedAfterSendBeforePreimageResolvedConnextIn(net *xudtest.NetworkHarness, ht *harnessTest) {
ht.act.FundETH(net, net.Bob)
testMakerCrashedDuringSwapConnextIn(net, ht, []string{"CUSTOM_SCENARIO=INSTABILITY::MAKER_CRASH_AFTER_SEND_BEFORE_PREIMAGE_RESOLVED"})
}

func testMakerCrashedAfterSendAfterPreimageResolved(net *xudtest.NetworkHarness, ht *harnessTest) {
testMakerCrashedDuringSwap(net, ht, []string{"CUSTOM_SCENARIO=INSTABILITY::MAKER_CRASH_AFTER_SEND_AFTER_PREIMAGE_RESOLVED"})
}

func testMakerCrashedAfterSendAfterPreimageResolvedConnextIn(net *xudtest.NetworkHarness, ht *harnessTest) {
testMakerCrashedDuringSwapConnextIn(net, ht, []string{"CUSTOM_SCENARIO=INSTABILITY::MAKER_CRASH_AFTER_SEND_AFTER_PREIMAGE_RESOLVED"})
}

func testMakerCrashedDuringSwap(net *xudtest.NetworkHarness, ht *harnessTest, customXudMakerEnvVars []string) {
var err error
net.Alice, err = net.SetCustomXud(ht.ctx, ht, net.Alice, customXudMakerEnvVars)
Expand Down Expand Up @@ -125,67 +96,6 @@ func testMakerCrashedDuringSwap(net *xudtest.NetworkHarness, ht *harnessTest, cu
ht.assert.Equal(alicePrevLtcBalance+ltcQuantity, aliceLtcBalance, "alice did not receive LTC")
}

func testMakerCrashedDuringSwapConnextIn(net *xudtest.NetworkHarness, ht *harnessTest, makerEnvArgs []string) {
var err error
net.Alice, err = net.SetCustomXud(ht.ctx, ht, net.Alice, makerEnvArgs)
ht.assert.NoError(err)
ht.act.init(net.Alice)
ht.act.waitConnextReady(net.Alice)

// Connect Alice to Bob.
ht.act.connect(net.Alice, net.Bob)
ht.act.verifyConnectivity(net.Alice, net.Bob)

err = openETHChannel(ht.ctx, net.Bob, 40000, 0)
ht.assert.NoError(err)

// Save the initial balances.
alicePrevBalance, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"})
ht.assert.NoError(err)
alicePrevEthBalance := alicePrevBalance.Balances["ETH"]

// Place an order on Alice.
aliceOrderReq := &xudrpc.PlaceOrderRequest{
OrderId: "testMakerCrashedDuringSwapConnextIn",
Price: 40,
Quantity: 100,
PairId: "BTC/ETH",
Side: xudrpc.OrderSide_SELL,
}
ht.act.placeOrderAndBroadcast(net.Alice, net.Bob, aliceOrderReq)

// brief wait for collateralization to complete for Alice
time.Sleep(1 * time.Second)

// Place a matching order on Bob.
bobOrderReq := &xudrpc.PlaceOrderRequest{
OrderId: "testMakerCrashedDuringSwapConnextIn",
Price: aliceOrderReq.Price,
Quantity: aliceOrderReq.Quantity,
PairId: aliceOrderReq.PairId,
Side: xudrpc.OrderSide_BUY,
}

_, err = net.Bob.Client.PlaceOrderSync(ht.ctx, bobOrderReq)
ht.assert.NoError(err)

<-net.Alice.ProcessExit

err = net.Alice.Start(nil)
ht.assert.NoError(err)
ht.act.waitConnextReady(net.Alice)

// Brief delay to allow for swap to be recovered consistently.
time.Sleep(3 * time.Second)

// Verify that Alice recovered ETH funds.
aliceBalance, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"})
ht.assert.NoError(err)
aliceEthBalance := aliceBalance.Balances["ETH"]
diff := uint64(float64(aliceOrderReq.Quantity) * aliceOrderReq.Price)
ht.assert.Equal(alicePrevEthBalance.ChannelBalance+diff, aliceEthBalance.ChannelBalance, "alice did not recover ETH funds")
}

func testMakerLndCrashedBeforeSettlement(net *xudtest.NetworkHarness, ht *harnessTest) {
var err error
net.Alice, err = net.SetCustomXud(ht.ctx, ht, net.Alice, []string{
Expand Down Expand Up @@ -247,89 +157,6 @@ func testMakerLndCrashedBeforeSettlement(net *xudtest.NetworkHarness, ht *harnes
ht.assert.Equal(alicePrevLtcBalance+ltcQuantity, aliceLtcBalance, "alice did not recover LTC funds")
}

func testMakerConnextClientCrashedBeforeSettlement(net *xudtest.NetworkHarness, ht *harnessTest) {
var err error
net.Alice, err = net.SetCustomXud(ht.ctx, ht, net.Alice, []string{
"CUSTOM_SCENARIO=INSTABILITY::MAKER_CLIENT_CRASHED_BEFORE_SETTLE",
"CLIENT_TYPE=ConnextClient",
// connext-client should be replaced, so we're not specifying its current PID,
// as in other client types.
})

ht.assert.NoError(err)
ht.act.init(net.Alice)
ht.act.waitConnextReady(net.Alice)
ht.act.waitConnextReady(net.Bob)

// Connect Alice to Bob.
ht.act.connect(net.Alice, net.Bob)
ht.act.verifyConnectivity(net.Alice, net.Bob)

err = openETHChannel(ht.ctx, net.Bob, 40000, 0)
ht.assert.NoError(err)

// Save the initial balances.
alicePrevBalance, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"})
ht.assert.NoError(err)
alicePrevEthBalance := alicePrevBalance.Balances["ETH"]

bobPrevBalance, err := net.Bob.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "BTC"})
ht.assert.NoError(err)
bobPrevBtcBalance := bobPrevBalance.Balances["BTC"]

// Place an order on Alice.
aliceOrderReq := &xudrpc.PlaceOrderRequest{
OrderId: "testMakerConnextClientCrashedBeforeSettlement",
Price: 40,
Quantity: 100,
PairId: "BTC/ETH",
Side: xudrpc.OrderSide_SELL,
}
ht.act.placeOrderAndBroadcast(net.Alice, net.Bob, aliceOrderReq)

// brief wait for collateralization to complete for Alice
time.Sleep(1 * time.Second)

// Place a matching order on Bob.
bobOrderReq := &xudrpc.PlaceOrderRequest{
OrderId: "testMakerConnextClientCrashedBeforeSettlement",
Price: aliceOrderReq.Price,
Quantity: aliceOrderReq.Quantity,
PairId: aliceOrderReq.PairId,
Side: xudrpc.OrderSide_BUY,
}
go net.Bob.Client.PlaceOrderSync(ht.ctx, bobOrderReq)

// Alice's connext-client is expected to be killed by Alice's custom xud.
<-net.Alice.ConnextClient.ProcessExit

// Wait a bit so that Alice's call to connext-client for settlement would fail.
time.Sleep(5 * time.Second)

// Restart Alice's connext-client.
err = net.Alice.ConnextClient.Start(nil)
ht.assert.NoError(err)
ht.act.waitConnextReady(net.Alice)

// Brief delay to allow for swap to be recovered consistently.
// The pending swap recheck interval is usually 5m, but was adjusted in
// Alice's custom xud to 5s (as well as the swap completion timeout interval).
time.Sleep(10 * time.Second)

// Verify that both parties received their payment.
bobBalance, err := net.Bob.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "BTC"})
ht.assert.NoError(err)
bobBtcBalance := bobBalance.Balances["BTC"]
diff := bobOrderReq.Quantity
ht.assert.Equal(bobPrevBtcBalance.ChannelBalance+diff, bobBtcBalance.ChannelBalance)

aliceBalance, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"})
ht.assert.NoError(err)
aliceEthBalance := aliceBalance.Balances["ETH"]
diff = uint64(float64(aliceOrderReq.Quantity) * aliceOrderReq.Price)
ht.assert.Equal(alicePrevEthBalance.ChannelBalance+diff, aliceEthBalance.ChannelBalance, "alice did not recover ETH funds")
}

func testMakerCrashedAfterSendDelayedSettlement(net *xudtest.NetworkHarness, ht *harnessTest) {
var err error
net.Alice, err = net.SetCustomXud(ht.ctx, ht, net.Alice, []string{"CUSTOM_SCENARIO=INSTABILITY::MAKER_CRASH_WHILE_SENDING"})
Expand Down Expand Up @@ -401,7 +228,7 @@ func testMakerCrashedAfterSendDelayedSettlementConnextOut(net *xudtest.NetworkHa
ht.assert.NoError(err)

ht.act.init(net.Alice)
ht.act.FundETH(net, net.Alice)
// ht.act.FundETH(net, net.Alice)

ht.act.init(net.Bob)
ht.act.waitConnextReady(net.Bob)
Expand Down Expand Up @@ -490,7 +317,7 @@ func testMakerCrashedAfterSendDelayedSettlementConnextIn(net *xudtest.NetworkHar
ht.act.waitConnextReady(net.Alice)

ht.act.init(net.Bob)
ht.act.FundETH(net, net.Bob)
// ht.act.FundETH(net, net.Bob)

// Connect Alice to Bob.
ht.act.connect(net.Alice, net.Bob)
Expand Down
Loading

0 comments on commit dee041d

Please sign in to comment.