Skip to content

Commit

Permalink
unskip core function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Jun 30, 2023
1 parent 183d035 commit 6b06081
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
14 changes: 7 additions & 7 deletions src/api-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { firstValueFrom } from 'rxjs';
import { firstValueFrom } from "rxjs";

import { ApiProvider } from './api-provider';
import { ChainId } from './configs';
import { ApiProvider } from "./api-provider";
import { ChainId } from "./configs";

describe.skip('api-provider', () => {
describe("api-provider", () => {
jest.setTimeout(30000);

const provider = new ApiProvider();

test('connectFromChain should be ok', async () => {
const chains: ChainId[] = ['kusama', 'karura', 'polkadot', 'acala'];
test("connectFromChain should be ok", async () => {
const chains: ChainId[] = ["kusama", "karura", "polkadot", "acala"];

expect(provider.getApi(chains[0])).toEqual(undefined);
expect(provider.getApi(chains[1])).toEqual(undefined);

const res = await firstValueFrom(
provider.connectFromChain(chains, {
karura: ['wss://karura.polkawallet.io']
karura: ["wss://karura.api.onfinality.io/public-ws"],
})
);

Expand Down
57 changes: 35 additions & 22 deletions src/bridge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { firstValueFrom } from "rxjs";

import { firstValueFrom } from 'rxjs';
import { ApiProvider } from "./api-provider";
import { BaseCrossChainAdapter } from "./base-chain-adapter";
import { PolkadotAdapter } from "./adapters/polkadot";
import { ChainId } from "./configs";
import { Bridge } from "./bridge";
import { AcalaAdapter } from "./adapters/acala";
import { FN } from "./types";

import { ApiProvider } from './api-provider';
import { BaseCrossChainAdapter } from './base-chain-adapter';
import { PolkadotAdapter } from './adapters/polkadot';
import { ChainId } from './configs';
import { Bridge } from './bridge';
import { AcalaAdapter } from './adapters/acala';
import { FN } from './types';

describe.skip('Bridge sdk usage', () => {
describe("Bridge sdk usage", () => {
jest.setTimeout(30000);

const provider = new ApiProvider();
Expand All @@ -34,18 +33,30 @@ describe.skip('Bridge sdk usage', () => {
adapters: Object.values(availableAdapters),
});

test('1. bridge init should be ok', async () => {
afterAll(async () => {
for (const adapter of bridge.adapters) {
const api = adapter.getApi();

if (api) {
await api.disconnect();
}
}

await new Promise((resolve) => setTimeout(() => resolve(undefined), 5000));
});

test("1. bridge init should be ok", async () => {
expect(bridge.router.getRouters().length).toBeGreaterThanOrEqual(Object.keys(availableAdapters).length);
expect(bridge.router.getDestinationChains({from: 'acala'}).length).toBeGreaterThanOrEqual(0);
expect(bridge.router.getAvailableTokens({from: 'acala', to: 'polkadot'}).length).toBeGreaterThanOrEqual(0);
expect(bridge.router.getDestinationChains({ from: "acala" }).length).toBeGreaterThanOrEqual(0);
expect(bridge.router.getAvailableTokens({ from: "acala", to: "polkadot" }).length).toBeGreaterThanOrEqual(0);
});

test('2. connect fromChain should be ok', async () => {
test("2. connect fromChain should be ok", async () => {
const chains = Object.keys(availableAdapters) as ChainId[];

expect(provider.getApi(chains[0])).toEqual(undefined);
expect(provider.getApi(chains[1])).toEqual(undefined);

// connect all adapters
const connected = await firstValueFrom(provider.connectFromChain(chains, undefined));
// and set apiProvider for each adapter
Expand All @@ -68,24 +79,26 @@ describe.skip('Bridge sdk usage', () => {
}, 1000);
});

test('3. token balance query & create tx should be ok', async () => {
const chain: ChainId = 'acala';
const toChain: ChainId = 'polkadot';
const token = 'DOT';
const testAddress = '23M5ttkmR6Kco7bReRDve6bQUSAcwqebatp3fWGJYb4hDSDJ';
test("3. token balance query & create tx should be ok", async () => {
const chain: ChainId = "acala";
const toChain: ChainId = "polkadot";
const token = "DOT";
const testAddress = "23M5ttkmR6Kco7bReRDve6bQUSAcwqebatp3fWGJYb4hDSDJ";

const balance = await firstValueFrom(availableAdapters[chain].subscribeTokenBalance(token, testAddress));

expect(balance.free.toNumber()).toBeGreaterThanOrEqual(0);
expect(balance.available.toNumber()).toBeGreaterThanOrEqual(0);

const inputConfig = await firstValueFrom(availableAdapters[chain].subscribeInputConfig({to: toChain, token, address:testAddress, signer: testAddress}));
const inputConfig = await firstValueFrom(
availableAdapters[chain].subscribeInputConfig({ to: toChain, token, address: testAddress, signer: testAddress })
);

expect(BigInt(inputConfig.estimateFee)).toBeGreaterThanOrEqual(BigInt(0));
expect(inputConfig.minInput.toNumber()).toBeGreaterThan(0);
expect(inputConfig.maxInput.toNumber()).toBeLessThanOrEqual(balance.available.toNumber());

const tx = availableAdapters[chain].createTx({to: toChain, token, amount: FN.fromInner('10000000000', 10), address:testAddress });
const tx = availableAdapters[chain].createTx({ to: toChain, token, amount: FN.fromInner("10000000000", 10), address: testAddress });

expect(tx.args.length).toBeGreaterThan(1);
});
Expand Down
26 changes: 12 additions & 14 deletions src/cross-chain-router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { chains } from "./configs";
import { BridgeRouterManager } from "./cross-chain-router";
import { RouteConfigs } from "./types";

describe.skip("cross-chain-router-manager", () => {
describe("cross-chain-router-manager", () => {
let manager: BridgeRouterManager;
let api: ApiPromise;
let wallet: Wallet;
Expand Down Expand Up @@ -119,20 +119,18 @@ describe.skip("cross-chain-router-manager", () => {
});

beforeAll(async () => {
await initSDK();
try {
await initSDK();
} catch (err) {
// ignore node disconnect issue
}
});

// test('get routers config should be ok', async () => {

// manager = new BridgeRouterManager();

// manager.addRouters(
// RouteConfigs.karura.map(e => ({...e, from: 'karura'})),
// false
// );
afterAll(async () => {
if (api) {
await api.disconnect();
}

// const routers = manager.getRouters();
// console.log(routers[0].xcm?.weightLimit?.toString());
// expect(routers[0].xcm?.fee.token).toEqual('KSM');
// });
await new Promise((resolve) => setTimeout(() => resolve(undefined), 5000));
});
});

0 comments on commit 6b06081

Please sign in to comment.