Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync / gateway development -> staging #76

Merged
merged 170 commits into from
Mar 28, 2023
Merged
Changes from 1 commit
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
3622b90
injective gateway changes
vic-en Feb 15, 2023
9d3b448
Merge development branch
Feb 21, 2023
6c81037
Batch order creation and cancelation for CLOB and injective
Feb 21, 2023
98c392d
fixes
vic-en Feb 21, 2023
c9e0a79
Merge branch 'development' into feat/injective_protocol
fengtality Feb 21, 2023
ec85187
Batch order creation and cancelation for CLOB and injective
Feb 21, 2023
166de8b
initial commit
vic-en Feb 23, 2023
26cb16c
injective gateway changes
vic-en Feb 15, 2023
97879e4
fixes
vic-en Feb 21, 2023
4f8b4f2
Merge branch 'development' of https://github.com/hummingbot/gateway i…
vic-en Feb 23, 2023
1ce4e44
Move code over
Feb 14, 2023
6e56e33
Clean up
Feb 14, 2023
fcd509f
Clean up unwanted changes
Feb 14, 2023
5329137
Compiles now
Feb 14, 2023
8f71a55
Bring patches over
Feb 14, 2023
1ed97bc
Add xdc to root
Feb 14, 2023
3777af2
Fix https
Feb 14, 2023
04a57db
Start unit tests for xdc chain
Feb 14, 2023
e8eb24f
validator test
Feb 14, 2023
0f1fcde
Add route tests
Feb 14, 2023
d3df317
Support xdc addresses in evm routes only when the chain is xdc
Feb 15, 2023
97f6206
Unit test for allowances
Feb 15, 2023
b938d21
Remove commented code
Feb 15, 2023
ab4a877
Use xdc prefixed address as wallet address
Feb 16, 2023
6ec0c8f
Update
Feb 16, 2023
30b71e4
remove logs
Feb 16, 2023
c126d81
Update
Feb 16, 2023
626e7b6
Drop patch packages
Feb 17, 2023
3ff6179
Fork of ethers so it is compatible with XDC and doesn't interfere wit…
james-hummingbot Feb 20, 2023
7654b4d
Add Xdcish
Feb 20, 2023
77fc380
It compiles
Feb 20, 2023
fc4888e
Fix wallet controller
Feb 20, 2023
832df40
(fix) update patch files and package.json
CrimsonJacket Feb 15, 2023
1ba0ebd
(feat) add xsswap
CrimsonJacket Feb 15, 2023
3578005
(fix/test) address issues with gateway start up and add manual token …
CrimsonJacket Feb 15, 2023
61a97e6
wip
CrimsonJacket Feb 17, 2023
c7483c8
(fix/test) remove redundant private key transformation and finalize u…
CrimsonJacket Feb 17, 2023
2df0e70
(update) update yarn.lock
CrimsonJacket Feb 21, 2023
9ec26a3
(fix/feat) resolve WXDC token address conflicts and add xsswap connector
CrimsonJacket Feb 21, 2023
d3cb225
Clean up
Feb 21, 2023
e97d4b7
(fix) address incorrect token address used in XDCSwap and ethers package
CrimsonJacket Feb 23, 2023
f292c38
(refactor) include token list for xinfin network
CrimsonJacket Feb 24, 2023
0866f3a
(remove) xdcswap
CrimsonJacket Feb 24, 2023
57239b8
(cleanup) fix merge issues with erc20 tokenlist file
CrimsonJacket Feb 24, 2023
d06e7f1
(remove) remove patches
CrimsonJacket Feb 24, 2023
303d07e
(fix) increase node space size to 10240 for tests
fengtality Feb 24, 2023
53865ff
resolve conflict
vic-en Feb 24, 2023
632df4f
Merge branch 'development' of https://github.com/hummingbot/gateway i…
vic-en Feb 24, 2023
d9365c3
Set permissions for hummingbot user to conf directory
klpanagi Feb 26, 2023
872845c
Merge branch 'development' into feat/xdc_chain_and_xsswap
james-hummingbot Feb 26, 2023
69e89ee
final update
vic-en Feb 27, 2023
5a23153
Merge branch 'feat/injective_w_batch_update' of https://github.com/Co…
vic-en Feb 27, 2023
324a739
(fix) replace cronos nodeURL in workflow
fengtality Feb 27, 2023
6f18f08
Merge branch 'development' into feat/xdc_chain_and_xsswap
vic-en Feb 28, 2023
4dfa75d
initial tests
vic-en Feb 28, 2023
56c3a18
update
vic-en Feb 28, 2023
bfd9069
Merge branch 'development' into feat/injective_protocol
vic-en Feb 28, 2023
da05d49
update
vic-en Mar 1, 2023
d0b90f2
clear chain metric timer
vic-en Mar 1, 2023
ff2a592
point node addressees in nonce test to hardhat
vic-en Mar 1, 2023
31e5138
assign id to logger metric timer
vic-en Mar 1, 2023
9b9ba42
remove test
vic-en Mar 1, 2023
26b8e2a
remove test
vic-en Mar 1, 2023
b310fbc
Merge branch 'feat/injective_protocol' of https://github.com/CoinAlph…
vic-en Mar 1, 2023
812104b
Revert "remove test"
vic-en Mar 1, 2023
53ed086
custom test
vic-en Mar 2, 2023
82ec200
update workflow
vic-en Mar 2, 2023
af0798b
increase memory
vic-en Mar 2, 2023
46b1dca
diff in src dir only
vic-en Mar 2, 2023
14f8bf1
update order
vic-en Mar 2, 2023
0b427b6
update workflow
vic-en Mar 2, 2023
dfd7151
fix outstanding issues
vic-en Mar 2, 2023
212eef5
fix defikingdoms test
vic-en Mar 2, 2023
605e63d
update defikingdom unit test
vic-en Mar 2, 2023
eb9a6d6
minor update
vic-en Mar 2, 2023
97eb092
workflow test
vic-en Mar 2, 2023
0ff7c5f
Revert "workflow test"
vic-en Mar 2, 2023
c3c191d
injective balance update
vic-en Mar 2, 2023
505178e
workflow test
vic-en Mar 2, 2023
ef1d308
update jest to use 50%
vic-en Mar 2, 2023
ae055da
Revert "update jest to use 50%"
vic-en Mar 3, 2023
717eb81
Revert "workflow test"
vic-en Mar 3, 2023
1889419
(fixes) Several dexalot-related fixes
petioptrv Mar 3, 2023
f81b924
decode tx log event
vic-en Mar 3, 2023
267672c
remove endpoint not implemented in swagger
vic-en Mar 6, 2023
e38c9ac
correct typo
vic-en Mar 6, 2023
7348476
update yarn
vic-en Mar 6, 2023
8ed804c
remove endpoint not implemented in swagger
vic-en Mar 6, 2023
5256f08
correct typo
vic-en Mar 6, 2023
18b97b5
update yarn
vic-en Mar 6, 2023
1c7cdc5
Merge branch 'development' of github.com:CoinAlpha/gateway into feat/…
Mar 6, 2023
fbc59da
Merge branch 'feat/xdc_chain_and_xsswap' of github.com:CoinAlpha/gate…
Mar 6, 2023
6aae11f
move libs to devDependencies
fengtality Mar 7, 2023
13acef8
chore: remove unused route
sytranvn Mar 7, 2023
d384298
Apply yarn format to reduce diffs
Mar 7, 2023
bfdeadc
update get order
vic-en Mar 7, 2023
fd78603
add /wallet/sign
vic-en Mar 7, 2023
a088aae
return toke symbols as sent in bal request
vic-en Mar 8, 2023
7fe694c
Merge pull request #51 from hummingbot/feat/injective_with_diff_test_…
fengtality Mar 8, 2023
79a06a1
Merge branch 'development' into chore/remove-unused-route
fengtality Mar 8, 2023
5a34350
Merge branch 'development' into fix/format
fengtality Mar 8, 2023
d90f54d
Merge pull request #52 from sytranvn/chore/remove-unused-route
fengtality Mar 8, 2023
101cd14
Merge branch 'development' into fix/format
fengtality Mar 8, 2023
aa9ef71
Merge pull request #53 from CoinAlpha/fix/format
fengtality Mar 8, 2023
c18bddf
Merge development branch
Mar 8, 2023
0176b34
Merge branch 'development' of github.com:hummingbot/gateway into feat…
Mar 8, 2023
2483015
Merge development
Mar 8, 2023
24c4831
typo
Mar 8, 2023
1355975
Merge branch 'feat/injective_protocol' of https://github.com/CoinAlph…
vic-en Mar 8, 2023
acee342
remove endpoint not implemented in swagger
vic-en Mar 6, 2023
12ebf1b
fix unit test
vic-en Mar 8, 2023
07bf97c
Merge branch 'feat/injective_w_batch_update' of https://github.com/Co…
vic-en Mar 8, 2023
661a9c9
(refactor) Adds the API Key request for Dexalot
petioptrv Mar 9, 2023
ac959ac
refactor balances controller
vic-en Mar 9, 2023
3f40797
Remove unnecessary console.log
Mar 9, 2023
f955da0
Merge pull request #45 from CoinAlpha/feat/xdc_chain_and_xsswap
fengtality Mar 9, 2023
f8ebd74
Merge branch 'development' into feat/injective_w_batch_update
fengtality Mar 9, 2023
b167c81
upgrade
vic-en Mar 9, 2023
78310a5
fix fees
vic-en Mar 10, 2023
5f6dc1d
Merge branch 'feat/injective_w_batch_update' of https://github.com/Co…
vic-en Mar 10, 2023
696b2cd
change BNB default rpc to ankr
fengtality Mar 12, 2023
5df9c20
Merge pull request #55 from CoinAlpha/feat/injective_w_batch_update
rapcmia Mar 13, 2023
85d7117
(feat) add dMiner tokens to BSC list
fengtality Mar 13, 2023
87ae3e8
Merge branch 'development' of github.com:hummingbot/gateway into deve…
fengtality Mar 13, 2023
59873ef
(fix) fix decimals for FIRO BLOCK
fengtality Mar 13, 2023
680ff17
(fix) don't decrement nonce
fengtality Mar 14, 2023
226f359
(test) fix tests related to nonce change
fengtality Mar 14, 2023
59164c3
(fix) escape harmony mainnet node from workflow
fengtality Mar 14, 2023
b809a21
(feat) add sushi avalanche
fengtality Mar 14, 2023
7881476
(fix) fix bug with existing BSC and MATIC sushi connectors
fengtality Mar 14, 2023
e33cb70
(feat) add harmony arbitrum sushiswap
fengtality Mar 14, 2023
abc7c43
(fix) revert and make fix to ethereum-base
fengtality Mar 15, 2023
0be3dcc
Merge branch 'fix/fix-nonce' of github.com:hummingbot/gateway into fe…
fengtality Mar 15, 2023
4a3ae3f
Merge pull request #58 from hummingbot/fix/fix-nonce
fengtality Mar 15, 2023
686fe52
Merge branch 'development' of github.com:hummingbot/gateway into feat…
fengtality Mar 15, 2023
cae292d
(fix) fix avalanche typo
fengtality Mar 15, 2023
6b61a76
(fix) fix tests
fengtality Mar 15, 2023
1b2eb5c
(fix) replace new BSC default nodes in workflow
fengtality Mar 15, 2023
2daff0d
Merge pull request #60 from hummingbot/feat/add-sushiswap-networks
fengtality Mar 15, 2023
15e496e
remove comments
vic-en Mar 16, 2023
6e541a8
address comments
vic-en Mar 16, 2023
d6ffec3
change networks for mainnet and testnet
vic-en Mar 16, 2023
06a688a
update dexalot test
vic-en Mar 16, 2023
9875184
Merge branch 'development' into feat/dexalot
vic-en Mar 16, 2023
25f55d3
(fix) change to EIP 1559 for gas calcs
fengtality Mar 16, 2023
dabe9d3
fix tests
fengtality Mar 16, 2023
4ccbde7
upgrade hardhat to try to fix tests
fengtality Mar 17, 2023
0b82c90
Merge pull request #66 from hummingbot/fix/use-1559
fengtality Mar 17, 2023
81b980a
Merge branch 'development' into feat/dexalot
fengtality Mar 17, 2023
58c0769
Merge branch 'development' into fix/injective_issues
vic-en Mar 17, 2023
52ccd39
(fix) test using hardhat with pinned block
fengtality Mar 19, 2023
ede9013
fix typo
fengtality Mar 19, 2023
de0308c
Merge pull request #68 from hummingbot/test/pinned-block-workflow
fengtality Mar 20, 2023
3525f5e
Merge branch 'development' into feat/dexalot
fengtality Mar 20, 2023
4707c28
Merge branch 'development' into fix/injective_issues
fengtality Mar 20, 2023
e68d562
(fix) revert eth gas calc and workflow change
fengtality Mar 20, 2023
8a7e302
Merge branch 'development' into feat/dexalot
fengtality Mar 20, 2023
942dd91
Merge branch 'development' into fix/injective_issues
fengtality Mar 20, 2023
98d087f
dexalot curl commands update
vic-en Mar 20, 2023
0311124
update network/balances swagger doc to include connector field
vic-en Mar 20, 2023
33df6bc
Merge branch 'feat/dexalot' of https://github.com/CoinAlpha/gateway i…
vic-en Mar 20, 2023
3ab615f
update network maps
vic-en Mar 21, 2023
71b55ca
Merge pull request #65 from CoinAlpha/feat/dexalot
fengtality Mar 23, 2023
c63c5ed
Merge branch 'development' into fix/injective_issues
fengtality Mar 24, 2023
226cc84
Merge remote-tracking branch 'origin/development' into fix/docker_per…
klpanagi Mar 26, 2023
a7103ee
Merge pull request #72 from klpanagi/fix/docker_permissions_conf_dir
fengtality Mar 26, 2023
465770e
Merge branch 'development' into fix/injective_issues
fengtality Mar 26, 2023
54e4871
Merge pull request #67 from CoinAlpha/fix/injective_issues
fengtality Mar 26, 2023
292960e
Update workflow.yml
nikspz Mar 28, 2023
673f7a0
Merge pull request #78 from hummingbot/nikspz-patch-1
nikspz Mar 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add route tests
James authored and CrimsonJacket committed Feb 24, 2023
commit 0f1fcde678c439c976b9e2d184c647227b4c6f67
1 change: 1 addition & 0 deletions src/chains/ethereum/ethereum.validators.ts
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ export const validateSpender: Validator = mkValidator(
val === 'mad_meerkat' ||
val === 'vvs' ||
val === 'pancakeswap' ||
val === 'xdcswap' ||
isAddress(val))
);

374 changes: 374 additions & 0 deletions test/chains/xdc/xdc.routes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,374 @@
import request from 'supertest';
import { patch, unpatch } from '../../services/patch';
import { gatewayApp } from '../../../src/app';
import {
NETWORK_ERROR_CODE,
OUT_OF_GAS_ERROR_CODE,
UNKNOWN_ERROR_ERROR_CODE,
NETWORK_ERROR_MESSAGE,
OUT_OF_GAS_ERROR_MESSAGE,
UNKNOWN_ERROR_MESSAGE,
} from '../../../src/services/error-handler';
import * as transactionSuccesful from '../ethereum/fixtures/transaction-succesful.json';
import * as transactionSuccesfulReceipt from '../ethereum/fixtures/transaction-succesful-receipt.json';
import * as transactionOutOfGas from '../ethereum/fixtures/transaction-out-of-gas.json';
import * as transactionOutOfGasReceipt from '../ethereum/fixtures/transaction-out-of-gas-receipt.json';
import { Xdc } from '../../../src/chains/xdc/xdc';
let xdc: Xdc;

const address: string = '0xFaA12FD102FE8623C9299c72B03E45107F2772B5';

beforeAll(async () => {
xdc = Xdc.getInstance('apothem');
});

afterAll(async () => {
await xdc.close();
});

afterEach(unpatch);

const patchGetWallet = () => {
patch(xdc, 'getWallet', () => {
return {
address,
};
});
};

const patchGetNonce = () => {
patch(xdc.nonceManager, 'getNonce', () => 2);
};

const patchGetTokenBySymbol = () => {
patch(xdc, 'getTokenBySymbol', () => {
return {
chainId: 51,
address: '0xaD2552941efbAc1532B5C8950EcCdb3EA9DFE68b',
decimals: 18,
name: 'Wrapped XDC',
symbol: 'WXDC',
logoURI: '',
};
});
};

const patchApproveERC20 = () => {
patch(xdc, 'approveERC20', () => {
return {
type: 2,
chainId: 43114,
nonce: 115,
maxPriorityFeePerGas: { toString: () => '106000000000' },
maxFeePerGas: { toString: () => '106000000000' },
gasPrice: { toString: () => null },
gasLimit: { toString: () => '100000' },
to: '0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa',
value: { toString: () => '0' },
data: '0x095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', // noqa: mock
accessList: [],
hash: '0x75f98675a8f64dcf14927ccde9a1d59b67fa09b72cc2642ad055dae4074853d9', // noqa: mock
v: 0,
r: '0xbeb9aa40028d79b9fdab108fcef5de635457a05f3a254410414c095b02c64643', // noqa: mock
s: '0x5a1506fa4b7f8b4f3826d8648f27ebaa9c0ee4bd67f569414b8cd8884c073100', // noqa: mock
from: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5',
confirmations: 0,
};
});
};

const patchGetERC20Allowance = () => {
patch(xdc, 'getERC20Allowance', () => ({ value: 1, decimals: 3 }));
};

const patchGetNativeBalance = () => {
patch(xdc, 'getNativeBalance', () => ({ value: 1, decimals: 3 }));
};

const patchGetERC20Balance = () => {
patch(xdc, 'getERC20Balance', () => ({ value: 1, decimals: 3 }));
};

describe('POST /evm/nonce', () => {
it('should return 200', async () => {
patchGetWallet();
patchGetNonce();

await request(gatewayApp)
.post(`/evm/nonce`)
.send({
chain: 'xdc',
network: 'apothem',
address,
})
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.nonce).toBe(2));
});

it('should return 404 when parameters are invalid', async () => {
await request(gatewayApp)
.post(`/evm/nonce`)
.send({
chain: 'xdc',
network: 'apothem',
address: 'da857cbda0ba96757fed842617a4',
})
.expect(404);
});
});

describe('POST /evm/approve', () => {
it('should return 200', async () => {
patchGetWallet();
xdc.getContract = jest.fn().mockReturnValue({
address,
});
patch(xdc.nonceManager, 'getNonce', () => 115);
patchGetTokenBySymbol();
patchApproveERC20();

await request(gatewayApp)
.post(`/evm/approve`)
.send({
chain: 'xdc',
network: 'apothem',
address,
spender: 'xdcswap',
token: 'PNG',
})
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.then((res: any) => {
expect(res.body.nonce).toEqual(115);
});
});

it('should return 404 when parameters are invalid', async () => {
await request(gatewayApp)
.post(`/evm/approve`)
.send({
chain: 'xdc',
network: 'apothem',
address,
spender: 'xdcswap',
token: 123,
nonce: '23',
})
.expect(404);
});
});

describe('POST /evm/allowances', () => {
it('should return 200 asking for allowances', async () => {
patchGetWallet();
patchGetTokenBySymbol();
const spender = '0xFaA12FD102FE8623C9299c72B03E45107F2772B5';
xdc.getSpender = jest.fn().mockReturnValue(spender);
xdc.getContract = jest.fn().mockReturnValue({
address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5',
});
patchGetERC20Allowance();

await request(gatewayApp)
.post(`/evm/allowances`)
.send({
chain: 'xdc',
network: 'apothem',
address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5',
spender: spender,
tokenSymbols: ['WETH', 'DAI'],
})
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.spender).toEqual(spender))
.expect((res) => expect(res.body.approvals.WETH).toEqual('0.001'))
.expect((res) => expect(res.body.approvals.DAI).toEqual('0.001'));
});
});

describe('POST /network/balances', () => {
it('should return 200 asking for supported tokens', async () => {
patchGetWallet();
patchGetTokenBySymbol();
patchGetNativeBalance();
patchGetERC20Balance();
xdc.getContract = jest.fn().mockReturnValue({
address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5',
});

await request(gatewayApp)
.post(`/network/balances`)
.send({
chain: 'xdc',
network: 'apothem',
address: '0xFaA12FD102FE8623C9299c72B03E45107F2772B5',
tokenSymbols: ['WETH', 'DAI'],
})
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => expect(res.body.balances.WETH).toBeDefined())
.expect((res) => expect(res.body.balances.DAI).toBeDefined());
});
});

describe('POST /evm/cancel', () => {
it('should return 200', async () => {
// override getWallet (network call)
xdc.getWallet = jest.fn().mockReturnValue({
address,
});

xdc.cancelTx = jest.fn().mockReturnValue({
hash: '0xf6b9e7cec507cb3763a1179ff7e2a88c6008372e3a6f297d9027a0b39b0fff77', // noqa: mock
});

await request(gatewayApp)
.post(`/evm/cancel`)
.send({
chain: 'xdc',
network: 'apothem',
address,
nonce: 23,
})
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.then((res: any) => {
expect(res.body.txHash).toEqual(
'0xf6b9e7cec507cb3763a1179ff7e2a88c6008372e3a6f297d9027a0b39b0fff77' // noqa: mock
);
});
});

it('should return 404 when parameters are invalid', async () => {
await request(gatewayApp)
.post(`/evm/cancel`)
.send({
chain: 'xdc',
network: 'apothem',
address: '',
nonce: '23',
})
.expect(404);
});
});

describe('POST /network/poll', () => {
it('should get a NETWORK_ERROR_CODE when the network is unavailable', async () => {
patch(xdc, 'getCurrentBlockNumber', () => {
const error: any = new Error('something went wrong');
error.code = 'NETWORK_ERROR';
throw error;
});

const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock
});

expect(res.statusCode).toEqual(503);
expect(res.body.errorCode).toEqual(NETWORK_ERROR_CODE);
expect(res.body.message).toEqual(NETWORK_ERROR_MESSAGE);
});

it('should get a UNKNOWN_ERROR_ERROR_CODE when an unknown error is thrown', async () => {
patch(xdc, 'getCurrentBlockNumber', () => {
throw new Error();
});

const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock
});

expect(res.statusCode).toEqual(503);
expect(res.body.errorCode).toEqual(UNKNOWN_ERROR_ERROR_CODE);
});

it('should get an OUT of GAS error for failed out of gas transactions', async () => {
patch(xdc, 'getCurrentBlockNumber', () => 1);
patch(xdc, 'getTransaction', () => transactionOutOfGas);
patch(xdc, 'getTransactionReceipt', () => transactionOutOfGasReceipt);
const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock
});

expect(res.statusCode).toEqual(503);
expect(res.body.errorCode).toEqual(OUT_OF_GAS_ERROR_CODE);
expect(res.body.message).toEqual(OUT_OF_GAS_ERROR_MESSAGE);
});

it('should get a null in txReceipt for Tx in the mempool', async () => {
patch(xdc, 'getCurrentBlockNumber', () => 1);
patch(xdc, 'getTransaction', () => transactionOutOfGas);
patch(xdc, 'getTransactionReceipt', () => null);
const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock
});
expect(res.statusCode).toEqual(200);
expect(res.body.txReceipt).toEqual(null);
expect(res.body.txData).toBeDefined();
});

it('should get a null in txReceipt and txData for Tx that didnt reach the mempool and TxReceipt is null', async () => {
patch(xdc, 'getCurrentBlockNumber', () => 1);
patch(xdc, 'getTransaction', () => null);
patch(xdc, 'getTransactionReceipt', () => null);
const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock
});
expect(res.statusCode).toEqual(200);
expect(res.body.txReceipt).toEqual(null);
expect(res.body.txData).toEqual(null);
});

it('should get txStatus = 1 for a succesful query', async () => {
patch(xdc, 'getCurrentBlockNumber', () => 1);
patch(xdc, 'getTransaction', () => transactionSuccesful);
patch(xdc, 'getTransactionReceipt', () => transactionSuccesfulReceipt);
const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x6d068067a5e5a0f08c6395b31938893d1cdad81f54a54456221ecd8c1941294d', // noqa: mock
});
expect(res.statusCode).toEqual(200);
expect(res.body.txReceipt).toBeDefined();
expect(res.body.txData).toBeDefined();
});

it('should get unknown error', async () => {
patch(xdc, 'getCurrentBlockNumber', () => {
const error: any = new Error('something went wrong');
error.code = -32006;
throw error;
});
const res = await request(gatewayApp).post('/network/poll').send({
chain: 'xdc',
network: 'apothem',
txHash:
'0x2faeb1aa55f96c1db55f643a8cf19b0f76bf091d0b7d1b068d2e829414576362', // noqa: mock
});
expect(res.statusCode).toEqual(503);
expect(res.body.errorCode).toEqual(UNKNOWN_ERROR_ERROR_CODE);
expect(res.body.message).toEqual(UNKNOWN_ERROR_MESSAGE);
});
});