diff --git a/src/adapters/astar.spec.ts b/src/adapters/astar.spec.ts index 8bef04ce..ff4232b1 100644 --- a/src/adapters/astar.spec.ts +++ b/src/adapters/astar.spec.ts @@ -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], }); }); @@ -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 - } + }); }); }); diff --git a/src/adapters/astar.ts b/src/adapters/astar.ts index a5e26aa6..5ff5f861 100644 --- a/src/adapters/astar.ts +++ b/src/adapters/astar.ts @@ -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]; @@ -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 );