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

Added test to try to reproduce prefetch bug #10509

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const launchToken = async (
walletAddress: string,
connectorWeight: number,
tokenCommunityManager: string,
nonce?: number,
) => {
const txReceipt = await contract.methods
.launchTokenWithLiquidity(
Expand All @@ -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;
};

Expand Down
7 changes: 1 addition & 6 deletions libs/model/src/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,96 @@ describe('End to end event tests', () => {
contractAddresses.launchpad,
) as unknown as Contract<typeof launchpadFactoryAbi>;

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<typeof lpBondingCurveAbi>;
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading