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

localdev tests #1238

Merged
merged 6 commits into from
Aug 3, 2023
Merged
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
7 changes: 7 additions & 0 deletions .github/workflows/integration_test_manta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ jobs:
with:
name: ${{ matrix.chain-spec.id }}-alice-stress.log
path: ${{ github.workspace }}/polkadot-launch/9921.log
- name: run tests
run: |
sleep 120
cd ${{ github.workspace }}/Manta/tests
yarn install
yarn
MANTA_BINARY=$HOME/.local/bin/manta yarn tests
docker-image-test:
timeout-minutes: 120
if: contains(github.event.pull_request.labels.*.name, 'A-manta' || github.ref == 'refs/heads/manta')
Expand Down
92 changes: 92 additions & 0 deletions tests/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {BN} from "@polkadot/util";

export const MANTA_1B = "1000000000000000000000000000";
export const MANTA_1K = new BN("1000000000000000000000");
export const LP_1K = "1000000000000000";
export const LP_2K = "2000000000000000";
export const USDT_10M = new BN("10000000000000");
export const USDT_20M = new BN("20000000000000");
export const USDC_10M = new BN("100000000000000000");
export const USDC_20M = new BN("200000000000000000");

export const USDT_LOCATION = {
V1: {
parents: 1,
interior: {
X3: [
{
Parachain: 1000
},
{
PalletInstance: 50
},
{
GeneralIndex: 1984
}
]
}
}
};

export const USDT_METADATA = {
metadata: {
name: "Tether USD",
symbol: "USDT",
decimals: 6,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};

export const USDC_LOCATION = {
V1: {
parents: 1,
interior: {
X3: [
{
Parachain: 1000
},
{
PalletInstance: 50
},
{
GeneralIndex: 1985
}
]
}
}
};

export const USDC_METADATA = {
metadata: {
name: "USDC",
symbol: "USDC",
decimals: 10,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};

export const MANDEX_METADATA = {
metadata: {
name: "MANDEX",
symbol: "MANDEX",
decimals: 18,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};

export const LP_USDT_USDC_METADATA = {
metadata: {
name: "LP-USDC-USDT",
symbol: "LP",
decimals: 12,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};
7 changes: 6 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"runtime_upgrade_test": "mocha -r ts-node/register runtime_upgrade_test.ts",
"parachain_lease_test": "mocha -r ts-node/register check_parachain_lease_expiration.ts",
"test_farming": "mocha -r ts-node/register test-farming.ts",
"tests": "mocha -r ts-node/register --timeout 50000 tests/test-*.ts",
"lint": "eslint ."
},
"keywords": [],
Expand All @@ -27,12 +28,16 @@
},
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^9.1.1",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"eslint": "^8.18.0",
"eslint-config-prettier": "8.5.0",
"mocha": "^10.0.0"
"mocha": "^10.0.0",
"mocha-steps": "^1.3.0",
"get-port": "^5.1.1"
}
}
92 changes: 12 additions & 80 deletions tests/test-farming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,19 @@ import { farming_rpc_api, farming_types } from './types';
import { expect } from 'chai';
import minimist, { ParsedArgs } from 'minimist';
import {execute_transaction, execute_via_governance,timer } from "./chain-util";
import {
LP_USDT_USDC_METADATA,
MANDEX_METADATA,
USDC_LOCATION,
USDC_METADATA,
USDT_LOCATION,
USDT_METADATA
} from "./constants";

const test_config = {
ws_address: "ws://127.0.0.1:9800",
timeout: 2000000
}
const location = {
V1: {
parents: 1,
interior: {
X3: [
{
Parachain: 1000
},
{
PalletInstance: 50
},
{
GeneralIndex: 1984
}
]
}
}
};
const location2 = {
V1: {
parents: 1,
interior: {
X3: [
{
Parachain: 1000
},
{
PalletInstance: 50
},
{
GeneralIndex: 1985
}
]
}
}
};
const metadata = {
metadata: {
name: "Tether USD",
symbol: "USDT",
decimals: 6,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};
const metadata2 = {
metadata: {
name: "USDC",
symbol: "USDC",
decimals: 10,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};
const metadata3 = {
metadata: {
name: "MANDEX",
symbol: "MANDEX",
decimals: 18,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};
const lp_metadata = {
metadata: {
name: "LP-USDC-USDT",
symbol: "LP",
decimals: 12,
isFrozen: false
},
minBalance: 1,
isSufficient: true
};

function local_asset(parachainId: number, generalKey: string) {
let location = {
Expand Down Expand Up @@ -129,7 +61,7 @@ describe('Node RPC Test', () => {
console.log(new Date() + " parachain:" + parachainId);

// register asset 8(decimal:6)
let callData = api.tx.assetManager.registerAsset(location, metadata);
let callData = api.tx.assetManager.registerAsset(USDT_LOCATION, USDT_METADATA);
await execute_via_governance(api, alice, callData);

let state: any = await api.query.assetManager.assetIdMetadata(8);
Expand All @@ -140,7 +72,7 @@ describe('Node RPC Test', () => {
console.log(new Date() + " Register Asset8:" + JSON.stringify(state));

// 9(decimal:10)
callData = api.tx.assetManager.registerAsset(location2, metadata2);
callData = api.tx.assetManager.registerAsset(USDC_LOCATION, USDC_METADATA);
await execute_via_governance(api, alice, callData);
state = await api.query.assetManager.assetIdMetadata(9);
while(state.isNone) {
Expand All @@ -150,7 +82,7 @@ describe('Node RPC Test', () => {
console.log(new Date() + " Register Asset9:" + JSON.stringify(state));

// 10(decimal:18)
callData = api.tx.assetManager.registerAsset(local_asset(parachainId, "MANDEX"), metadata3);
callData = api.tx.assetManager.registerAsset(local_asset(parachainId, "MANDEX"), MANDEX_METADATA);
await execute_via_governance(api, alice, callData);
let mandexId = 10;
state = await api.query.assetManager.assetIdMetadata(mandexId);
Expand All @@ -161,7 +93,7 @@ describe('Node RPC Test', () => {
console.log(new Date() + " Register Asset10:" + JSON.stringify(state));

// register lp asset 11(decimal:12)
callData = api.tx.assetManager.registerLpAsset(8, 9, lp_metadata);
callData = api.tx.assetManager.registerLpAsset(8, 9, LP_USDT_USDC_METADATA);
await execute_via_governance(api, alice, callData);
let lpAssetId = 11;
state = await api.query.assetManager.assetIdMetadata(lpAssetId);
Expand Down
18 changes: 18 additions & 0 deletions tests/tests/test-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import {describeWithManta, executeTx, remark} from "./util";
import '@polkadot/api-augment';
import {USDT_LOCATION, USDT_METADATA} from "../constants";

describeWithManta("Manta RPC (Assets)", (context) => {
step("asset manager register asset should work", async function () {
const parachainId = Number(await context.api.query.parachainInfo.parachainId());
console.log(new Date() + " parachain:" + parachainId);

let callData = await context.api.tx.assetManager.registerAsset(USDT_LOCATION, USDT_METADATA);
await executeTx(context, callData, true);

let state: any = await context.api.query.assetManager.assetIdMetadata(8);
console.log(new Date() + " Register Asset8:" + JSON.stringify(state));
});
});
18 changes: 18 additions & 0 deletions tests/tests/test-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import {describeWithManta, remark} from "./util";
import '@polkadot/api-augment';
import {MANTA_1B} from "../constants";

describeWithManta("Manta RPC (Balance)", (context) => {
step("genesis balance is setup correctly", async function () {
expect((await context.api.query.system.number()).toString()).to.equal("0");

const aliceBalance = (await context.api.query.system.account(context.alice.address)).data.free.toString();
expect(aliceBalance.toString()).to.equal(MANTA_1B);

await remark(context);

expect((await context.api.query.system.number()).toString()).to.equal("1");
});
});
85 changes: 85 additions & 0 deletions tests/tests/test-dex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import {describeWithManta, executeTx, remark} from "./util";
import '@polkadot/api-augment';
import {
LP_1K, LP_2K,
LP_USDT_USDC_METADATA, MANTA_1K, USDC_10M, USDC_20M,
USDC_LOCATION,
USDC_METADATA,
USDT_10M, USDT_20M,
USDT_LOCATION,
USDT_METADATA
} from "../constants";
import {BN} from "@polkadot/util";

describeWithManta("Manta RPC (Dex)", (context) => {
step("dex add liquidity should work", async function () {
const api = context.api;
const alice = context.alice.address;
const bob = context.bob.address;

const parachainId = Number(await api.query.parachainInfo.parachainId());
console.log(new Date() + " parachain:" + parachainId);

let callData = await api.tx.assetManager.registerAsset(USDT_LOCATION, USDT_METADATA);
await executeTx(context, callData, true);

callData = await api.tx.assetManager.registerAsset(USDC_LOCATION, USDC_METADATA);
await executeTx(context, callData, true);

callData = api.tx.assetManager.registerLpAsset(8, 9, LP_USDT_USDC_METADATA);
await executeTx(context, callData, true);

callData = api.tx.zenlinkProtocol.createPair([parachainId,2,8], [parachainId,2,9]);
await executeTx(context, callData, true);

callData = api.tx.balances.transfer(bob, MANTA_1K);
await executeTx(context, callData);

callData = api.tx.assetManager.mintAsset(8, alice, USDT_20M);
await executeTx(context, callData, true);
callData = api.tx.assetManager.mintAsset(8, bob, USDT_20M);
await executeTx(context, callData, true);

callData = api.tx.assetManager.mintAsset(9, alice, USDC_20M);
await executeTx(context, callData, true);
callData = api.tx.assetManager.mintAsset(9, bob, USDC_20M);
await executeTx(context, callData, true);

// Alice add liquidity
callData = api.tx.zenlinkProtocol.addLiquidity([parachainId,2,8], [parachainId,2,9],
USDT_10M, USDC_10M, USDT_10M, USDC_10M, 1000);
await executeTx(context, callData);

let state = await api.query.zenlinkProtocol.pairStatuses([[parachainId,2,8], [parachainId,2,9]]);
expect(JSON.parse(JSON.stringify(state)).trading.totalSupply.toString()).to.equal(LP_1K);

// Bob add liquidity
callData = api.tx.zenlinkProtocol.addLiquidity([parachainId,2,8], [parachainId,2,9],
USDT_10M, USDC_10M, USDT_10M, USDC_10M, 1000);
await executeTx(context, callData, false, false);

state = await api.query.zenlinkProtocol.pairStatuses([[parachainId,2,8], [parachainId,2,9]]);
expect(JSON.parse(JSON.stringify(state)).trading.totalSupply.toString()).to.equal(LP_2K);

state = await api.query.assets.account(10, alice);
expect(JSON.parse(JSON.stringify(state)).balance.toString()).to.equal(LP_1K);

state = await api.query.assets.account(10, bob);
expect(JSON.parse(JSON.stringify(state)).balance.toString()).to.equal(LP_1K);

callData = api.tx.zenlinkProtocol.removeLiquidity([parachainId,2,8], [parachainId,2,9],
new BN(LP_1K),
USDT_10M, USDC_10M,
alice,
1000);
await executeTx(context, callData);

state = await api.query.zenlinkProtocol.pairStatuses([[parachainId,2,8], [parachainId,2,9]]);
expect(JSON.parse(JSON.stringify(state)).trading.totalSupply.toString()).to.equal(LP_1K);

state = await api.query.assets.account(10, alice);
expect(JSON.parse(JSON.stringify(state))).to.equal(null);
});
});
Loading
Loading