Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/serde-1.0.200
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed May 6, 2024
2 parents 9ae7405 + 42d4e46 commit 4a3c3a8
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 196 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ bin/

node_modules
**/package-lock.json
**/build
14 changes: 9 additions & 5 deletions e2e_tests/common.js → e2e_tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const RELAY_ASSET_ID = 1;
import { ApiPromise } from "@polkadot/api";
import { SubmittableExtrinsic, SignerOptions } from "@polkadot/api/types";
import { KeyringPair } from "@polkadot/keyring/types";

async function submitExtrinsic(signer, call, options) {
const RELAY_ASSET_ID = 1;

async function submitExtrinsic(signer: KeyringPair, call: SubmittableExtrinsic<"promise">, options: Partial<SignerOptions>): Promise<void> {
return new Promise(async (resolve, reject) => {
const unsub = await call.signAndSend(signer, options, (result) => {
console.log(`Current status is ${result.status}`);
Expand All @@ -17,13 +21,13 @@ async function submitExtrinsic(signer, call, options) {
} else if (result.isError) {
console.log(`Transaction error`);
unsub();
return resolve();
return reject();
}
});
});
}

async function setupRelayAsset(api, signer) {
async function setupRelayAsset(api: ApiPromise, signer: KeyringPair) {
const assetMetadata = {
decimals: 12,
name: "ROC",
Expand All @@ -50,4 +54,4 @@ async function setupRelayAsset(api, signer) {
await submitExtrinsic(signer, sudoCall, {});
}

module.exports = { submitExtrinsic, setupRelayAsset, RELAY_ASSET_ID }
export { submitExtrinsic, setupRelayAsset, RELAY_ASSET_ID }
75 changes: 0 additions & 75 deletions e2e_tests/custom-fee-payment.js

This file was deleted.

52 changes: 0 additions & 52 deletions e2e_tests/delegated-governance.js

This file was deleted.

73 changes: 73 additions & 0 deletions e2e_tests/fee-payment/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { submitExtrinsic, setupRelayAsset, RELAY_ASSET_ID } from "../common";

async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
const { wsUri: regionXUri } = networkInfo.nodesByName[nodeName];
const { wsUri: rococoUri } = networkInfo.nodesByName["rococo-validator01"];

const rococoApi = await ApiPromise.create({ provider: new WsProvider(rococoUri) });
const regionXApi = await ApiPromise.create({
provider: new WsProvider(regionXUri),
signedExtensions: {
ChargeAssetTxPayment: {
extrinsic: {
tip: "Compact<Balance>",
assetId: "Option<AssetId>",
},
payload: {},
},
},
});

// account to submit tx
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");

const setXcmVersion = rococoApi.tx.xcmPallet.forceDefaultXcmVersion([3]);
await submitExtrinsic(alice, rococoApi.tx.sudo.sudo(setXcmVersion), {});

await setupRelayAsset(regionXApi, alice);

const receiverKeypair = new Keyring();
receiverKeypair.addFromAddress(alice.address);

const feeAssetItem = 0;
const weightLimit = "Unlimited";
const reserveTransfer = rococoApi.tx.xcmPallet.limitedReserveTransferAssets(
{ V3: { parents: 0, interior: { X1: { Parachain: 2000 } } } }, //dest
{
V3: {
parents: 0,
interior: {
X1: {
AccountId32: {
chain: "Any",
id: receiverKeypair.pairs[0].publicKey,
},
},
},
},
}, //beneficiary
{
V3: [
{
id: {
Concrete: { parents: 0, interior: "Here" },
},
fun: {
Fungible: 10n ** 9n,
},
},
],
}, //asset
feeAssetItem,
weightLimit
);
await submitExtrinsic(alice, reserveTransfer, {});

// Try to pay for fees with relay chain asset.
const remarkCall = regionXApi.tx.system.remark("0x44");
await submitExtrinsic(alice, remarkCall, { assetId: RELAY_ASSET_ID });
}

export { run };
18 changes: 18 additions & 0 deletions e2e_tests/fee-payment/native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiPromise, Keyring, WsProvider } from "@polkadot/api";
import { submitExtrinsic } from "../common";

async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
const { wsUri } = networkInfo.nodesByName[nodeName];
const api = await ApiPromise.create({ provider: new WsProvider(wsUri) });

// account to submit tx
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");
const bob = keyring.addFromUri("//Bob");

const call = api.tx.balances.transferKeepAlive(bob.address, 10n ** 6n);
const sudo = api.tx.sudo.sudo(call);
await submitExtrinsic(alice, sudo, {});
}

export { run };
52 changes: 52 additions & 0 deletions e2e_tests/governance/delegated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { submitExtrinsic, setupRelayAsset, RELAY_ASSET_ID } from "../common";

const PREIMAGE_HASH = "0xb8375f7ca0c64a384f2dd643a0d520977f3aae06e64afb8c960891eee5147bd1";

async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
const { wsUri } = networkInfo.nodesByName[nodeName];
const api = await ApiPromise.create({
provider: new WsProvider(wsUri),
signedExtensions: {
ChargeAssetTxPayment: {
extrinsic: {
tip: "Compact<Balance>",
assetId: "Option<AssetId>",
},
payload: {},
},
},
});

// account to submit tx
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");
const anna = keyring.addFromUri("//Anna");

await setupRelayAsset(api, alice);

const giveBalanceCall = api.tx.tokens.setBalance(anna.address, RELAY_ASSET_ID, 10n ** 18n, 0);
await submitExtrinsic(alice, api.tx.sudo.sudo(giveBalanceCall), {});

const remarkCallBytes = api.tx.system.remark("hey").toU8a();
await submitExtrinsic(alice, api.tx.preimage.notePreimage(remarkCallBytes), {});

const submitProposal = api.tx.delegatedReferenda.submit(
{ system: "Root" },
{ Lookup: { hash: PREIMAGE_HASH, len: remarkCallBytes.length } },
{ After: 5 }
);
await submitExtrinsic(anna, submitProposal, { assetId: RELAY_ASSET_ID });

const placeDeposit = api.tx.delegatedReferenda.placeDecisionDeposit(0);
await submitExtrinsic(anna, placeDeposit, { assetId: RELAY_ASSET_ID });

const voteCall = api.tx.delegatedConvictionVoting.vote(0, {
// Voting with relay chain tokens. We know this is true; otherwise, this call
// would fail, given that Anna doesn't have 10^16 RegionX tokens.
Standard: { vote: { aye: true, conviction: "None" }, balance: 10n ** 16n },
});
await submitExtrinsic(anna, voteCall, { assetId: RELAY_ASSET_ID });
}

export { run };
35 changes: 35 additions & 0 deletions e2e_tests/governance/native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { submitExtrinsic, setupRelayAsset } from "../common";

const PREIMAGE_HASH = "0x0ccf4369e9a9f88f035828ba0dd5da645d5c0fa7baa86bdc8d7a80c183ab84c9";

async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
const { wsUri } = networkInfo.nodesByName[nodeName];
const api = await ApiPromise.create({ provider: new WsProvider(wsUri) });

// account to submit tx
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");

await setupRelayAsset(api, alice);

const spendCallBytes = api.tx.treasury.spendLocal(10n ** 6n, alice.address).toU8a();
await submitExtrinsic(alice, api.tx.preimage.notePreimage(spendCallBytes), {});

const submitProposal = api.tx.nativeReferenda.submit(
{ Origins: "SmallTipper" },
{ Lookup: { hash: PREIMAGE_HASH, len: spendCallBytes.length } },
{ After: 5 }
);
await submitExtrinsic(alice, submitProposal, {});

const placeDeposit = api.tx.nativeReferenda.placeDecisionDeposit(0);
await submitExtrinsic(alice, placeDeposit, {});

const voteCall = api.tx.nativeConvictionVoting.vote(0, {
Standard: { vote: { aye: true, conviction: "None" }, balance: 10n ** 16n },
});
await submitExtrinsic(alice, voteCall, {});
}

export { run };
18 changes: 0 additions & 18 deletions e2e_tests/native-fee-payment.js

This file was deleted.

Loading

0 comments on commit 4a3c3a8

Please sign in to comment.