From 41b05c7d6d780724920080518884b45209119a8a Mon Sep 17 00:00:00 2001 From: Karl Ranna Date: Thu, 26 Nov 2020 15:39:38 +0000 Subject: [PATCH 1/2] cleanup unit/integration tests --- lib/connextclient/ConnextClient.ts | 2 +- lib/swaps/consts.ts | 2 +- test/jest/Connext.spec.ts | 96 +++++++++----------- test/jest/HttpServer.spec.ts | 6 +- test/jest/HttpService.spec.ts | 6 +- test/jest/SwapClientManager.spec.ts | 1 + test/jest/__snapshots__/Connext.spec.ts.snap | 4 +- 7 files changed, 55 insertions(+), 62 deletions(-) diff --git a/lib/connextclient/ConnextClient.ts b/lib/connextclient/ConnextClient.ts index baf4c9291..2e8652c1d 100644 --- a/lib/connextclient/ConnextClient.ts +++ b/lib/connextclient/ConnextClient.ts @@ -698,7 +698,7 @@ class ConnextClient extends SwapClient { return { state: PaymentState.Pending }; } } catch (err) { - if (err.code === errorCodes.PAYMENT_NOT_FOUND) { + if (err.code === errorCodes.NOT_FOUND) { this.logger.trace(`hashlock status for connext transfer with hash ${rHash} not found`); return { state: PaymentState.Failed }; } diff --git a/lib/swaps/consts.ts b/lib/swaps/consts.ts index f8c7d55de..0ebff347d 100644 --- a/lib/swaps/consts.ts +++ b/lib/swaps/consts.ts @@ -3,4 +3,4 @@ export const MAX_FEE_RATIO = 0.03; /** The maximum time in milliseconds to wait for a client to be ready. */ export const BASE_MAX_CLIENT_WAIT_TIME = 6000; /** The maximum time in milliseconds we will wait for a swap payment to complete. */ -export const MAX_PAYMENT_TIME = 15000; +export const MAX_PAYMENT_TIME = 90000; diff --git a/test/jest/Connext.spec.ts b/test/jest/Connext.spec.ts index e6a84048c..87a0f7911 100644 --- a/test/jest/Connext.spec.ts +++ b/test/jest/Connext.spec.ts @@ -60,6 +60,7 @@ describe('ConnextClient', () => { port: 1337, webhookhost: 'http://testerson', webhookport: 7331, + nodeIdentifier: 'vector321', }; const logger = new mockedLogger(); logger.trace = jest.fn(); @@ -89,6 +90,7 @@ describe('ConnextClient', () => { currencyInstances, logger, unitConverter: new UnitConverter(), + network: 'mainnet', }); }); @@ -227,7 +229,15 @@ describe('ConnextClient', () => { expect.assertions(1); connext['getHashLockStatus'] = jest .fn() - .mockReturnValue({ status: 'PENDING' }); + .mockReturnValue({ + transferState: { + expiry: "10001", + }, + transferResolver: {}, + }); + connext['getHeight'] = jest + .fn() + .mockReturnValue(10000); const result = await connext['lookupPayment']('0x12345', 'ETH'); expect(result).toEqual({ state: PaymentState.Pending }); }); @@ -236,78 +246,58 @@ describe('ConnextClient', () => { expect.assertions(1); connext['getHashLockStatus'] = jest .fn() - .mockReturnValue({ status: 'COMPLETED', preImage: '0x1337' }); + .mockReturnValue({ + transferState: { + expiry: "10001", + }, + transferResolver: { + preImage: '0x1337', + }, + }); + connext['getHeight'] = jest + .fn() + .mockReturnValue(10000); const result = await connext['lookupPayment']('0x12345', 'ETH'); expect(result).toEqual({ state: PaymentState.Succeeded, preimage: '1337' }); }); - it('returns PaymentState.Failed when rejected app install for payment without status field', async () => { - expect.assertions(3); - const senderAppIdentityHash = '12345'; + it('returns PaymentState.Failed when preimage is hash zero', async () => { + expect.assertions(1); connext['getHashLockStatus'] = jest .fn() .mockReturnValue({ - senderAppIdentityHash, + transferState: { + expiry: "10001", + }, + transferResolver: { + preImage: '0x0000000000000000000000000000000000000000000000000000000000000000', + }, }); - connext['sendRequest'] = jest.fn().mockReturnValue(Promise.resolve()); + connext['getHeight'] = jest + .fn() + .mockReturnValue(10000); const result = await connext['lookupPayment']('0x12345', 'ETH'); - expect(connext['sendRequest']).toHaveBeenCalledTimes(1); - expect(connext['sendRequest']).toHaveBeenCalledWith( - '/reject-install', - 'POST', - expect.objectContaining({ appIdentityHash: senderAppIdentityHash }), - ); expect(result).toEqual({ state: PaymentState.Failed }); }); - it('returns PaymentState.Pending when failing to reject app install for payment without status field', async () => { - expect.assertions(3); - const senderAppIdentityHash = '12345'; + it('returns PaymentState.Failed when EXPIRED', async () => { + expect.assertions(1); connext['getHashLockStatus'] = jest .fn() .mockReturnValue({ - senderAppIdentityHash, + transferState: { + expiry: "10001", + }, + transferResolver: {}, }); - connext['sendRequest'] = jest.fn().mockReturnValue(Promise.reject()); - const result = await connext['lookupPayment']('0x12345', 'ETH'); - expect(connext['sendRequest']).toHaveBeenCalledTimes(1); - expect(connext['sendRequest']).toHaveBeenCalledWith( - '/reject-install', - 'POST', - expect.objectContaining({ appIdentityHash: senderAppIdentityHash }), - ); - expect(result).toEqual({ state: PaymentState.Pending }); - }); - - it('returns PaymentState.Failed when EXPIRED', async () => { - expect.assertions(3); - connext['getHashLockStatus'] = jest + connext['getHeight'] = jest .fn() - .mockReturnValue({ status: 'EXPIRED' }); + .mockReturnValue(10001); connext['sendRequest'] = jest.fn().mockReturnValue(Promise.resolve()); const hash = '8f28fb27a164ae992fb4808b11c137d06e8e7d9304043a6b7163323f7cf53920'; const currency = 'ETH'; const result = await connext['lookupPayment'](hash, currency); expect(result).toEqual({ state: PaymentState.Failed }); - expect(connext['sendRequest']).toHaveBeenCalledTimes(1); - expect(connext['sendRequest']).toHaveBeenCalledWith( - '/hashlock-resolve', - 'POST', - expect.objectContaining({ - assetId: ETH_ASSET_ID, - preImage: '0x', - paymentId: '0xb2c0648834d105f3b372c6a05d11b0f19d88a8909f6315c8535e383e59991f8e', - }), - ); - }); - - it('returns PaymentState.Failed when FAILED', async () => { - expect.assertions(1); - connext['getHashLockStatus'] = jest - .fn() - .mockReturnValue({ status: 'FAILED' }); - const result = await connext['lookupPayment']('0x12345', 'ETH'); - expect(result).toEqual({ state: PaymentState.Failed }); }); it('returns PaymentState.Pending when error is unknown', async () => { @@ -321,12 +311,12 @@ describe('ConnextClient', () => { expect(result).toEqual({ state: PaymentState.Pending }); }); - it('returns PaymentState.Failed when error is PAYMENT_NOT_FOUND', async () => { + it('returns PaymentState.Failed when error is NOT_FOUND', async () => { expect.assertions(1); connext['getHashLockStatus'] = jest .fn() .mockImplementation(() => { - throw errors.PAYMENT_NOT_FOUND; + throw errors.NOT_FOUND; }); const result = await connext['lookupPayment']('0x12345', 'ETH'); expect(result).toEqual({ state: PaymentState.Failed }); diff --git a/test/jest/HttpServer.spec.ts b/test/jest/HttpServer.spec.ts index 2d14d42fd..c23e2b23d 100644 --- a/test/jest/HttpServer.spec.ts +++ b/test/jest/HttpServer.spec.ts @@ -29,7 +29,11 @@ describe('HttpServer - preimage', () => { it('should receive and parse a preimage request', (done) => { request(`http://localhost:${port}`) .post('/preimage') - .send({ data: { transferMeta: { preImage } } }) + .send({ + transfer: { + transferResolver: { preImage } + } + }) .expect(200) .expect('Content-Type', 'application/json') .end((err) => { diff --git a/test/jest/HttpService.spec.ts b/test/jest/HttpService.spec.ts index 09c3c6aa2..3b0eff6d6 100644 --- a/test/jest/HttpService.spec.ts +++ b/test/jest/HttpService.spec.ts @@ -7,10 +7,8 @@ const mockedService = >Service; const rHash = 'd92e2eb0e9118faedc5ce533b65737b33a88c187c10e74e6d8b1be34626ae892'; const preImage = 'd55dd2b285a815f9449d9e665ed61dd19663e08e9d4e84db621ca3e78082fabf'; const preimageRequest: any = { - id: '1', - data: { - type: '', - transferMeta: { + transfer: { + transferResolver: { preImage: `0x${preImage}`, }, }, diff --git a/test/jest/SwapClientManager.spec.ts b/test/jest/SwapClientManager.spec.ts index 1308be9f1..8a207601a 100644 --- a/test/jest/SwapClientManager.spec.ts +++ b/test/jest/SwapClientManager.spec.ts @@ -103,6 +103,7 @@ describe('Swaps.SwapClientManager', () => { port: 4321, webhookhost: 'localhost', webhookport: 4422, + nodeIdentifier: 'vector123', }; config.strict = true; db = new DB(loggers.db, config.dbpath); diff --git a/test/jest/__snapshots__/Connext.spec.ts.snap b/test/jest/__snapshots__/Connext.spec.ts.snap index 2a720846b..2880c5393 100644 --- a/test/jest/__snapshots__/Connext.spec.ts.snap +++ b/test/jest/__snapshots__/Connext.spec.ts.snap @@ -2,8 +2,8 @@ exports[`ConnextClient sendRequest deposit fails with 404 1`] = ` Object { - "code": "8.8", - "message": "connext payment not found", + "code": "8.18", + "message": "connext returned not found response", } `; From dee041d55c503fece5b8687726e9e73cbd4eb24f Mon Sep 17 00:00:00 2001 From: Karl Ranna Date: Thu, 26 Nov 2020 18:51:31 +0000 Subject: [PATCH 2/2] test(connext): disable connext v1 simtests --- test/simulation/actions.go | 10 +- test/simulation/docker-build.sh | 21 ++-- test/simulation/docker-compose.yml | 22 ++-- test/simulation/docker-run.sh | 14 +-- test/simulation/tests-instability.go | 177 +-------------------------- test/simulation/tests-integration.go | 144 ++++++---------------- test/simulation/xud_test.go | 76 +++++++----- test/simulation/xudtest/harness.go | 26 ++-- test/simulation/xudtest/node.go | 43 ++++--- 9 files changed, 156 insertions(+), 377 deletions(-) diff --git a/test/simulation/actions.go b/test/simulation/actions.go index dac411f9d..93060d330 100644 --- a/test/simulation/actions.go +++ b/test/simulation/actions.go @@ -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" @@ -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) @@ -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 { diff --git a/test/simulation/docker-build.sh b/test/simulation/docker-build.sh index da4a704c1..4b94b096a 100755 --- a/test/simulation/docker-build.sh +++ b/test/simulation/docker-build.sh @@ -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 $@ diff --git a/test/simulation/docker-compose.yml b/test/simulation/docker-compose.yml index c40cb107a..0719b9b47 100644 --- a/test/simulation/docker-compose.yml +++ b/test/simulation/docker-compose.yml @@ -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: @@ -29,13 +29,13 @@ 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 @@ -43,12 +43,12 @@ services: 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 diff --git a/test/simulation/docker-run.sh b/test/simulation/docker-run.sh index 852371aef..0fef13519 100755 --- a/test/simulation/docker-run.sh +++ b/test/simulation/docker-run.sh @@ -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 @@ -27,8 +27,8 @@ if [[ $testRetCode != 0 ]]; then done fi -pushd temp/indra -make reset -popd +# pushd temp/indra +# make reset +# popd exit $testRetCode diff --git a/test/simulation/tests-instability.go b/test/simulation/tests-instability.go index 7c2ece779..41b9d8fee 100644 --- a/test/simulation/tests-instability.go +++ b/test/simulation/tests-instability.go @@ -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) @@ -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{ @@ -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"}) @@ -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) @@ -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) diff --git a/test/simulation/tests-integration.go b/test/simulation/tests-integration.go index 8c19a6eb2..05c6f334a 100644 --- a/test/simulation/tests-integration.go +++ b/test/simulation/tests-integration.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/ExchangeUnion/xud-simulation/connexttest" + // "github.com/ExchangeUnion/xud-simulation/connexttest" "time" "github.com/ExchangeUnion/xud-simulation/xudrpc" @@ -18,10 +18,6 @@ var integrationTestCases = []*testCase{ name: "order matching and swap", test: testOrderMatchingAndSwap, }, - { - name: "order matching and swap connext", - test: testOrderMatchingAndSwapConnext, - }, { name: "dust order discarded", test: testDustOrderDiscarded, @@ -244,15 +240,15 @@ func testInternalMatchAndInvalidation(net *xudtest.NetworkHarness, ht *harnessTe func testRuntimeAddPairActiveOrders(net *xudtest.NetworkHarness, ht *harnessTest) { // Remove previously-added pairs/currencies from both Alice and Bob. ht.act.removePair(net.Alice, "LTC/BTC") - ht.act.removePair(net.Alice, "BTC/ETH") + // ht.act.removePair(net.Alice, "BTC/ETH") ht.act.removeCurrency(net.Alice, "LTC") ht.act.removeCurrency(net.Alice, "BTC") - ht.act.removeCurrency(net.Alice, "ETH") + // ht.act.removeCurrency(net.Alice, "ETH") ht.act.removePair(net.Bob, "LTC/BTC") - ht.act.removePair(net.Bob, "BTC/ETH") + // ht.act.removePair(net.Bob, "BTC/ETH") ht.act.removeCurrency(net.Bob, "LTC") ht.act.removeCurrency(net.Bob, "BTC") - ht.act.removeCurrency(net.Bob, "ETH") + // ht.act.removeCurrency(net.Bob, "ETH") // Connect Alice to Bob. ht.act.connect(net.Alice, net.Bob) @@ -261,9 +257,10 @@ func testRuntimeAddPairActiveOrders(net *xudtest.NetworkHarness, ht *harnessTest // Re-add the pairs/currencies to Alice after peer connection was already established. ht.act.addCurrency(net.Alice, "BTC", xudrpc.Currency_LND, "", 8) ht.act.addCurrency(net.Alice, "LTC", xudrpc.Currency_LND, "", 8) - ht.act.addCurrency(net.Alice, "ETH", xudrpc.Currency_CONNEXT, connexttest.ETHTokenAddress, 18) + // TODO(karl): enable connext V2 simulation tests + // ht.act.addCurrency(net.Alice, "ETH", xudrpc.Currency_CONNEXT, connexttest.ETHTokenAddress, 18) ht.act.addPair(net.Alice, "LTC", "BTC") - ht.act.addPair(net.Alice, "BTC", "ETH") + // ht.act.addPair(net.Alice, "BTC", "ETH") // Place LTC/BTC order on Alice. req := &xudrpc.PlaceOrderRequest{ @@ -296,33 +293,35 @@ func testRuntimeAddPairActiveOrders(net *xudtest.NetworkHarness, ht *harnessTest ht.act.removeOrderAndInvalidate(net.Alice, net.Bob, res.RemainingOrder) // Place BTC/ETH order on Alice. - req = &xudrpc.PlaceOrderRequest{ - OrderId: "maker_order_id", - Price: 40, - Quantity: 100, - PairId: "BTC/ETH", - Side: xudrpc.OrderSide_BUY, - } - res, err = net.Alice.Client.PlaceOrderSync(ht.ctx, req) - ht.assert.NoError(err) - ht.assert.Len(res.InternalMatches, 0) - ht.assert.Len(res.SwapSuccesses, 0) - ht.assert.Len(res.SwapFailures, 0) - ht.assert.NotNil(res.RemainingOrder) - - // Bob should receive the order once his BTC/ETH pair is re-added. - bobOrdersChan = subscribeOrders(ht.ctx, net.Bob) - ht.act.addCurrency(net.Bob, "ETH", xudrpc.Currency_CONNEXT, connexttest.ETHTokenAddress, 18) - ht.act.addPair(net.Bob, "BTC", "ETH") - - e = <-bobOrdersChan - ht.assert.NoError(e.err) - ht.assert.NotNil(e.orderUpdate) - peerOrder = e.orderUpdate.GetOrder() - ht.assert.Equal(peerOrder.Id, res.RemainingOrder.Id) - ht.assert.Equal(peerOrder.PairId, req.PairId) - ht.assert.Equal(peerOrder.NodeIdentifier.NodePubKey, net.Alice.PubKey()) - ht.act.removeOrderAndInvalidate(net.Alice, net.Bob, res.RemainingOrder) + /* + req = &xudrpc.PlaceOrderRequest{ + OrderId: "maker_order_id", + Price: 40, + Quantity: 100, + PairId: "BTC/ETH", + Side: xudrpc.OrderSide_BUY, + } + res, err = net.Alice.Client.PlaceOrderSync(ht.ctx, req) + ht.assert.NoError(err) + ht.assert.Len(res.InternalMatches, 0) + ht.assert.Len(res.SwapSuccesses, 0) + ht.assert.Len(res.SwapFailures, 0) + ht.assert.NotNil(res.RemainingOrder) + + // Bob should receive the order once his BTC/ETH pair is re-added. + bobOrdersChan = subscribeOrders(ht.ctx, net.Bob) + ht.act.addCurrency(net.Bob, "ETH", xudrpc.Currency_CONNEXT, connexttest.ETHTokenAddress, 18) + ht.act.addPair(net.Bob, "BTC", "ETH") + + e = <-bobOrdersChan + ht.assert.NoError(e.err) + ht.assert.NotNil(e.orderUpdate) + peerOrder = e.orderUpdate.GetOrder() + ht.assert.Equal(peerOrder.Id, res.RemainingOrder.Id) + ht.assert.Equal(peerOrder.PairId, req.PairId) + ht.assert.Equal(peerOrder.NodeIdentifier.NodePubKey, net.Alice.PubKey()) + ht.act.removeOrderAndInvalidate(net.Alice, net.Bob, res.RemainingOrder) + */ // Cleanup. ht.act.disconnect(net.Alice, net.Bob) @@ -491,75 +490,6 @@ func testOrderReplacement(net *xudtest.NetworkHarness, ht *harnessTest) { ht.act.disconnect(net.Alice, net.Bob) } -func testOrderMatchingAndSwapConnext(net *xudtest.NetworkHarness, ht *harnessTest) { - // Connect Alice to Bob. - ht.act.connect(net.Alice, net.Bob) - ht.act.verifyConnectivity(net.Alice, net.Bob) - - ht.act.FundETH(net, net.Alice) - - preChanAliceBal, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"}) - ht.assert.NoError(err) - preChanAliceEthBal := preChanAliceBal.Balances["ETH"] - - // Open channel from Alice. - err = openETHChannel(ht.ctx, net.Alice, 40000, 0) - ht.assert.NoError(err) - // wait for 1 block for the deposit transaction to confirm - time.Sleep(15 * time.Second) - - // Verify Alice ETH balance. - chanFeesThreshold := uint64(2100) - preSwapAliceBal, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"}) - preSwapAliceEthBal := preSwapAliceBal.Balances["ETH"] - ht.assert.True(preChanAliceEthBal.TotalBalance-preSwapAliceEthBal.TotalBalance <= chanFeesThreshold) - ht.assert.Equal(preSwapAliceEthBal.TotalBalance-preSwapAliceEthBal.ChannelBalance, preSwapAliceEthBal.WalletBalance) - ht.assert.Equal(uint64(40000), preSwapAliceEthBal.ChannelBalance) - - // wait for 1 block for node to collateralize ETH channel - time.Sleep(15 * time.Second) - - // Place an order on Alice. - req := &xudrpc.PlaceOrderRequest{ - OrderId: "maker_order_id", - Price: 40, - Quantity: 100, - PairId: "BTC/ETH", - Side: xudrpc.OrderSide_BUY, - } - ht.act.placeOrderAndBroadcast(net.Alice, net.Bob, req) - - // Place a matching order on Bob. - req = &xudrpc.PlaceOrderRequest{ - OrderId: "taker_order_id", - Price: req.Price, - Quantity: req.Quantity, - PairId: req.PairId, - Side: xudrpc.OrderSide_SELL, - } - ht.act.placeOrderAndSwap(net.Bob, net.Alice, req) - - time.Sleep(5 * time.Second) - - // Verify Alice ETH balance. - amt := uint64(req.Price * float64(req.Quantity)) - aliceBal, err := net.Alice.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"}) - aliceEthBal := aliceBal.Balances["ETH"] - ht.assert.Equal(preSwapAliceEthBal.TotalBalance-amt, aliceEthBal.TotalBalance) - ht.assert.Equal(aliceEthBal.TotalBalance-aliceEthBal.ChannelBalance, aliceEthBal.WalletBalance) - ht.assert.Equal(preSwapAliceEthBal.ChannelBalance-amt, aliceEthBal.ChannelBalance) - - // Verify Bob ETH balance. - bobBalance, err := net.Bob.Client.GetBalance(ht.ctx, &xudrpc.GetBalanceRequest{Currency: "ETH"}) - bobEthBalance := bobBalance.Balances["ETH"] - ht.assert.Equal(amt, bobEthBalance.TotalBalance) - ht.assert.Equal(uint64(0), bobEthBalance.WalletBalance) - ht.assert.Equal(amt, bobEthBalance.ChannelBalance) - - // Cleanup. - ht.act.disconnect(net.Alice, net.Bob) -} - func testMultiHopSwap(net *xudtest.NetworkHarness, ht *harnessTest) { // Connect Alice to Dave. ht.act.connect(net.Alice, net.Dave) diff --git a/test/simulation/xud_test.go b/test/simulation/xud_test.go index 49947c2bd..9648e8710 100644 --- a/test/simulation/xud_test.go +++ b/test/simulation/xud_test.go @@ -3,11 +3,11 @@ package main import ( "context" "fmt" - "github.com/ExchangeUnion/xud-simulation/connexttest" - "github.com/ethereum/go-ethereum/ethclient" + // "github.com/ExchangeUnion/xud-simulation/connexttest" + // "github.com/ethereum/go-ethereum/ethclient" "github.com/stretchr/testify/require" "log" - "net/http" + // "net/http" "os" "strings" "testing" @@ -275,6 +275,7 @@ func TestSecurityUnsettledChannels(t *testing.T) { } } +/* func verifyEthProviderReachability() error { client, err := ethclient.Dial(connexttest.EthProviderURL) if err != nil { @@ -297,14 +298,17 @@ func verifyConnextNodeReachability() error { return nil } +*/ func launchNetwork(noBalanceChecks bool) (*xudtest.NetworkHarness, func()) { - if err := verifyEthProviderReachability(); err != nil { - log.Fatalf("EthProvider reachability failure: %v", err) - } - if err := verifyConnextNodeReachability(); err != nil { - log.Fatalf("Connext node reachability failure: %v", err) - } + /* + if err := verifyEthProviderReachability(); err != nil { + log.Fatalf("EthProvider reachability failure: %v", err) + } + if err := verifyConnextNodeReachability(); err != nil { + log.Fatalf("Connext node reachability failure: %v", err) + } + */ // Create XUD network instance without launching it. log.Printf("xud: creating network") @@ -439,34 +443,36 @@ func launchNetwork(noBalanceChecks bool) (*xudtest.NetworkHarness, func()) { log.Fatalf("lnd-btc: unable to set up test network: %v", err) } - connextNetworkHarness := connexttest.NewNetworkHarness() - go func() { - for { - select { - case err, more := <-connextNetworkHarness.ProcessErrors(): - if !more { - return + /* + connextNetworkHarness := connexttest.NewNetworkHarness() + go func() { + for { + select { + case err, more := <-connextNetworkHarness.ProcessErrors(): + if !more { + return + } + if strings.Contains(err.Err.Error(), "signal: terminated") { + continue + } + + log.Printf("connext: finished with error (stderr):\n%v", err) } - if strings.Contains(err.Err.Error(), "signal: terminated") { - continue - } - - log.Printf("connext: finished with error (stderr):\n%v", err) } + }() + log.Printf("connext: launching network...") + if err := connextNetworkHarness.SetUp(); err != nil { + log.Fatalf("connext: unable to set up test network: %v", err) } - }() - log.Printf("connext: launching network...") - if err := connextNetworkHarness.SetUp(); err != nil { - log.Fatalf("connext: unable to set up test network: %v", err) - } - if err := connextNetworkHarness.Start(); err != nil { - log.Fatalf("connext: unable to start test network: %v", err) - } + if err := connextNetworkHarness.Start(); err != nil { + log.Fatalf("connext: unable to start test network: %v", err) + } + */ // Launch XUD network. xudHarness.SetLnd(lndBtcNetworkHarness, "BTC") xudHarness.SetLnd(lndLtcNetworkHarness, "LTC") - xudHarness.SetConnext(connextNetworkHarness) + // xudHarness.SetConnext(connextNetworkHarness) log.Printf("xud: launching network...") if err := xudHarness.Start(); err != nil { @@ -495,10 +501,12 @@ func launchNetwork(noBalanceChecks bool) (*xudtest.NetworkHarness, func()) { } log.Printf("ltcd: harness teared down") - if err := connextNetworkHarness.TearDownAll(); err != nil { - log.Printf("connext: cannot tear down network harness: %v", err) - } - log.Printf("connext: network harness teared down") + /* + if err := connextNetworkHarness.TearDownAll(); err != nil { + log.Printf("connext: cannot tear down network harness: %v", err) + } + log.Printf("connext: network harness teared down") + */ if err := xudHarness.TearDownAll(cfg.XudKill, cfg.XudCleanup); err != nil { log.Fatalf("cannot tear down xud network harness: %v", err) diff --git a/test/simulation/xudtest/harness.go b/test/simulation/xudtest/harness.go index 01f169c73..f1b7a4a5e 100644 --- a/test/simulation/xudtest/harness.go +++ b/test/simulation/xudtest/harness.go @@ -2,8 +2,8 @@ package xudtest import ( "context" - "fmt" - "github.com/ExchangeUnion/xud-simulation/connexttest" + // "fmt" + // "github.com/ExchangeUnion/xud-simulation/connexttest" "sync" "time" @@ -25,9 +25,9 @@ type NetworkHarness struct { Carol *HarnessNode Dave *HarnessNode - LndBtcNetwork *lntest.NetworkHarness - LndLtcNetwork *lntest.NetworkHarness - ConnextNetwork *connexttest.NetworkHarness + LndBtcNetwork *lntest.NetworkHarness + LndLtcNetwork *lntest.NetworkHarness + // ConnextNetwork *connexttest.NetworkHarness errorChan chan *XudError @@ -50,6 +50,7 @@ type CtxSetter interface { SetCtx(ctx context.Context, cancel context.CancelFunc) } +/* func (n *NetworkHarness) newConnextClient(ctx context.Context, node *HarnessNode, envVars *[]string) (*connexttest.HarnessClient, error) { if err := n.ConnextNetwork.TearDown(node.ConnextClient.ID); err != nil { return nil, err @@ -72,14 +73,17 @@ func (n *NetworkHarness) newConnextClient(ctx context.Context, node *HarnessNode return client, nil } +*/ func (n *NetworkHarness) SetCustomXud(ctx context.Context, ctxSetter CtxSetter, node *HarnessNode, envVars []string) (*HarnessNode, error) { t := time.Now() - connextClient, err := n.newConnextClient(ctx, node, &envVars) - if err != nil { - return nil, err - } + /* + connextClient, err := n.newConnextClient(ctx, node, &envVars) + if err != nil { + return nil, err + } + */ if err := node.shutdown(true, true); err != nil { return nil, err @@ -93,7 +97,7 @@ func (n *NetworkHarness) SetCustomXud(ctx context.Context, ctxSetter CtxSetter, customNode.SetEnvVars(envVars) customNode.SetLnd(node.LndBtcNode, "BTC") customNode.SetLnd(node.LndLtcNode, "LTC") - customNode.SetConnextClient(connextClient) + // customNode.SetConnextClient(connextClient) if err := customNode.Start(n.errorChan); err != nil { return nil, err @@ -193,6 +197,7 @@ func (n *NetworkHarness) SetLnd(ln *lntest.NetworkHarness, chain string) { n.Dave.SetLnd(ln.Dave, chain) } +/* func (n *NetworkHarness) SetConnext(net *connexttest.NetworkHarness) { n.ConnextNetwork = net n.Alice.SetConnextClient(net.Alice) @@ -200,6 +205,7 @@ func (n *NetworkHarness) SetConnext(net *connexttest.NetworkHarness) { n.Carol.SetConnextClient(net.Carol) n.Dave.SetConnextClient(net.Dave) } +*/ // ProcessErrors returns a channel used for reporting any fatal process errors. // If any of the active nodes within the harness' test network incur a fatal diff --git a/test/simulation/xudtest/node.go b/test/simulation/xudtest/node.go index ca6921f5d..aff97d607 100644 --- a/test/simulation/xudtest/node.go +++ b/test/simulation/xudtest/node.go @@ -13,7 +13,7 @@ import ( "sync/atomic" "time" - "github.com/ExchangeUnion/xud-simulation/connexttest" + // "github.com/ExchangeUnion/xud-simulation/connexttest" "context" @@ -91,23 +91,26 @@ func (cfg nodeConfig) genArgs() []string { args = append(args, fmt.Sprintf("--lnd.LTC.port=%v", cfg.LndLtcPort)) args = append(args, fmt.Sprintf("--lnd.LTC.certpath=%v", cfg.LndLtcCertPath)) args = append(args, fmt.Sprintf("--lnd.LTC.macaroonpath=%v", cfg.LndLtcMacPath)) + args = append(args, "--connext.disable") + + /* + if !cfg.RaidenDisable { + args = append(args, fmt.Sprintf("--raiden.host=%v", cfg.RaidenHost)) + args = append(args, fmt.Sprintf("--raiden.port=%v", cfg.RaidenPort)) + } else { + args = append(args, "--raiden.disable") + } - if !cfg.RaidenDisable { - args = append(args, fmt.Sprintf("--raiden.host=%v", cfg.RaidenHost)) - args = append(args, fmt.Sprintf("--raiden.port=%v", cfg.RaidenPort)) - } else { - args = append(args, "--raiden.disable") - } - - if !cfg.ConnextDisable { - args = append(args, fmt.Sprintf("--connext.host=%v", cfg.ConnextHost)) - args = append(args, fmt.Sprintf("--connext.port=%v", cfg.ConnextPort)) - args = append(args, "--connext.webhookhost=127.0.0.1") - args = append(args, fmt.Sprintf("--connext.webhookport=%v", cfg.HTTPPort)) + if !cfg.ConnextDisable { + args = append(args, fmt.Sprintf("--connext.host=%v", cfg.ConnextHost)) + args = append(args, fmt.Sprintf("--connext.port=%v", cfg.ConnextPort)) + args = append(args, "--connext.webhookhost=127.0.0.1") + args = append(args, fmt.Sprintf("--connext.webhookport=%v", cfg.HTTPPort)) - } else { - args = append(args, "--connext.disable") - } + } else { + args = append(args, "--connext.disable") + } + */ return args } @@ -124,9 +127,9 @@ type HarnessNode struct { ID int pubKey string - LndBtcNode *lntest.HarnessNode - LndLtcNode *lntest.HarnessNode - ConnextClient *connexttest.HarnessClient + LndBtcNode *lntest.HarnessNode + LndLtcNode *lntest.HarnessNode + // ConnextClient *connexttest.HarnessClient // processExit is a channel that's closed once it's detected that the // process this instance of HarnessNode is bound to has exited. @@ -209,11 +212,13 @@ func (hn *HarnessNode) SetLnd(lndNode *lntest.HarnessNode, chain string) { } } +/* func (hn *HarnessNode) SetConnextClient(client *connexttest.HarnessClient) { hn.Cfg.ConnextHost = "0.0.0.0" hn.Cfg.ConnextPort = client.Cfg.Port hn.ConnextClient = client } +*/ func (hn *HarnessNode) SetEnvVars(envVars []string) { hn.EnvVars = envVars