Skip to content

Commit

Permalink
Merge pull request #2008 from ExchangeUnion/feat/connext-vector-remov…
Browse files Browse the repository at this point in the history
…e-simtests

test: connext vector remove simtests
  • Loading branch information
Karl Ranna authored Nov 26, 2020
2 parents 99588c0 + dee041d commit ad30f4a
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 439 deletions.
2 changes: 1 addition & 1 deletion lib/connextclient/ConnextClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
2 changes: 1 addition & 1 deletion lib/swaps/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
96 changes: 43 additions & 53 deletions test/jest/Connext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('ConnextClient', () => {
port: 1337,
webhookhost: 'http://testerson',
webhookport: 7331,
nodeIdentifier: 'vector321',
};
const logger = new mockedLogger();
logger.trace = jest.fn();
Expand Down Expand Up @@ -89,6 +90,7 @@ describe('ConnextClient', () => {
currencyInstances,
logger,
unitConverter: new UnitConverter(),
network: 'mainnet',
});
});

Expand Down Expand Up @@ -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 });
});
Expand All @@ -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 () => {
Expand All @@ -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 });
Expand Down
6 changes: 5 additions & 1 deletion test/jest/HttpServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 2 additions & 4 deletions test/jest/HttpService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const mockedService = <jest.Mock<Service>><any>Service;
const rHash = 'd92e2eb0e9118faedc5ce533b65737b33a88c187c10e74e6d8b1be34626ae892';
const preImage = 'd55dd2b285a815f9449d9e665ed61dd19663e08e9d4e84db621ca3e78082fabf';
const preimageRequest: any = {
id: '1',
data: {
type: '',
transferMeta: {
transfer: {
transferResolver: {
preImage: `0x${preImage}`,
},
},
Expand Down
1 change: 1 addition & 0 deletions test/jest/SwapClientManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/jest/__snapshots__/Connext.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
`;

Expand Down
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
Loading

0 comments on commit ad30f4a

Please sign in to comment.