Skip to content
Open
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
177 changes: 176 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, BN_ZERO, MangataGenericEvent } 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,168 @@ 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.batchAsSudoFinalized(
Assets.mintToken(bootstrapCurrency, testUser1),
Assets.mintNative(testUser1),
);

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 provisionBootstrap(testUser1, GASP_ASSET_ID, 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);
});

test("[BUG] maintenance - GIVEN bootstrap start AND provision with one user WHEN maintenanceMode runs in Public phase THEN bootstrap pool doesn't appear", 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.batchAsSudoFinalized(
Assets.mintToken(bootstrapCurrency, testUser1),
Assets.mintNative(testUser1),
);

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);

await provisionBootstrap(
testUser1,
bootstrapCurrency,
BN_HUNDRED_BILLIONS,
).then((result) => {
const eventResponse = getEventResultFromMangataTx(result);
expect(eventResponse.state).toEqual(ExtrinsicResult.ExtrinsicSuccess);
});

await provisionBootstrap(testUser1, GASP_ASSET_ID, BN_HUNDRED_BILLIONS).then(
(result) => {
const eventResponse = getEventResultFromMangataTx(result);
expect(eventResponse.state).toEqual(ExtrinsicResult.ExtrinsicSuccess);
},
);

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

await checkMaintenanceStatus(true, false);

await waitForBootstrapStatus("Finished", bootstrapPeriod);

//BUG - we need to have a possibility to claim rewards, but we received an error here
await claimRewardsBootstrap(testUser1).then((result) => {
const eventResponse = getEventResultFromMangataTx(result);
expect(eventResponse.state).toEqual(ExtrinsicResult.ExtrinsicSuccess);
});

const poolId = await getLiquidityAssetId(GASP_ASSET_ID, bootstrapCurrency);
expect(poolId).bnGt(BN_ZERO);
await checkLastBootstrapFinalized(sudo);

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();
await checkMaintenanceStatus(false, false);
});