-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-160: tx pool endpoint tests + new cs image (#1408)
* API-160: tx pool endpoint tests + new cs image * push staged file * fix test * remove self sended txs * fixes after review
- Loading branch information
1 parent
428c2d6
commit 3660954
Showing
4 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import axios from 'axios'; | ||
import { config } from './config/env.config'; | ||
import { ChainSimulatorUtils } from './utils/test.utils'; | ||
import { fundAddress } from './utils/chain.simulator.operations'; | ||
|
||
describe('Pool e2e tests with chain simulator', () => { | ||
beforeAll(async () => { | ||
await ChainSimulatorUtils.waitForEpoch(2); | ||
await fundAddress(config.chainSimulatorUrl, config.aliceAddress); | ||
await new Promise((resolve) => setTimeout(resolve, 20000)); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('GET /pool', () => { | ||
it('should return status code 200', async () => { | ||
const response = await axios.get(`${config.apiServiceUrl}/pool`); | ||
const txsPool = response.data; | ||
|
||
expect(response.status).toBe(200); | ||
expect(txsPool).toBeInstanceOf(Array); | ||
}); | ||
|
||
it('should return the transaction pool', async () => { | ||
const response = await axios.get( | ||
`${config.apiServiceUrl}/pool`, | ||
); | ||
const pool = response.data; | ||
const expectedProperties = [ | ||
'txHash', | ||
'nonce', | ||
'receiver', | ||
'gasPrice', | ||
'gasLimit', | ||
]; | ||
|
||
for (const tx of pool) { | ||
for (const property of expectedProperties) { | ||
expect(tx).toHaveProperty(property); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
describe('GET /pool/:txhash', () => { | ||
it('should return status code 200 and the transaction', async () => { | ||
const poolResponse = await axios.get( | ||
`${config.apiServiceUrl}/pool?size=1`, | ||
); | ||
const response = await axios.get( | ||
`${config.apiServiceUrl}/pool/${poolResponse.data[0].txHash}`, | ||
); | ||
const tx = response.data; | ||
|
||
expect(response.status).toBe(200); | ||
expect(tx).toHaveProperty( | ||
'txHash', | ||
poolResponse.data[0].txHash, | ||
); | ||
}); | ||
|
||
it('should return status code 404 for non-existent tx hash', async () => { | ||
const nonExistentTxHash = '0000000000000000000000000000000000000000000000000000000000000000'; | ||
try { | ||
await axios.get( | ||
`${config.apiServiceUrl}/pool/${nonExistentTxHash}`, | ||
); | ||
} catch (error: any) { | ||
expect(error.response.status).toBe(404); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ | |
"../.." | ||
], | ||
"testTimeout": 180000 | ||
} | ||
} |