From a1acc326f7716235f8e3c50fdff64d43f7254cd0 Mon Sep 17 00:00:00 2001 From: kassad Date: Wed, 8 Jan 2025 07:37:21 -0800 Subject: [PATCH 1/2] Added test to try to reproduce prefetch bug --- .../contractHelpers/Launchpad.ts | 7 +- libs/model/src/vitest.setup.ts | 7 +- .../event-processing-lifecycle.spec.ts | 119 ++++++++++++------ .../integration/integrationUtils/mainSetup.ts | 20 +-- 4 files changed, 98 insertions(+), 55 deletions(-) diff --git a/libs/evm-protocols/src/common-protocol/contractHelpers/Launchpad.ts b/libs/evm-protocols/src/common-protocol/contractHelpers/Launchpad.ts index 8d3db851b6f..c69429ed051 100644 --- a/libs/evm-protocols/src/common-protocol/contractHelpers/Launchpad.ts +++ b/libs/evm-protocols/src/common-protocol/contractHelpers/Launchpad.ts @@ -9,6 +9,7 @@ export const launchToken = async ( walletAddress: string, connectorWeight: number, tokenCommunityManager: string, + nonce?: number, ) => { const txReceipt = await contract.methods .launchTokenWithLiquidity( @@ -23,7 +24,11 @@ export const launchToken = async ( tokenCommunityManager, connectorWeight, ) - .send({ from: walletAddress, value: 4.167e8 }); + .send({ + from: walletAddress, + value: Math.floor(4.167e8 * (nonce! * 2)), + nonce, + }); return txReceipt; }; diff --git a/libs/model/src/vitest.setup.ts b/libs/model/src/vitest.setup.ts index b0b374eaf6f..20444edcbb8 100644 --- a/libs/model/src/vitest.setup.ts +++ b/libs/model/src/vitest.setup.ts @@ -24,10 +24,5 @@ beforeAll(async ({ name }) => { // Single point of test bootstrapping! // Only when running tests in libs/model and legacy commonwealth - if ( - ['@hicommonwealth/model', 'commonwealth'].includes( - process.env.npm_package_name ?? '', - ) - ) - await bootstrap_testing(); + await bootstrap_testing(); }, 20_000); diff --git a/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts b/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts index c4d96c8ea64..05e8f142542 100644 --- a/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts +++ b/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts @@ -21,56 +21,95 @@ describe('End to end event tests', () => { contractAddresses.launchpad, ) as unknown as Contract; - await cp.launchToken( - launchpadFactory, - 'testToken', - 'test', - [], - [], - web3.utils.toWei(1e9, 'ether'), + const lpBondingCurveFactory = new web3.eth.Contract( + lpBondingCurveAbi, + contractAddresses.lpBondingCurve, + ); + + const baseNonce = await web3.eth.getTransactionCount( anvilAccounts[0].address, - 830000, - contractAddresses.tokenCommunityManager, ); + let nonce = baseNonce; - await mineBlocks(1); + async function launchAndBuyToken(name, symbol) { + console.log(`launching token ${nonce}`); - let token = await models.LaunchpadToken.findOne({ - where: { name: 'testToken' }, - }); - await vi.waitFor( - async () => { - token = await models.LaunchpadToken.findOne({ - where: { name: 'testToken' }, - }); - expect(token).toBeTruthy(); - }, - { - timeout: 100000, - interval: 500, - }, - ); + nonce += BigInt(1); + try { + await cp.launchToken( + launchpadFactory, + name, + symbol, + [], + [], + web3.utils.toWei(1e9, 'ether'), + anvilAccounts[0].address, + 830000, + contractAddresses.tokenCommunityManager, + Number(nonce), + ); + } catch (e) { + console.log(e); + } - const lpBondingCurveFactory = new web3.eth.Contract( - lpBondingCurveAbi as AbiItem[], - contractAddresses.lpBondingCurve, - ) as unknown as Contract; + console.log(`launched token ${nonce}`); - await cp.buyToken( - lpBondingCurveFactory, - token!.token_address, - anvilAccounts[0].address, - 100, - ); + await mineBlocks(1); + + let token = await models.LaunchpadToken.findOne({ + where: { name }, + }); + + await vi.waitFor( + async () => { + token = await models.LaunchpadToken.findOne({ + where: { name }, + }); + if (!token) { + throw new Error('Token not found yet'); + } + }, + { + timeout: 100000, + interval: 500, + }, + ); - await mineBlocks(1); + await cp.buyToken( + lpBondingCurveFactory, + token.token_address, + anvilAccounts[0].address, + 100, + ); + + console.log(`bought token ${nonce}`); + + await mineBlocks(1); + } + + const tokenLaunchPromises = [ + { name: 'testToken1', symbol: 'TT1', nonce: 1 }, + { name: 'testToken2', symbol: 'TT2', nonce: 2 }, + { name: 'testToken3', symbol: 'TT3', nonce: 3 }, + { name: 'testToken4', symbol: 'TT4', nonce: 4 }, + { name: 'testToken5', symbol: 'TT5', nonce: 5 }, + { name: 'testToken6', symbol: 'TT6', nonce: 6 }, + { name: 'testToken7', symbol: 'TT7', nonce: 7 }, + { name: 'testToken8', symbol: 'TT8', nonce: 8 }, + { name: 'testToken9', symbol: 'TT9', nonce: 9 }, + { name: 'testToken10', symbol: 'TT10', nonce: 10 }, + ]; + + await Promise.all( + tokenLaunchPromises.map(({ name, symbol }) => + launchAndBuyToken(name, symbol), + ), + ); await vi.waitFor( async () => { - const launchpadTrade = await models.LaunchpadTrade.findOne({ - where: { token_address: token!.token_address, is_buy: true }, - }); - expect(launchpadTrade).toBeTruthy(); + const launchpadTrades = await models.LaunchpadTrade.findAll(); + expect(launchpadTrades.length).toEqual(10); }, { timeout: 100000, diff --git a/packages/commonwealth/test/devnet/integration/integrationUtils/mainSetup.ts b/packages/commonwealth/test/devnet/integration/integrationUtils/mainSetup.ts index 9298515c35e..96dea8a5445 100644 --- a/packages/commonwealth/test/devnet/integration/integrationUtils/mainSetup.ts +++ b/packages/commonwealth/test/devnet/integration/integrationUtils/mainSetup.ts @@ -13,14 +13,18 @@ import { anvilAccounts, setupWeb3 } from './process-setup/setupWeb3'; export async function setupCommonwealthE2E() { // setup outbox notifications - await outboxTriggerMigration( - models.sequelize.getQueryInterface(), - models.sequelize, - ); - await outboxTriggerMigrationFix( - models.sequelize.getQueryInterface(), - models.sequelize, - ); + try { + await outboxTriggerMigration( + models.sequelize.getQueryInterface(), + models.sequelize, + ); + await outboxTriggerMigrationFix( + models.sequelize.getQueryInterface(), + models.sequelize, + ); + } catch (e) { + // triggers already exist + } // need to set up anvil before we can run evmCE. // need to set up rmq before running consumer From 6889a453ac542b3cde64b78c4056e9c7c15c0579 Mon Sep 17 00:00:00 2001 From: kassad Date: Wed, 8 Jan 2025 12:46:23 -0800 Subject: [PATCH 2/2] temp commit --- .../test/devnet/integration/event-processing-lifecycle.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts b/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts index 05e8f142542..7a152f54918 100644 --- a/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts +++ b/packages/commonwealth/test/devnet/integration/event-processing-lifecycle.spec.ts @@ -34,6 +34,7 @@ describe('End to end event tests', () => { async function launchAndBuyToken(name, symbol) { console.log(`launching token ${nonce}`); + // temp nonce += BigInt(1); try { await cp.launchToken(