Skip to content
Open
Changes from 1 commit
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
84 changes: 83 additions & 1 deletion test/sequential/xyk-pallet.api.maintenance-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hexToU8a } from "@polkadot/util";
import { getApi, initApi } from "../../utils/api";
import { Assets } from "../../utils/Assets";
import { GASP_ASSET_ID } from "../../utils/Constants";
import { MangataGenericEvent } from "gasp-sdk";
import { BN_HUNDRED_BILLIONS, MangataGenericEvent, toBN } from "gasp-sdk";
import { BN } from "@polkadot/util";
import { setupApi, setupUsers, sudo } from "../../utils/setup";
import { Sudo } from "../../utils/sudo";
Expand All @@ -20,6 +20,16 @@ import { testLog } from "../../utils/Logger";
import { checkMaintenanceStatus } from "../../utils/validators";
import { Market } from "../../utils/market";
import { FoundationMembers } from "../../utils/FoundationMembers";
import {
checkLastBootstrapFinalized,
claimRewardsBootstrap,
createNewBootstrapCurrency,
provisionBootstrap,
scheduleBootstrap,
setupBootstrapTokensBalance,
waitForBootstrapStatus,
} from "../../utils/Bootstrap";
import { xykErrors } from "../../utils/utils";

jest.spyOn(console, "log").mockImplementation(jest.fn());
jest.setTimeout(2500000);
Expand Down Expand Up @@ -264,3 +274,75 @@ async function getSudoError(

expect(sudoEventError.name).toEqual(expectedError);
}

test("maintenance- bootstrap can be run in maintenanceMode, but you can't provide it and the pool will not be created", async () => {
await checkMaintenanceStatus(false, false);
await checkLastBootstrapFinalized(sudo);
const bootstrapCurrency = await createNewBootstrapCurrency(sudo);
const waitingPeriod = 10;
const bootstrapPeriod = 8;

[testUser1] = setupUsers();

await setupBootstrapTokensBalance(bootstrapCurrency, sudo, [testUser1]);

await sudo.mint(bootstrapCurrency, testUser1, toBN("1", 20));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse the Asset.mint and add it to the next batchAsSudoFinalize. One day we will get rid of this sudo.mint stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


await Sudo.batchAsSudoFinalized(
Sudo.sudoAsWithAddressString(
foundationAccountAddress,
Maintenance.switchMaintenanceModeOn(),
),
);

await checkMaintenanceStatus(true, false);

await scheduleBootstrap(
sudo,
GASP_ASSET_ID,
bootstrapCurrency,
waitingPeriod,
bootstrapPeriod,
).then((result) => {
const eventResponse = getEventResultFromMangataTx(result);
expect(eventResponse.state).toEqual(ExtrinsicResult.ExtrinsicSuccess);
});

await waitForBootstrapStatus("Public", waitingPeriod);

// check that user can make provision while bootstrap running
await provisionBootstrap(
testUser1,
bootstrapCurrency,
BN_HUNDRED_BILLIONS,
).then((result) => {
const eventResponse = getEventResultFromMangataTx(result);
expect(eventResponse.state).toEqual(ExtrinsicResult.ExtrinsicFailed);
expect(eventResponse.data).toEqual("ProvisioningBlockedByMaintenanceMode");
});

await waitForBootstrapStatus("Finished", bootstrapPeriod);
await claimRewardsBootstrap(testUser1).then((result) => {
const eventResponse = getEventResultFromMangataTx(result);
expect(eventResponse.state).toEqual(ExtrinsicResult.ExtrinsicFailed);
expect(eventResponse.data).toEqual(xykErrors.MathOverflow);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow. math overflow? :O

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is because the amount is 0 or -1

});

const foundationSwitchModeEvents = await Sudo.batchAsSudoFinalized(
Sudo.sudoAsWithAddressString(
foundationAccountAddress,
Maintenance.switchMaintenanceModeOff(),
),
);

const filteredEvent = foundationSwitchModeEvents.filter(
(extrinsicResult) => extrinsicResult.method === "SudoAsDone",
);
const eventIndex = JSON.parse(JSON.stringify(filteredEvent[0].event.data[0]));
expect(eventIndex.ok).toBeDefined();

const poolId = await getLiquidityAssetId(GASP_ASSET_ID, bootstrapCurrency);
expect(poolId).bnEqual(new BN(-1));
Comment on lines +357 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a side effect of no one being able to provide liq. Can you do another test that starts maintenance after a a provision being done? ie:
1,- CheckMaintenanceOff
2,- Start bootstrap
3,- Wait for Public phase and provision with one user
4,- start maintenance
5,- wait for boostrap finished.
6,- Check that bootstrap did not / did create the pool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario was created, but we have a bug here https://mangatafinance.atlassian.net/browse/GASP-2210

await checkMaintenanceStatus(false, false);
await checkLastBootstrapFinalized(sudo);
});