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..7a152f54918 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,96 @@ 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, - }, - ); + // temp + 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