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

wip try run e2e with chops #248

Closed
wants to merge 21 commits into from
Closed
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "GPLv3",
"private": true,
"dependencies": {
"@acala-network/chopsticks": "^0.8.3",
"@acala-network/chopsticks": "0.9.1-2",
"@babel/plugin-proposal-decorators": "^7.17.8",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-syntax-flow": "^7.22.5",
Expand Down Expand Up @@ -70,10 +70,13 @@
"test": "jest",
"test-run": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --forceExit ",
"test-parallel": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-parallel;rm nonce.db ; rm sudo.lock; node --expose-gc --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --ci --group=parallel --forceExit --workerIdleMemoryLimit=200MB --logHeapUsage",
"test-parallel-chops": "export MANGATA_ENDPOINT=ws://127.0.0.1:9946; export CHOPSTICK_ENABLED=true; export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-parallel;rm nonce.db ; rm sudo.lock; node --expose-gc --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --ci --group=parallel --group=-parallelSkipChops --forceExit --workerIdleMemoryLimit=200MB --logHeapUsage --max-workers=1",
"test-parallel-skipped-chops": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-parallel;rm nonce.db ; rm sudo.lock; node --expose-gc --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --ci --group=parallelSkipChops --forceExit --workerIdleMemoryLimit=200MB --logHeapUsage",
"test-sequential-no-bootstrap": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=sequential --group=-bootstrap --group=-rewards-bootstrap --forceExit ",
"test-seqgasless": "export GASLESS=true; export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=seqgasless --forceExit ",
"test-maintenance": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq-e2e; rm nonce.db; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=maintenance ",
"test-bootstrap": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=bootstrap --group=-bootstrap-rewards --forceExit ",
"test-bootstrap-chops": "export MANGATA_ENDPOINT=ws://127.0.0.1:9946; export CHOPSTICK_ENABLED=true; export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=bootstrap --group=-bootstrap-rewards --forceExit ",
"test-crowdloan": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=crowdloan --forceExit ",
"test-rewards-bootstrap": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=rewards-bootstrap --forceExit ",
"test-sequential-autocompound": "export JEST_HTML_REPORTERS_PUBLIC_PATH=reports/html-report-seq; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --group=rewardsV2Sequential --forceExit ",
Expand Down
3 changes: 2 additions & 1 deletion test/governance/candidacy.users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SudoUser } from "../../utils/Framework/User/SudoUser";
import { UserFactory, Users } from "../../utils/Framework/User/UserFactory";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import { getEnvironmentRequiredVars, waitForNBlocks } from "../../utils/utils";
import { setupApi } from "../../utils/setup";

// Global variables
const { chainUri: environmentUri } = getEnvironmentRequiredVars();
Expand Down Expand Up @@ -41,7 +42,7 @@ beforeAll(async () => {
await cryptoWaitReady(); // Wait for Polkadots WASM backend

// Instantiate nodes
bootnode = new Node(environmentUri);
bootnode = new Node(environmentUri, await setupApi());
await bootnode.connect();
await bootnode.subscribeToHead();

Expand Down
3 changes: 2 additions & 1 deletion test/governance/voting.users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SudoUser } from "../../utils/Framework/User/SudoUser";
import { UserFactory, Users } from "../../utils/Framework/User/UserFactory";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import { getEnvironmentRequiredVars, waitForNBlocks } from "../../utils/utils";
import { setupApi } from "../../utils/setup";

const { chainUri: environmentUri } = getEnvironmentRequiredVars();

Expand All @@ -29,7 +30,7 @@ jest.setTimeout(1500000);
beforeAll(async () => {
await cryptoWaitReady(); // Wait for Polkadots WASM backend

bootnode = new Node(environmentUri);
bootnode = new Node(environmentUri, await setupApi());
await bootnode.connect();
await bootnode.subscribeToHead();

Expand Down
18 changes: 9 additions & 9 deletions test/parallel/assetRegistry.getTradeable.rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @group parallel
*/
import { jest } from "@jest/globals";
import { getApi, initApi, mangata } from "../../utils/api";
import { getApi, initApi } from "../../utils/api";
import {
expectMGAExtrinsicSuDidSuccess,
filterEventData,
Expand All @@ -14,7 +14,7 @@ import { Assets } from "../../utils/Assets";
import { BN } from "@polkadot/util";
import { BN_THOUSAND } from "@mangata-finance/sdk";
import { Xyk } from "../../utils/xyk";
import { getLiquidityAssetId } from "../../utils/tx";
import { getLiquidityAssetId, getTradeableTokens } from "../../utils/tx";

jest.spyOn(console, "log").mockImplementation(jest.fn());
jest.setTimeout(1500000);
Expand Down Expand Up @@ -91,43 +91,43 @@ describe("AssetRegistry RPC -", () => {
});

test("GIVEN a token that does not exist on the asset registry THEN it won't be returned in RPC", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).not.toContain(
noRegistered.toString(),
);
});
});
test("GIVEN a token that does exist on the asset registry AND name is empty and symbol is empty and operation disabled is not set THEN it won't be returned in RPC", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).not.toContain(empty.toString());
});
});
test("GIVEN a token that does exist on the asset registry AND name is not empty and symbol is empty and operation disabled is not set THEN it won't be returned in RPC", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).not.toContain(onlyName.toString());
});
});
test("GIVEN a token that does exist on the asset registry AND name is not empty and symbol is not empty and operation disabled is not set THEN its returned in RPC", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).toContain(nameSymbol.toString());
});
});
test("GIVEN a token that does exist on the asset registry AND name is not empty and symbol is not empty and operation disabled is false THEN its returned in RPC", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).toContain(
nameSymbolDisableFalse.toString(),
);
});
});
test("GIVEN a token that does exist on the asset registry AND name is not empty and symbol is not empty and operation disabled is true THEN its not returned in RPC", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).not.toContain(
nameSymbolDisableTrue.toString(),
);
});
});
test("GIVEN a token that belongs to a pool WHEN pool is not disabled THEN the token is not filtered", async () => {
await mangata?.rpc.getTradeableTokens().then((tokens) => {
await getTradeableTokens().then((tokens) => {
expect(tokens.map((x) => x.tokenId)).toContain(liq.toString());
});
});
Expand Down
1 change: 1 addition & 0 deletions test/parallel/feeLock.API.feePayment.parallel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* @group paralgasless
* @group parallel
* @group parallelSkipChops
*/
import { jest } from "@jest/globals";
import { Keyring } from "@polkadot/api";
Expand Down
1 change: 1 addition & 0 deletions test/parallel/feeLock.API.rpcValueThresholds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*
* @group paralgasless
* @group parallel
* @group parallelSkipChops
*/
import { jest } from "@jest/globals";
import { Keyring } from "@polkadot/api";
Expand Down
15 changes: 10 additions & 5 deletions test/parallel/feeLock.API.swapValueThresholds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
*
* @group paralgasless
* @group parallel
* @group parallelSkipChops
*/
import { jest } from "@jest/globals";
import { Keyring } from "@polkadot/api";
import { getApi, initApi, mangata } from "../../utils/api";
import { getApi, initApi } from "../../utils/api";
import { Assets } from "../../utils/Assets";
import {
MGA_ASSET_ID,
Expand All @@ -16,7 +17,11 @@ import { waitSudoOperationSuccess } from "../../utils/eventListeners";
import { BN } from "@polkadot/util";
import { setupApi, setupUsers } from "../../utils/setup";
import { Sudo } from "../../utils/sudo";
import { updateFeeLockMetadata, sellAsset } from "../../utils/tx";
import {
updateFeeLockMetadata,
sellAsset,
isSellAssetLockFree,
} from "../../utils/tx";
import { AssetWallet, User } from "../../utils/User";
import {
getEnvironmentRequiredVars,
Expand Down Expand Up @@ -117,7 +122,7 @@ test("gasless- Given a feeLock correctly configured WHEN the user swaps two toke
const saleAssetValue = thresholdValue.mul(new BN(2));

await testUser1.refreshAmounts(AssetWallet.BEFORE);
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down Expand Up @@ -180,7 +185,7 @@ test("gasless- Given a feeLock correctly configured WHEN the user swaps two toke
const saleAssetValue = thresholdValue.sub(new BN(5));

await testUser1.refreshAmounts(AssetWallet.BEFORE);
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down Expand Up @@ -226,7 +231,7 @@ test("gasless- Given a feeLock correctly configured WHEN the user swaps two toke
const saleAssetValue = thresholdValue.mul(new BN(2));

await testUser1.refreshAmounts(AssetWallet.BEFORE);
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down
38 changes: 26 additions & 12 deletions test/parallel/feeLock.API.unlocking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
*
* @group paralgasless
* @group parallel
* @group parallelSkipChops
*/
import { jest } from "@jest/globals";
import { ApiPromise, Keyring } from "@polkadot/api";
import { getApi, initApi, mangata } from "../../utils/api";
import { getApi, initApi } from "../../utils/api";
import { Assets } from "../../utils/Assets";
import { MGA_ASSET_ID } from "../../utils/Constants";
import {
Expand All @@ -15,7 +16,12 @@ import {
import { BN_ZERO } from "@mangata-finance/sdk";
import { Extrinsic, setupApi, setupUsers } from "../../utils/setup";
import { Sudo } from "../../utils/sudo";
import { updateFeeLockMetadata, unlockFee, sellAsset } from "../../utils/tx";
import {
updateFeeLockMetadata,
unlockFee,
sellAsset,
isSellAssetLockFree,
} from "../../utils/tx";
import { AssetWallet, User } from "../../utils/User";
import {
getEnvironmentRequiredVars,
Expand Down Expand Up @@ -106,36 +112,44 @@ beforeAll(async () => {

await Sudo.batchAsSudoFinalized(...txs);
});

afterEach(async () => {
await waitNewBlock();
});
test("gasless- GIVEN some locked tokens and no more free MGX WHEN another tx is submitted AND lock period did not finished THEN the operation can not be submitted", async () => {
const api = getApi();
const feeLockAmount = await (await getFeeLockMetadata(api)).feeLockAmount;
await testUsers[0].addMGATokens(sudo, feeLockAmount);

const saleAssetValue = thresholdValue.sub(new BN(5));
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
expect(isFree).toBeFalsy();
await testUsers[0].sellAssets(firstCurrency, secondCurrency, saleAssetValue);

await expect(
sellAsset(
testUsers[0].keyRingPair,
firstCurrency,
secondCurrency,
saleAssetValue,
new BN(0),
).catch((reason) => {
throw new Error(reason.data);
}),
)
.catch((reason) => {
throw new Error(reason.data);
})
.then(() => {
throw new Error("This should have failed!");
}),
).rejects.toThrow(feeLockErrors.FeeLockingFail);
await waitNewBlock();
});

test("gasless- GIVEN some locked tokens and no more free MGX WHEN another tx is submitted AND lock period finished THEN the operation can be submitted ( unlock before locking )", async () => {
await testUsers[1].addMGATokens(sudo, new BN(feeLockAmount).add(new BN(1)));

const saleAssetValue = thresholdValue.sub(new BN(5));
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down Expand Up @@ -166,7 +180,7 @@ test("gasless- GIVEN some locked tokens WHEN querying accountFeeLockData THEN th
await testUsers[2].addMGATokens(sudo, new BN(feeLockAmount).add(new BN(1)));

const saleAssetValue = thresholdValue.sub(new BN(5));
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down Expand Up @@ -195,7 +209,7 @@ test("gasless- GIVEN some locked tokens and lastFeeLockBlock is lower than curre
await testUsers[3].addMGATokens(sudo, new BN(feeLockAmount).add(new BN(1)));

const saleAssetValue = thresholdValue.sub(new BN(5));
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down Expand Up @@ -236,7 +250,7 @@ test("gasless- GIVEN a lock WHEN the period is N THEN the tokens can not be unlo
await testUsers[4].addMGATokens(sudo, new BN(feeLockAmount));

const saleAssetValue = thresholdValue.sub(new BN(5));
const isFree = await mangata?.rpc.isSellAssetLockFree(
const isFree = await isSellAssetLockFree(
[firstCurrency.toString(), secondCurrency.toString()],
saleAssetValue,
);
Expand Down
Loading