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

update astar tests & update astar v3 #72

Closed
wants to merge 1 commit 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
93 changes: 39 additions & 54 deletions src/adapters/astar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { Bridge } from '../bridge';
import { AstarAdapter } from './astar';
import { AcalaAdapter } from './acala';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { FixedPointNumber } from '@acala-network/sdk-core';

describe.skip('astar adapter should work', () => {
import { Bridge } from "../bridge";
import { AstarAdapter, ShidenAdapter } from "./astar";
import { AcalaAdapter } from "./acala";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { FixedPointNumber } from "@acala-network/sdk-core";
import { ChainId } from "../configs";

describe.skip("astar adapter should work", () => {
jest.setTimeout(50000);

const address = '5GREeQcGHt7na341Py6Y6Grr38KUYRvVoiFSiDB52Gt7VZiN';
const address = "5GREeQcGHt7na341Py6Y6Grr38KUYRvVoiFSiDB52Gt7VZiN";
let bridge: Bridge;

beforeAll(async () => {
const astar = new AstarAdapter();
const shiden = new ShidenAdapter();
const acala = new AcalaAdapter();

const astarApi = new ApiPromise({ provider: new WsProvider('wss://rpc.astar.network') });
const acalaApi = new ApiPromise({ provider: new WsProvider('wss://acala-rpc-0.aca-api.network') });
const astarApi = new ApiPromise({ provider: new WsProvider("wss://rpc.astar.network") });
const shidenApi = new ApiPromise({ provider: new WsProvider("wss://shiden-rpc.dwellir.com") });
const acalaApi = new ApiPromise({ provider: new WsProvider("wss://acala-rpc-0.aca-api.network") });

await astar.init(astarApi);
await shiden.init(shidenApi);
await acala.init(acalaApi);

bridge = new Bridge({
adapters: [astar, acala],
adapters: [astar, acala, shiden],
});
});

Expand All @@ -33,60 +37,41 @@ describe.skip('astar adapter should work', () => {
await api.disconnect();
}
}
})
});

test('bridge sdk init should work', (done) => {
test("bridge sdk init should work", (done) => {
expect(bridge).toBeDefined();

done();
});

test('transfer ASTR from astar to acala should work', (done) => {
try {
const adapter = bridge.findAdapter('astar');

expect(adapter).toBeDefined();

if (!adapter) return;

const astr = adapter.getToken('ASTR');

const tx = adapter.createTx({
to: 'acala',
token: 'ASTR',
amount: new FixedPointNumber(1, astr.decimals),
address
});

expect(tx).toBeDefined();
done();
} catch (e) {
// ignore error
}
});

test('transfer ACA from shiden to karura should work', (done) => {
try {
["astar", "shiden"].forEach((chainId) => {
const tokens = chainId === "astar" ? ["AUSD", "ACA", "LDOT", "ASTR"] : ["KUSD", "SDN"];
const destChain = chainId === "astar" ? "acala" : "karura";
tokens.forEach((token) => {
test(`transfer ${token} from ${chainId} to ${destChain} should work`, (done) => {
try {
const adapter = bridge.findAdapter(chainId as ChainId);

const adapter = bridge.findAdapter('astar');
expect(adapter).toBeDefined();

expect(adapter).toBeDefined();
if (!adapter) return;

if (!adapter) return;
const t = adapter.getToken(token);

const aca = adapter.getToken('ACA');
const tx = adapter.createTx({
to: destChain,
token,
amount: new FixedPointNumber(1, t.decimals),
address,
});

const tx = adapter.createTx({
to: 'acala',
token: 'ACA',
amount: new FixedPointNumber(1, aca.decimals),
address
expect(tx).toBeDefined();
done();
} catch (e) {
// ignore error
}
});

expect(tx).toBeDefined();
done();
} catch (e) {
// ignore error
}
});
});
});
12 changes: 4 additions & 8 deletions src/adapters/astar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ class BaseAstarAdapter extends BaseCrossChainAdapter {
// to karura
KUSD: "0x0081000000000000000000000000000000000000000000000000000000000000",
// to acala
ACA: "0x0000",
AUSD: "0x0001",
LDOT: "0x0003",
ACA: "0x0000000000000000000000000000000000000000000000000000000000000000",
AUSD: "0x0001000000000000000000000000000000000000000000000000000000000000",
LDOT: "0x0003000000000000000000000000000000000000000000000000000000000000",
};

const tokenId = tokenIds[token];
Expand All @@ -318,11 +318,7 @@ class BaseAstarAdapter extends BaseCrossChainAdapter {
createPolkadotXCMAccount(this.api, accountId),
createPolkadotXCMAsset(this.api, rawAmount, [
{ Parachain: paraChainId },
this.chain.id === "astar"
? {
GeneralKey: tokenId,
}
: { GeneralKey: { length: 2, data: tokenId } },
{ GeneralKey: { length: 2, data: tokenId } },
]),
0
);
Expand Down