Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Feb 5, 2024
1 parent 66443e9 commit 53b3cc4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ export async function balanceOf(api: ApiPromise, acc: string): Promise<number> {
return parseHNString(account.data.free);
}

export async function getBlockNumber(api: ApiPromise): Promise<number> {
const num = (await api.query.system.number()).toHuman();
return parseHNString(num.toString());
}

export function parseHNString(str: string): number {
return parseInt(str.replace(/,/g, ''));
}
Expand Down
9 changes: 5 additions & 4 deletions tests/market/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use(chaiAsPromised);

const REGION_COLLECTION_ID = 42;
const LISTING_DEPOIST = 100;
// Set to only one relay
const TIMIESLICE_PERIOD = 80;
// In reality this is 80, however we use 8 for testing.
const TIMESLICE_PERIOD = 8;

const wsProvider = new WsProvider('ws://127.0.0.1:9944');
// Create a keyring instance
Expand All @@ -47,7 +47,7 @@ describe('Coretime market listing', () => {

const marketFactory = new Market_Factory(api, alice);
market = new Market(
(await marketFactory.new(xcRegions.address, LISTING_DEPOIST)).address,
(await marketFactory.new(xcRegions.address, LISTING_DEPOIST, TIMESLICE_PERIOD)).address,
alice,
api,
);
Expand Down Expand Up @@ -178,7 +178,8 @@ describe('Coretime market listing', () => {
const id: any = api.createType('Id', { U128: region.getEncodedRegionId(api) });
await xcRegions.withSigner(alice).tx.approve(market.address, id, true);

await wait(6000);
// Wait for the region to expire.
await wait(2000 * TIMESLICE_PERIOD);

const timeslicePrice = 50;
const result = await market
Expand Down
4 changes: 3 additions & 1 deletion tests/market/purchase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use(chaiAsPromised);

const REGION_COLLECTION_ID = 42;
const LISTING_DEPOIST = 0;
// In reality this is 80, however we use 8 for testing.
const TIMESLICE_PERIOD = 8;

const wsProvider = new WsProvider('ws://127.0.0.1:9944');
// Create a keyring instance
Expand All @@ -48,7 +50,7 @@ describe('Coretime market purchases', () => {

const marketFactory = new Market_Factory(api, alice);
market = new Market(
(await marketFactory.new(xcRegions.address, LISTING_DEPOIST)).address,
(await marketFactory.new(xcRegions.address, LISTING_DEPOIST, TIMESLICE_PERIOD)).address,
alice,
api,
);
Expand Down
15 changes: 8 additions & 7 deletions tests/market/unlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createRegionCollection,
expectEvent,
expectOnSale,
getBlockNumber,
initRegion,
mintRegion,
wait,
Expand All @@ -23,6 +24,8 @@ use(chaiAsPromised);

const REGION_COLLECTION_ID = 42;
const LISTING_DEPOIST = 5 * Math.pow(10, 15);
// In reality this is 80, however we use 8 for testing.
const TIMESLICE_PERIOD = 8;

const wsProvider = new WsProvider('ws://127.0.0.1:9944');
// Create a keyring instance
Expand All @@ -47,7 +50,7 @@ describe('Coretime market unlisting', () => {

const marketFactory = new Market_Factory(api, alice);
market = new Market(
(await marketFactory.new(xcRegions.address, LISTING_DEPOIST)).address,
(await marketFactory.new(xcRegions.address, LISTING_DEPOIST, TIMESLICE_PERIOD)).address,
alice,
api,
);
Expand Down Expand Up @@ -182,7 +185,7 @@ describe('Coretime market unlisting', () => {
mask: CoreMask.completeMask(),
};
const regionRecord: RegionRecord = {
end: 1,
end: 5,
owner: alice.address,
paid: null,
};
Expand All @@ -203,9 +206,9 @@ describe('Coretime market unlisting', () => {

await expectOnSale(market, id, alice, timeslicePrice);
expect((await xcRegions.query.ownerOf(id)).value.unwrap()).to.deep.equal(market.address);
/*

const bobBalance = await balanceOf(api, bob.address);
// Wait for the region to expire.
await wait(2000 * region.getEnd() * TIMESLICE_PERIOD);

const result = await market.withSigner(bob).tx.unlistRegion(id);
expectEvent(result, 'RegionUnlisted', {
Expand All @@ -220,8 +223,6 @@ describe('Coretime market unlisting', () => {
// Alice receives the region back:
expect((await xcRegions.query.ownerOf(id)).value.unwrap()).to.be.equal(alice.address);

// Bob receives the listing deposit:
expect(await balanceOf(api, bob.address)).to.be.eq(bobBalance + LISTING_DEPOIST);
*/
// TODO: should ideally ensure that bob received the reward.
});
});

0 comments on commit 53b3cc4

Please sign in to comment.