Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor chai usage in tests #2041

Merged
merged 3 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { use, should } from 'chai';
import { use } from 'chai';
import chaiAsPromised from 'chai-as-promised';

use(chaiAsPromised);
should();
8 changes: 4 additions & 4 deletions test/integration/AeSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ describe('AeSdk', () => {
const aeSdk = await getSdk(0);
aeSdk._options._expectedMineRate = 1000;
aeSdk._options._microBlockCycle = 300;
expect(await aeSdk._getPollInterval('key-block')).to.be.equal(333);
expect(await aeSdk._getPollInterval('micro-block')).to.be.equal(100);
expect(await aeSdk._getPollInterval('key-block')).to.equal(333);
expect(await aeSdk._getPollInterval('micro-block')).to.equal(100);
});

it('returns correct value', async () => {
const aeSdk = await getSdk(0);
delete aeSdk._options._expectedMineRate;
delete aeSdk._options._microBlockCycle;
const [kb, mb] = networkId === 'ae_dev' ? [0, 0] : [60000, 1000];
expect(await aeSdk._getPollInterval('key-block')).to.be.equal(kb);
expect(await aeSdk._getPollInterval('micro-block')).to.be.equal(mb);
expect(await aeSdk._getPollInterval('key-block')).to.equal(kb);
expect(await aeSdk._getPollInterval('micro-block')).to.equal(mb);
});
});
});
4 changes: 2 additions & 2 deletions test/integration/AeSdkMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ describe('AeSdkMethods', () => {
contract Identity =
entrypoint getArg(x : int) = x`,
});
expect(contract.$options.onAccount?.address).to.be.eql(accounts[0].address);
expect(contract.$options.onAccount?.address).to.eql(accounts[0].address);
[, aeSdkMethods._options.onAccount] = accounts;
expect(contract.$options.onAccount?.address).to.be.eql(accounts[1].address);
expect(contract.$options.onAccount?.address).to.eql(accounts[1].address);
});

it('converts context to JSON', () => {
Expand Down
74 changes: 37 additions & 37 deletions test/integration/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function copyFields(
fields
.filter((key) => source[key] != null)
.forEach((key) => {
expect(typeof target[key]).to.be.equal(typeof source[key]);
expect(target[key]?.constructor).to.be.equal(source[key]?.constructor);
expect(typeof target[key]).to.equal(typeof source[key]);
expect(target[key]?.constructor).to.equal(source[key]?.constructor);
if (typeof target[key] === 'string' && target[key][2] === '_') {
expect(target[key].slice(0, 2)).to.be.equal(source[key].slice(0, 2));
expect(target[key].slice(0, 2)).to.equal(source[key].slice(0, 2));
}
target[key] = source[key];
});
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Middleware API', () => {
nodeSyncing: false,
nodeVersion: '7.1.0',
};
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

describe('blocks', () => {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Middleware API', () => {
);
expectedRes.data.unshift(...res.data.slice(0, -1));
expect(res.data[0].time.getFullYear()).to.be.within(2024, 2030);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets micro block', async () => {
Expand All @@ -122,7 +122,7 @@ describe('Middleware API', () => {
txsHash: 'bx_2i471KqJ5XTLVQJS4x95FyLuwbAcj4SetvemPUs4oV47S9dFb3',
};
copyFields(expectedRes, res, ['time', 'hash', 'prevHash', 'prevKeyHash', 'signature']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand Down Expand Up @@ -293,7 +293,7 @@ describe('Middleware API', () => {
copyFields(item, res.data[idx], ['blockHash', 'blockTime']);
copyFields(item.payload, res.data[idx].payload, ['blockHash', 'microTime']);
});
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets transactions', async () => {
Expand Down Expand Up @@ -335,13 +335,13 @@ describe('Middleware API', () => {
res.data.length = 0;
res.data.push(tx);
copyFields(expectedRes.data[0], res.data[0], ['blockHash', 'microTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets transactions count', async () => {
const res = await middleware.getTransactionsCount();
const expectedRes: typeof res = { body: 10 };
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets transfers', async () => {
Expand All @@ -366,7 +366,7 @@ describe('Middleware API', () => {
);
expectedRes.data.push(...res.data.slice(1));
copyFields(expectedRes.data[0], res.data[0], ['refTxType']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand Down Expand Up @@ -403,7 +403,7 @@ describe('Middleware API', () => {
middleware,
);
copyFields(expectedRes.data[0], res.data[0], ['blockHash']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets contract logs', async () => {
Expand Down Expand Up @@ -435,7 +435,7 @@ describe('Middleware API', () => {
middleware,
);
copyFields(expectedRes.data[0], res.data[0], ['blockHash', 'blockTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets contract', async () => {
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('Middleware API', () => {
sourceTxType: 'ContractCreateTx',
};
copyFields(expectedRes, res, ['blockHash']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand Down Expand Up @@ -507,13 +507,13 @@ describe('Middleware API', () => {
'approximateExpireTime',
'expireHeight',
]);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets names count', async () => {
const res = await middleware.getNamesCount();
const expectedRes: typeof res = { body: 2 };
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets name claims', async () => {
Expand Down Expand Up @@ -545,7 +545,7 @@ describe('Middleware API', () => {
middleware,
);
copyFields(expectedRes.data[0], res.data[0], ['blockHash']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets name updates', async () => {
Expand Down Expand Up @@ -589,7 +589,7 @@ describe('Middleware API', () => {
middleware,
);
copyFields(expectedRes.data[0], res.data[0], ['blockHash']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets account pointees pointers', async () => {
Expand Down Expand Up @@ -635,7 +635,7 @@ describe('Middleware API', () => {
middleware,
);
copyFields(expectedRes.data[0], res.data[0], ['blockHash', 'blockTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets auctions', async () => {
Expand Down Expand Up @@ -686,7 +686,7 @@ describe('Middleware API', () => {
'auctionEnd',
]);
copyFields(expectedRes.data[0].lastBid, res.data[0].lastBid, ['blockHash', 'microTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand Down Expand Up @@ -748,7 +748,7 @@ describe('Middleware API', () => {
);
copyFields(expectedRes.data[0].register, res.data[0].register, ['blockHash', 'microTime']);
copyFields(expectedRes.data[0], res.data[0], ['registerTime', 'approximateExpireTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets oracle', async () => {
Expand All @@ -771,7 +771,7 @@ describe('Middleware API', () => {
registerTxHash: 'th_299u2zPGuFDJPpmYM6ZpRaAiCnRViGwW4aph12Hz9Qr1Cc7tPP',
};
copyFields(expectedRes, res, ['registerTime', 'approximateExpireTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand Down Expand Up @@ -812,7 +812,7 @@ describe('Middleware API', () => {
middleware,
);
copyFields(expectedRes.data[0], res.data[0], ['lastUpdatedTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets channel', async () => {
Expand Down Expand Up @@ -843,7 +843,7 @@ describe('Middleware API', () => {
updatesCount: 1,
};
copyFields(expectedRes, res, ['lastUpdatedTime']);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand Down Expand Up @@ -881,7 +881,7 @@ describe('Middleware API', () => {
middleware,
);
expectedRes.data.push(...res.data.slice(1));
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets total', async () => {
Expand Down Expand Up @@ -913,7 +913,7 @@ describe('Middleware API', () => {
middleware,
);
expectedRes.data.push(...res.data.slice(1));
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets miner', async () => {
Expand All @@ -922,7 +922,7 @@ describe('Middleware API', () => {
{ data: [], next: null, prev: null },
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets blocks', async () => {
Expand All @@ -935,7 +935,7 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets transactions', async () => {
Expand All @@ -948,7 +948,7 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets names', async () => {
Expand All @@ -961,7 +961,7 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand All @@ -976,15 +976,15 @@ describe('Middleware API', () => {
it('gets not paginated data', async () => {
const res = await middleware.requestByPath('/v3/status');
const expectedRes: typeof res = await middleware.getStatus();
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets first page', async () => {
const res = await middleware.requestByPath<MiddlewarePage<Activity>>(
`/v3/accounts/${presetAccount1Address}/activities`,
);
const expectedRes: typeof res = await middleware.getAccountActivities(presetAccount1Address);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets first page with query parameters', async () => {
Expand All @@ -999,7 +999,7 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('gets second page', async () => {
Expand All @@ -1014,7 +1014,7 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});
});

Expand All @@ -1030,15 +1030,15 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('nevigates to the previous page', async () => {
const first = await middleware.getTransactions({ limit: 1 });
const second = await first.next();
const res = await second.prev();
expect(res).to.be.eql(first);
expect(res.prevPath).to.be.eql(null);
expect(res).to.eql(first);
expect(res.prevPath).to.eql(null);
const expectedRes: typeof res = new MiddlewarePage(
{
data: (await middleware.getTransactions()).data.slice(0, 1),
Expand All @@ -1047,7 +1047,7 @@ describe('Middleware API', () => {
},
middleware,
);
expect(res).to.be.eql(expectedRes);
expect(res).to.eql(expectedRes);
});

it('fails to navigate out of page range', async () => {
Expand Down
Loading