From 8e3b9f040c9bf309d97ae16c5a8421d5e91e8103 Mon Sep 17 00:00:00 2001 From: Vadim Nikonov Date: Mon, 21 Nov 2022 15:14:33 +0300 Subject: [PATCH 1/3] add new test: new gas price higher than previous one --- .../test/worker-tests/poolWorker.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/zp-relayer/test/worker-tests/poolWorker.test.ts b/zp-relayer/test/worker-tests/poolWorker.test.ts index dabee056..830ab8a2 100644 --- a/zp-relayer/test/worker-tests/poolWorker.test.ts +++ b/zp-relayer/test/worker-tests/poolWorker.test.ts @@ -27,6 +27,8 @@ import { import { validateTx } from '../../validateTx' import flow from '../flows/flow_independent_deposits_5.json' import flowDependentDeposits from '../flows/flow_dependent_deposits_2.json' +import { type } from 'os' +import { get } from 'https' chai.use(chaiAsPromised) const expect = chai.expect @@ -224,4 +226,41 @@ describe('poolWorker', () => { await expect(job.waitUntilFinished(poolQueueEvents)).rejectedWith('Incorrect root at index') }) + + it.only('should be new gas price higher than previous one', async () => { + const deposit = flow[0] + await mintTokens(deposit.txTypeData.from as string, parseInt(deposit.txTypeData.amount)) + await disableMining() + + // @ts-ignore + const job = await submitJob(deposit) + + // sentWorker.on('progress', async () => { + // await enableMining() + // }) + + const [[txHash, sentId]] = await job.waitUntilFinished(poolQueueEvents) + expect(txHash.length).eq(66) + + const getGasPriceBefore = await web3.eth.getTransaction(txHash) + const gasPriceBefore = Number(getGasPriceBefore['gasPrice']) + + // await disableMining() + + sentWorker.on('progress', async () => { + await enableMining() + }) + + const sentJob = (await sentTxQueue.getJob(sentId)) as Job + const [status, sentHash, ] = await sentJob.waitUntilFinished(sentQueueEvents) + expect(status).eq(SentTxState.MINED) + expect(txHash).not.eq(sentHash) + + const getGasPriceAfter = await web3.eth.getTransaction(sentHash) + const gasPriceAfter = Number(getGasPriceAfter['gasPrice']) + console.log(gasPriceBefore + ' < ' + gasPriceAfter) + + expect(gasPriceBefore).lt(gasPriceAfter) + + }) }) From bdc21d349e58f74faef5d1530b4de3e6c7f8c787 Mon Sep 17 00:00:00 2001 From: Vadim Nikonov Date: Mon, 21 Nov 2022 15:16:35 +0300 Subject: [PATCH 2/3] updated test --- zp-relayer/test/worker-tests/poolWorker.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/zp-relayer/test/worker-tests/poolWorker.test.ts b/zp-relayer/test/worker-tests/poolWorker.test.ts index 830ab8a2..4ab2b7b2 100644 --- a/zp-relayer/test/worker-tests/poolWorker.test.ts +++ b/zp-relayer/test/worker-tests/poolWorker.test.ts @@ -235,9 +235,6 @@ describe('poolWorker', () => { // @ts-ignore const job = await submitJob(deposit) - // sentWorker.on('progress', async () => { - // await enableMining() - // }) const [[txHash, sentId]] = await job.waitUntilFinished(poolQueueEvents) expect(txHash.length).eq(66) @@ -245,8 +242,6 @@ describe('poolWorker', () => { const getGasPriceBefore = await web3.eth.getTransaction(txHash) const gasPriceBefore = Number(getGasPriceBefore['gasPrice']) - // await disableMining() - sentWorker.on('progress', async () => { await enableMining() }) From 59b6948614fb3603aec47f8f6b86275d896bbc4d Mon Sep 17 00:00:00 2001 From: Leonid Tyurin Date: Mon, 21 Nov 2022 18:06:47 +0400 Subject: [PATCH 3/3] Refactor --- .../test/worker-tests/poolWorker.test.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/zp-relayer/test/worker-tests/poolWorker.test.ts b/zp-relayer/test/worker-tests/poolWorker.test.ts index 4ab2b7b2..29d97824 100644 --- a/zp-relayer/test/worker-tests/poolWorker.test.ts +++ b/zp-relayer/test/worker-tests/poolWorker.test.ts @@ -27,8 +27,6 @@ import { import { validateTx } from '../../validateTx' import flow from '../flows/flow_independent_deposits_5.json' import flowDependentDeposits from '../flows/flow_dependent_deposits_2.json' -import { type } from 'os' -import { get } from 'https' chai.use(chaiAsPromised) const expect = chai.expect @@ -57,8 +55,6 @@ describe('poolWorker', () => { let snapShotId: string let eventsInit = false - before(async () => {}) - beforeEach(async () => { snapShotId = await evmSnapshot() @@ -155,7 +151,7 @@ describe('poolWorker', () => { await mintTokens(deposit.txTypeData.from as string, parseInt(deposit.txTypeData.amount)) await sentWorker.pause() - const mockPoolWorker = await createPoolTxWorker(gasPriceService, async () => {}, workerMutex, newConnection()) + const mockPoolWorker = await createPoolTxWorker(gasPriceService, async () => { }, workerMutex, newConnection()) mockPoolWorker.run() await mockPoolWorker.waitUntilReady() @@ -184,7 +180,7 @@ describe('poolWorker', () => { const [status2, , rescheduledIds2] = await sentJob2.waitUntilFinished(sentQueueEvents) expect(status2).eq(SentTxState.REVERT) expect(rescheduledIds2.length).eq(0) - + const poolJob3 = (await poolTxQueue.getJob(rescheduledIds1[0])) as Job const [[, sentId3]] = await poolJob3.waitUntilFinished(poolQueueEvents) expect(await pool.state.jobIdsMapping.get(poolJob2.id as string)).eq(poolJob3.id) @@ -227,7 +223,7 @@ describe('poolWorker', () => { await expect(job.waitUntilFinished(poolQueueEvents)).rejectedWith('Incorrect root at index') }) - it.only('should be new gas price higher than previous one', async () => { + it('should increase gas price on re-send', async () => { const deposit = flow[0] await mintTokens(deposit.txTypeData.from as string, parseInt(deposit.txTypeData.amount)) await disableMining() @@ -235,27 +231,25 @@ describe('poolWorker', () => { // @ts-ignore const job = await submitJob(deposit) - const [[txHash, sentId]] = await job.waitUntilFinished(poolQueueEvents) expect(txHash.length).eq(66) - const getGasPriceBefore = await web3.eth.getTransaction(txHash) - const gasPriceBefore = Number(getGasPriceBefore['gasPrice']) + const txBefore = await web3.eth.getTransaction(txHash) + const gasPriceBefore = Number(txBefore.gasPrice) sentWorker.on('progress', async () => { await enableMining() }) const sentJob = (await sentTxQueue.getJob(sentId)) as Job - const [status, sentHash, ] = await sentJob.waitUntilFinished(sentQueueEvents) + const [status, sentHash,] = await sentJob.waitUntilFinished(sentQueueEvents) expect(status).eq(SentTxState.MINED) expect(txHash).not.eq(sentHash) - const getGasPriceAfter = await web3.eth.getTransaction(sentHash) - const gasPriceAfter = Number(getGasPriceAfter['gasPrice']) + const txAfter = await web3.eth.getTransaction(sentHash) + const gasPriceAfter = Number(txAfter.gasPrice) console.log(gasPriceBefore + ' < ' + gasPriceAfter) expect(gasPriceBefore).lt(gasPriceAfter) - }) })