-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add xcm upm mock endpoint and tests (#792)
* Accept tokens from other parachains * Remove waived locations * xcm tests constants for dancelight * Configure dancelight xcm mocknets * Dancelight xcm test working * toml maid * Extract Parse and its impl for location * Rust fmt * Toml fmt * Extract NativeAssetReserve from xcm config to commons * Add xcm upm mock endpoint * Xcm mock working * Remove unnecesary changes * Add xcm upm mock endpoint * Xcm mock working * Remove unnecesary changes * Remove unnecesary logs * Revert moonwall config changes * Prettify * add test for receiving a ump message * Fix tests * Improve xcm ump dancelight test * Clippy is not complaining anymore :D * Fix typo * Fix merge * Fix merge issues * Fix merge issues * Fix merge issues * Fix merge issues * Missing fixes * Format * Improve the way we handle upward messages * Remove unnecesary clone * Improve dev_rpc_data type --------- Co-authored-by: Agusrodri <[email protected]>
- Loading branch information
Showing
7 changed files
with
221 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { beforeAll, customDevRpcRequest, describeSuite, expect } from "@moonwall/cli"; | ||
import { generateKeyringPair, KeyringPair } from "@moonwall/util"; | ||
import { ApiPromise, Keyring } from "@polkadot/api"; | ||
import { u8aToHex } from "@polkadot/util"; | ||
import { jumpToSession } from "util/block"; | ||
import { injectUmpMessageAndSeal, RawXcmMessage, XcmFragment } from "../../../util/xcm"; | ||
|
||
describeSuite({ | ||
id: "DTR1003", | ||
title: "XCM - Succeeds sending XCM", | ||
foundationMethods: "dev", | ||
testCases: ({ context, it }) => { | ||
let polkadotJs: ApiPromise; | ||
let alice: KeyringPair; | ||
let random: KeyringPair; | ||
let transferredBalance; | ||
|
||
beforeAll(async function () { | ||
polkadotJs = context.polkadotJs(); | ||
alice = new Keyring({ type: "sr25519" }).addFromUri("//Alice", { | ||
name: "Alice default", | ||
}); | ||
|
||
random = generateKeyringPair("sr25519"); | ||
|
||
transferredBalance = 100_000_000_000_000_000n; | ||
|
||
const location = { | ||
V3: { | ||
parents: 0, | ||
interior: { X1: { Parachain: 2000 } }, | ||
}, | ||
}; | ||
|
||
const locationToAccountResult = await polkadotJs.call.locationToAccountApi.convertLocation(location); | ||
expect(locationToAccountResult.isOk); | ||
|
||
const convertedAddress = locationToAccountResult.asOk.toJSON(); | ||
|
||
let aliceNonce = (await polkadotJs.query.system.account(alice.address)).nonce.toNumber(); | ||
|
||
// Send some tokens to the sovereign account of para 2000 | ||
const txSigned = polkadotJs.tx.balances.transferAllowDeath(convertedAddress, transferredBalance); | ||
await context.createBlock(await txSigned.signAsync(alice, { nonce: aliceNonce++ }), { | ||
allowFailures: false, | ||
}); | ||
|
||
const balanceSigned = (await polkadotJs.query.system.account(convertedAddress)).data.free.toBigInt(); | ||
expect(balanceSigned).to.eq(transferredBalance); | ||
}); | ||
|
||
it({ | ||
id: "T01", | ||
title: "Should succeed receiving tokens", | ||
test: async function () { | ||
const balanceRandomBefore = ( | ||
await polkadotJs.query.system.account(random.address) | ||
).data.free.toBigInt(); | ||
expect(balanceRandomBefore).to.eq(0n); | ||
|
||
const xcmMessage = new XcmFragment({ | ||
assets: [ | ||
{ | ||
multilocation: { | ||
parents: 0, | ||
interior: { Here: null }, | ||
}, | ||
fungible: transferredBalance / 10n, | ||
}, | ||
], | ||
beneficiary: u8aToHex(random.addressRaw), | ||
}) | ||
.withdraw_asset() | ||
.buy_execution() | ||
.deposit_asset_v3() | ||
.as_v3(); | ||
|
||
// Enable para inherent to process xcm message | ||
await customDevRpcRequest("mock_enableParaInherentCandidate", []); | ||
|
||
// Send ump message | ||
await injectUmpMessageAndSeal(context, { | ||
type: "XcmVersionedXcm", | ||
payload: xcmMessage, | ||
} as RawXcmMessage); | ||
|
||
// Wait until message is processed | ||
await jumpToSession(context, 3); | ||
await context.createBlock(); | ||
|
||
const balanceRandomAfter = (await polkadotJs.query.system.account(random.address)).data.free.toBigInt(); | ||
expect(Number(balanceRandomAfter)).to.be.greaterThan(0); | ||
}, | ||
}); | ||
}, | ||
}); |
Oops, something went wrong.