Skip to content

Commit

Permalink
all good but unpaid execution?
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed May 7, 2024
1 parent a6870bd commit 7c35a49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion e2e_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@polkadot/api": "^11.0.2",
"@polkadot/keyring": "^12.6.2",
"coretime-utils": "^0.3.0",
"coretime-utils": "^0.3.2",
"typescript": "^5.4.5"
}
}
15 changes: 8 additions & 7 deletions e2e_tests/region-transfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { CONFIG, INITIAL_PRICE, UNIT, CORE_COUNT } from "../consts";
import { submitExtrinsic, sleep, transferRelayAssetToRegionX, setupRelayAsset } from "../common";
import { KeyringPair } from "@polkadot/keyring/types";
import { CoreMask, getEncodedRegionId, Id, RegionId } from "coretime-utils";
import { getEncodedRegionId, Id, RegionId, voidMask } from "coretime-utils";
import assert from 'node:assert';

async function run(_nodeName: any, networkInfo: any, _jsArgs: any) {
Expand Down Expand Up @@ -33,6 +33,7 @@ async function run(_nodeName: any, networkInfo: any, _jsArgs: any) {
await submitExtrinsic(alice, coretimeApi.tx.sudo.sudo(setBalanceCall), {});

const regionId = await purchaseRegion(coretimeApi, alice);
if(!regionId) throw new Error("RegionId not found");

const receiverKeypair = new Keyring();
receiverKeypair.addFromAddress(alice.address);
Expand Down Expand Up @@ -81,7 +82,7 @@ async function run(_nodeName: any, networkInfo: any, _jsArgs: any) {

const regions = (await regionXApi.query.regions.regions.entries());
assert.equal(regions.length, 1);
assert.deepStrictEqual(regions[0][0].toHuman(), [{ begin: '34', core: '0', mask: "0xffffffffffffffffffff" }]);
assert.deepStrictEqual(regions[0][0].toHuman(), [regionId]);
assert.deepStrictEqual(regions[0][1].toHuman(), { owner: alice.address, record: 'Pending' });

const reserveTransferToCoretime = regionXApi.tx.polkadotXcm.limitedReserveTransferAssets(
Expand Down Expand Up @@ -168,8 +169,8 @@ async function startSales(coretimeApi: ApiPromise, signer: KeyringPair): Promise
return submitExtrinsic(signer, sudo, {});
}

async function purchaseRegion(coretimeApi: ApiPromise, buyer: KeyringPair): Promise<RegionId> {
const callTx = async (resolve: (regionId: RegionId) => void) => {
async function purchaseRegion(coretimeApi: ApiPromise, buyer: KeyringPair): Promise<RegionId | null> {
const callTx = async (resolve: (regionId: RegionId | null) => void) => {
const purchase = coretimeApi.tx.broker.purchase(INITIAL_PRICE * 2);
const unsub = await purchase.signAndSend(buyer, async (result: any) => {
if (result.status.isInBlock) {
Expand All @@ -183,18 +184,18 @@ async function purchaseRegion(coretimeApi: ApiPromise, buyer: KeyringPair): Prom
return new Promise(callTx);
}

async function getRegionId(coretimeApi: ApiPromise): Promise<RegionId> {
async function getRegionId(coretimeApi: ApiPromise): Promise<RegionId | null> {
const events: any = await coretimeApi.query.system.events();

for (const record of events) {
const { event } = record;
if (event.section === "broker" && event.method === "Purchased") {
const data = event.data[1].toHuman();
return { begin: data.begin, core: data.core, mask: new CoreMask(data.mask) }
return data;
}
}

return { begin: 0, core: 0, mask: CoreMask.voidMask() };
return null;
}

export { run };

0 comments on commit 7c35a49

Please sign in to comment.