Skip to content

Commit

Permalink
tests: small change - helper.getApi() instead of helper.api!
Browse files Browse the repository at this point in the history
  • Loading branch information
uandysmith authored and Grigoriy Simonov committed Oct 9, 2023
1 parent afc8657 commit 742522c
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 181 deletions.
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
"@openzeppelin/contracts": "^4.9.2",
"@polkadot/api": "10.9.1",
"@polkadot/rpc-core": "^10.9.1",
"@polkadot/types": "^10.9.1",
"@polkadot/types-codec": "^10.9.1",
"@polkadot/util": "12.5.1",
"@polkadot/util-crypto": "12.5.1",
"@polkadot/wasm-crypto-asmjs": "^7.2.1",
Expand Down
6 changes: 3 additions & 3 deletions tests/src/collator-selection/identity.seqtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Integration Test: Identities Manipulation', () => {
const oldIdentities = await getIdentityAccounts(helper);

// delete a couple, check that they are no longer there
const registry = helper.api!.registry;
const registry = helper.getApi().registry;
const scapegoats: AccountId32[] = [new GenericAccountId(registry, crowd.pop()!.address), new GenericAccountId(registry, crowd.pop()!.address)];
await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [scapegoats]);
const newIdentities = await getIdentityAccounts(helper);
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('Integration Test: Identities Manipulation', () => {
]);
await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo] as any);

const registry = helper.api!.registry;
const registry = helper.getApi().registry;
for(let i = 0; i < supers.length; i++) {
// check deposit
expect((await helper.getApi().query.identity.subsOf(supers[i].address))[0].toNumber()).to.be.equal(1000001 + i);
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('Integration Test: Identities Manipulation', () => {
await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2] as any);

// make sure everything else is the same
const registry = helper.api!.registry;
const registry = helper.getApi().registry;
for(let i = 0; i < supers.length - 1; i++) {
// check deposit
expect((await helper.getApi().query.identity.subsOf(supers[i].address))[0].toNumber()).to.be.eq(1000001 + i);
Expand Down
4 changes: 2 additions & 2 deletions tests/src/createItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ describe('integration test: ext. ():', () => {
{
const createData = {fungible: {value: 100}};
const events = await helper.executeExtrinsic(alice, 'api.tx.unique.createItem', [collectionId, to, createData as any]);
const result = helper.util.extractTokensFromCreationResult(helper.api!, events);
const result = helper.util.extractTokensFromCreationResult(helper.getApi(), events);
expect(result.tokens[0].amount).to.be.equal(100n);
expect(result.tokens[0].collectionId).to.be.equal(collectionId);
expect(result.tokens[0].owner).to.be.deep.equal(to);
}
{
const createData = {fungible: {value: 50}};
const events = await helper.executeExtrinsic(alice, 'api.tx.unique.createItem', [collectionId, to, createData as any]);
const result = helper.util.extractTokensFromCreationResult(helper.api!, events);
const result = helper.util.extractTokensFromCreationResult(helper.getApi(), events);
expect(result.tokens[0].amount).to.be.equal(50n);
expect(result.tokens[0].collectionId).to.be.equal(collectionId);
expect(result.tokens[0].owner).to.be.deep.equal(to);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/eth/nativeFungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('NativeFungible: ERC20 calls', () => {
const collectionAddress = helper.ethAddress.fromCollectionId(0);
const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);

await expect(contract.methods.approve(spender, 100).call({from: owner})).to.be.rejectedWith('Approve not supported');
await expect(contract.methods.approve(spender, 100).call({from: owner})).to.be.rejectedWith('approve not supported');
});

itEth('balanceOf()', async ({helper}) => {
Expand Down
30 changes: 15 additions & 15 deletions tests/src/governance/council.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = proposeResult.result.events.find(helper.api!.events.council.Proposed.is);
const councilProposedEvent = proposeResult.result.events.find(helper.getApi().events.council.Proposed.is);
if(!councilProposedEvent)
throw Error('Expected event council.Proposed');
const proposalIndex = councilProposedEvent.data.proposalIndex.toNumber();
Expand All @@ -61,7 +61,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = proposeResult.result.events.find(helper.api!.events.council.Proposed.is);
const councilProposedEvent = proposeResult.result.events.find(helper.getApi().events.council.Proposed.is);
if(!councilProposedEvent)
throw Error('Expected event council.Proposed');
const proposalIndex = councilProposedEvent.data.proposalIndex.toNumber();
Expand Down Expand Up @@ -94,7 +94,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = proposeResult.result.events.find(helper.api!.events.council.Proposed.is);
const councilProposedEvent = proposeResult.result.events.find(helper.getApi().events.council.Proposed.is);
if(!councilProposedEvent)
throw Error('Expected event council.Proposed');
const proposalIndex = councilProposedEvent.data.proposalIndex.toNumber();
Expand All @@ -106,7 +106,7 @@ describeGov('Governance: Council tests', () => {

await helper.council.collective.close(counselors.filip, proposalHash, proposalIndex);

const democracyStartedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.api!.events.democracy.Started);
const democracyStartedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.getApi().events.democracy.Started);
const democracyReferendumIndex = democracyStartedEvent.refIndex.toNumber();
const democracyThreshold = democracyStartedEvent.threshold;

Expand All @@ -132,10 +132,10 @@ describeGov('Governance: Council tests', () => {
},
});

const passedReferendumEvent = await helper.wait.expectEvent(democracyVotingPeriod, helper.api!.events.democracy.Passed);
const passedReferendumEvent = await helper.wait.expectEvent(democracyVotingPeriod, helper.getApi().events.democracy.Passed);
expect(passedReferendumEvent.refIndex.toNumber()).to.be.equal(democracyReferendumIndex);

await helper.wait.expectEvent(democracyEnactmentPeriod, helper.api!.events.scheduler.Dispatched);
await helper.wait.expectEvent(democracyEnactmentPeriod, helper.getApi().events.scheduler.Dispatched);
const receiverBalance = await helper.balance.getSubstrate(forceSetBalanceReceiver.address);
expect(receiverBalance).to.be.equal(forceSetBalanceTestValue);
});
Expand All @@ -149,7 +149,7 @@ describeGov('Governance: Council tests', () => {
moreThanHalfCouncilThreshold,
);

const councilProposedEvent = proposeResult.result.events.find(helper.api!.events.council.Proposed.is);
const councilProposedEvent = proposeResult.result.events.find(helper.getApi().events.council.Proposed.is);
if(!councilProposedEvent)
throw Error('Expected event council.Proposed');
const proposalIndex = councilProposedEvent.data.proposalIndex.toNumber();
Expand All @@ -159,7 +159,7 @@ describeGov('Governance: Council tests', () => {

await helper.wait.newBlocks(councilMotionDuration);
const closeResult = await helper.council.collective.close(counselors.filip, proposalHash, proposalIndex);
const closeEvent = closeResult.result.events.find(helper.api!.events.council.Closed.is);
const closeEvent = closeResult.result.events.find(helper.getApi().events.council.Closed.is);
if(!closeEvent)
throw Error('Expected event council.Closed');
const members = await helper.callQuery('api.query.councilMembership.members');
Expand Down Expand Up @@ -371,7 +371,7 @@ describeGov('Governance: Council tests', () => {

itSub('[Negative] Council cannot cancel Democracy proposals', async ({helper}) => {
const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposedEvent = proposeResult.result.events.find(helper.api!.events.democracy.Proposed.is);
const proposedEvent = proposeResult.result.events.find(helper.getApi().events.democracy.Proposed.is);
if(!proposedEvent)
throw Error('Expected event democracy.Proposed');
const proposalIndex = proposedEvent.data.proposalIndex.toNumber();
Expand All @@ -383,7 +383,7 @@ describeGov('Governance: Council tests', () => {
itSub('[Negative] Council member cannot cancel Democracy proposals', async ({helper}) => {

const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);
const proposedEvent = proposeResult.result.events.find(helper.api!.events.democracy.Proposed.is);
const proposedEvent = proposeResult.result.events.find(helper.getApi().events.democracy.Proposed.is);
if(!proposedEvent)
throw Error('Expected event democracy.Proposed');
const proposalIndex = proposedEvent.data.proposalIndex.toNumber();
Expand All @@ -396,7 +396,7 @@ describeGov('Governance: Council tests', () => {

itSub('[Negative] Council cannot cancel ongoing Democracy referendums', async ({helper}) => {
await helper.getSudo().democracy.externalProposeDefault(sudoer, dummyProposalCall(helper));
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.api!.events.democracy.Started);
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.getApi().events.democracy.Started);
const referendumIndex = startedEvent.refIndex.toNumber();

await expect(proposalFromAllCouncil(helper.democracy.emergencyCancelCall(referendumIndex)))
Expand All @@ -405,7 +405,7 @@ describeGov('Governance: Council tests', () => {

itSub('[Negative] Council member cannot cancel ongoing Democracy referendums', async ({helper}) => {
await helper.getSudo().democracy.externalProposeDefault(sudoer, dummyProposalCall(helper));
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.api!.events.democracy.Started);
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.getApi().events.democracy.Started);
const referendumIndex = startedEvent.refIndex.toNumber();

await expect(helper.council.collective.execute(
Expand All @@ -426,7 +426,7 @@ describeGov('Governance: Council tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand All @@ -447,7 +447,7 @@ describeGov('Governance: Council tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand All @@ -467,7 +467,7 @@ describeGov('Governance: Council tests', () => {
councilSize,
);

const councilProposedEvent = proposeResult.result.events.find(helper.api!.events.council.Proposed.is);
const councilProposedEvent = proposeResult.result.events.find(helper.getApi().events.council.Proposed.is);
if(!councilProposedEvent)
throw Error('Expected event council.Proposed');
const proposalIndex = councilProposedEvent.data.proposalIndex.toNumber();
Expand Down
6 changes: 3 additions & 3 deletions tests/src/governance/democracy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describeGov('Governance: Democracy tests', () => {
{After: 0},
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event council.Proposed');
const fellowshipReferendumIndex = submittedEvent.data.index.toNumber();
Expand All @@ -44,10 +44,10 @@ describeGov('Governance: Democracy tests', () => {

await helper.wait.expectEvent(
fellowshipPreparePeriod + fellowshipConfirmPeriod + fellowshipMinEnactPeriod,
helper.api!.events.democracy.Proposed,
helper.getApi().events.democracy.Proposed,
);

const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.api!.events.democracy.Started);
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.getApi().events.democracy.Started);
const referendumIndex = startedEvent.refIndex.toNumber();

const ayeBalance = 10_000n;
Expand Down
20 changes: 10 additions & 10 deletions tests/src/governance/fellowship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand All @@ -40,7 +40,7 @@ describeGov('Governance: Fellowship tests', () => {
const enactmentId = await helper.fellowship.referenda.enactmentEventId(referendumIndex);
const dispatchedEvent = await helper.wait.expectEvent(
fellowshipPreparePeriod + fellowshipConfirmPeriod + defaultEnactmentMoment.After,
helper.api!.events.scheduler.Dispatched,
helper.getApi().events.scheduler.Dispatched,
(event: any) => event.id == enactmentId,
);

Expand Down Expand Up @@ -88,7 +88,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const fellowshipReferendumIndex = submittedEvent.data.index.toNumber();
Expand All @@ -98,7 +98,7 @@ describeGov('Governance: Fellowship tests', () => {

const democracyProposed = await helper.wait.expectEvent(
fellowshipPreparePeriod + fellowshipConfirmPeriod + fellowshipMinEnactPeriod,
helper.api!.events.democracy.Proposed,
helper.getApi().events.democracy.Proposed,
);

const democracyEnqueuedProposal = await helper.democracy.expectPublicProposal(democracyProposed.proposalIndex.toNumber());
Expand All @@ -122,7 +122,7 @@ describeGov('Governance: Fellowship tests', () => {
newDummyProposal,
defaultEnactmentMoment,
);
const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand All @@ -144,7 +144,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand Down Expand Up @@ -184,7 +184,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand Down Expand Up @@ -269,7 +269,7 @@ describeGov('Governance: Fellowship tests', () => {
defaultEnactmentMoment,
);

const submittedEvent = submitResult.result.events.find(helper.api!.events.fellowshipReferenda.Submitted.is);
const submittedEvent = submitResult.result.events.find(helper.getApi().events.fellowshipReferenda.Submitted.is);
if(!submittedEvent)
throw Error('Expected event fellowshipReferenda.Submitted');
const referendumIndex = submittedEvent.data.index.toNumber();
Expand Down Expand Up @@ -324,7 +324,7 @@ describeGov('Governance: Fellowship tests', () => {
itSub('[Negative] FellowshipProposition cannot cancel Democracy proposals', async ({helper}) => {
const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n);

const proposedEvent = proposeResult.result.events.find(helper.api!.events.democracy.Proposed.is);
const proposedEvent = proposeResult.result.events.find(helper.getApi().events.democracy.Proposed.is);
if(!proposedEvent)
throw Error('Expected event democracy.Proposed');
const proposalIndex = proposedEvent.data.proposalIndex.toNumber();
Expand All @@ -334,7 +334,7 @@ describeGov('Governance: Fellowship tests', () => {

itSub('[Negative] FellowshipProposition cannot cancel ongoing Democracy referendums', async ({helper}) => {
await helper.getSudo().democracy.externalProposeDefault(sudoer, dummyProposalCall(helper));
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.api!.events.democracy.Started);
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.getApi().events.democracy.Started);
const referendumIndex = startedEvent.refIndex.toNumber();

await testBadFellowshipProposal(helper, helper.democracy.emergencyCancelCall(referendumIndex));
Expand Down
6 changes: 3 additions & 3 deletions tests/src/governance/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describeGov('Governance: Initialization', () => {
);

console.log('\t- The referendum is being decided');
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.api!.events.democracy.Started);
const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, helper.getApi().events.democracy.Started);

await helper.democracy.vote(counselors.filip, startedEvent.refIndex.toNumber(), {
Standard: {
Expand All @@ -155,10 +155,10 @@ describeGov('Governance: Initialization', () => {
},
});

const passedReferendumEvent = await helper.wait.expectEvent(democracyVotingPeriod, helper.api!.events.democracy.Passed);
const passedReferendumEvent = await helper.wait.expectEvent(democracyVotingPeriod, helper.getApi().events.democracy.Passed);
expect(passedReferendumEvent.refIndex.toNumber()).to.be.equal(startedEvent.refIndex.toNumber());

await helper.wait.expectEvent(democracyEnactmentPeriod, helper.api!.events.scheduler.Dispatched);
await helper.wait.expectEvent(democracyEnactmentPeriod, helper.getApi().events.scheduler.Dispatched);

councilMembers = await helper.council.membership.getMembers();
const expectedCounselors = [
Expand Down
Loading

0 comments on commit 742522c

Please sign in to comment.