diff --git a/tests/package.json b/tests/package.json index 9bfcfc66e1..263d87f101 100644 --- a/tests/package.json +++ b/tests/package.json @@ -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", diff --git a/tests/src/collator-selection/identity.seqtest.ts b/tests/src/collator-selection/identity.seqtest.ts index c7d4602e6f..03ae68888b 100644 --- a/tests/src/collator-selection/identity.seqtest.ts +++ b/tests/src/collator-selection/identity.seqtest.ts @@ -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); @@ -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); @@ -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); diff --git a/tests/src/createItem.test.ts b/tests/src/createItem.test.ts index 2be3b4a614..fd8a22e28e 100644 --- a/tests/src/createItem.test.ts +++ b/tests/src/createItem.test.ts @@ -69,7 +69,7 @@ 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); @@ -77,7 +77,7 @@ describe('integration test: ext. ():', () => { { 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); diff --git a/tests/src/eth/nativeFungible.test.ts b/tests/src/eth/nativeFungible.test.ts index ea8047bcc8..5883d6db21 100644 --- a/tests/src/eth/nativeFungible.test.ts +++ b/tests/src/eth/nativeFungible.test.ts @@ -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}) => { diff --git a/tests/src/governance/council.test.ts b/tests/src/governance/council.test.ts index a3ff715706..d715488e6e 100644 --- a/tests/src/governance/council.test.ts +++ b/tests/src/governance/council.test.ts @@ -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(); @@ -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(); @@ -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(); @@ -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; @@ -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); }); @@ -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(); @@ -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'); @@ -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(); @@ -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(); @@ -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))) @@ -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( @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/src/governance/democracy.test.ts b/tests/src/governance/democracy.test.ts index 3fd2498300..5ceb03020f 100644 --- a/tests/src/governance/democracy.test.ts +++ b/tests/src/governance/democracy.test.ts @@ -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(); @@ -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; diff --git a/tests/src/governance/fellowship.test.ts b/tests/src/governance/fellowship.test.ts index cfd9d954c8..3fb8c45a05 100644 --- a/tests/src/governance/fellowship.test.ts +++ b/tests/src/governance/fellowship.test.ts @@ -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(); @@ -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, ); @@ -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(); @@ -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()); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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)); diff --git a/tests/src/governance/init.test.ts b/tests/src/governance/init.test.ts index eedf404d80..56d7fc27cf 100644 --- a/tests/src/governance/init.test.ts +++ b/tests/src/governance/init.test.ts @@ -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: { @@ -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 = [ diff --git a/tests/src/governance/technicalCommittee.test.ts b/tests/src/governance/technicalCommittee.test.ts index 8ab3418539..35b0dc2385 100644 --- a/tests/src/governance/technicalCommittee.test.ts +++ b/tests/src/governance/technicalCommittee.test.ts @@ -45,7 +45,7 @@ describeGov('Governance: Technical Committee tests', () => { allTechCommitteeThreshold, ); - const commiteeProposedEvent = Event.expect(proposeResult, helper.api!.events.technicalCommittee.Proposed); + const commiteeProposedEvent = Event.expect(proposeResult, helper.getApi().events.technicalCommittee.Proposed); const proposalIndex = commiteeProposedEvent.data.proposalIndex.toNumber(); const proposalHash = commiteeProposedEvent.data.proposalHash.toHex(); @@ -55,9 +55,9 @@ describeGov('Governance: Technical Committee tests', () => { await helper.technicalCommittee.collective.vote(techcomms.greg, proposalHash, proposalIndex, true); const closeResult = await helper.technicalCommittee.collective.close(techcomms.andy, proposalHash, proposalIndex); - Event.expect(closeResult, helper.api!.events.technicalCommittee.Closed); - Event.expect(closeResult, helper.api!.events.technicalCommittee.Approved); - const result = Event.expect(closeResult, helper.api!.events.technicalCommittee.Executed).data.result; + Event.expect(closeResult, helper.getApi().events.technicalCommittee.Closed); + Event.expect(closeResult, helper.getApi().events.technicalCommittee.Approved); + const result = Event.expect(closeResult, helper.getApi().events.technicalCommittee.Executed).data.result; expect(result.isOk).to.be.true; return closeResult; @@ -71,24 +71,24 @@ describeGov('Governance: Technical Committee tests', () => { await helper.getSudo().democracy.externalProposeDefaultWithPreimage(sudoer, preimageHash); const fastTrackProposal = await proposalFromAllCommittee(helper.democracy.fastTrackCall(preimageHash, democracyFastTrackVotingPeriod, 0)); - Event.expect(fastTrackProposal, helper.api!.events.democracy.Started); + Event.expect(fastTrackProposal, helper.getApi().events.democracy.Started); }); itSub('TechComm can cancel Democracy proposals', async ({helper}) => { const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n); - const proposalIndex = Event.expect(proposeResult, helper.api!.events.democracy.Proposed).data.proposalIndex.toNumber(); + const proposalIndex = Event.expect(proposeResult, helper.getApi().events.democracy.Proposed).data.proposalIndex.toNumber(); const cancelProposal = await proposalFromAllCommittee(helper.democracy.cancelProposalCall(proposalIndex)); - Event.expect(cancelProposal, helper.api!.events.democracy.ProposalCanceled); + Event.expect(cancelProposal, helper.getApi().events.democracy.ProposalCanceled); }); itSub('TechComm can 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(); const emergencyCancelProposal = await proposalFromAllCommittee(helper.democracy.emergencyCancelCall(referendumIndex)); - Event.expect(emergencyCancelProposal, helper.api!.events.democracy.Cancelled); + Event.expect(emergencyCancelProposal, helper.getApi().events.democracy.Cancelled); }); itSub('TechComm member can veto Democracy proposals', async ({helper}) => { @@ -99,7 +99,7 @@ describeGov('Governance: Technical Committee tests', () => { techcomms.andy, helper.democracy.vetoExternalCall(preimageHash), ); - Event.expect(vetoExternalCall, helper.api!.events.democracy.Vetoed); + Event.expect(vetoExternalCall, helper.getApi().events.democracy.Vetoed); }); itSub('TechComm can cancel Fellowship referendums', async ({helper}) => { @@ -113,9 +113,9 @@ describeGov('Governance: Technical Committee tests', () => { proposal, defaultEnactmentMoment, ); - const referendumIndex = Event.expect(submitResult, helper.api!.events.fellowshipReferenda.Submitted).data.index.toNumber(); + const referendumIndex = Event.expect(submitResult, helper.getApi().events.fellowshipReferenda.Submitted).data.index.toNumber(); const cancelProposal = await proposalFromAllCommittee(helper.fellowship.referenda.cancelCall(referendumIndex)); - Event.expect(cancelProposal, helper.api!.events.fellowshipReferenda.Cancelled); + Event.expect(cancelProposal, helper.getApi().events.fellowshipReferenda.Cancelled); }); itSub.skip('TechComm member can add a Fellowship member', async ({helper}) => { @@ -301,7 +301,7 @@ describeGov('Governance: Technical Committee tests', () => { itSub('[Negative] TechComm member cannot cancel Democracy proposals', async ({helper}) => { const proposeResult = await helper.getSudo().democracy.propose(sudoer, dummyProposalCall(helper), 0n); - const proposalIndex = Event.expect(proposeResult, helper.api!.events.democracy.Proposed).data.proposalIndex.toNumber(); + const proposalIndex = Event.expect(proposeResult, helper.getApi().events.democracy.Proposed).data.proposalIndex.toNumber(); await expect(helper.technicalCommittee.collective.execute( techcomms.andy, @@ -312,7 +312,7 @@ describeGov('Governance: Technical Committee tests', () => { itSub('[Negative] TechComm 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.technicalCommittee.collective.execute( @@ -354,7 +354,7 @@ describeGov('Governance: Technical Committee tests', () => { defaultEnactmentMoment, ); - const referendumIndex = Event.expect(submitResult, helper.api!.events.fellowshipReferenda.Submitted).data.index.toNumber(); + const referendumIndex = Event.expect(submitResult, helper.getApi().events.fellowshipReferenda.Submitted).data.index.toNumber(); await expect(helper.technicalCommittee.collective.execute( techcomms.andy, @@ -371,7 +371,7 @@ describeGov('Governance: Technical Committee tests', () => { committeeSize, ); - const committeeProposedEvent = Event.expect(proposeResult, helper.api!.events.technicalCommittee.Proposed).data; + const committeeProposedEvent = Event.expect(proposeResult, helper.getApi().events.technicalCommittee.Proposed).data; const proposalIndex = committeeProposedEvent.proposalIndex.toNumber(); const proposalHash = committeeProposedEvent.proposalHash.toHex(); diff --git a/tests/src/maintenance.seqtest.ts b/tests/src/maintenance.seqtest.ts index 863d3afc9c..3d0175e84c 100644 --- a/tests/src/maintenance.seqtest.ts +++ b/tests/src/maintenance.seqtest.ts @@ -315,7 +315,7 @@ describe('Integration Test: Maintenance Functionality', () => { ])).to.be.fulfilled as ITransactionResult; // preimage is executed, and an appropriate event is present - const events = result.result.events.filter(helper.api!.events.identity.IdentitiesInserted.is); + const events = result.result.events.filter(helper.getApi().events.identity.IdentitiesInserted.is); expect(events.length).to.be.equal(1); // the preimage goes back to being unrequested diff --git a/tests/src/scheduler.seqtest.ts b/tests/src/scheduler.seqtest.ts index af808c8346..e242b027da 100644 --- a/tests/src/scheduler.seqtest.ts +++ b/tests/src/scheduler.seqtest.ts @@ -410,7 +410,7 @@ describe('Scheduling token and balance transfers', () => { const priority = 112; await helper.getSudo().scheduler.changePriority(superuser, scheduledId, priority); - const priorityChanged = await helper.wait.expectEvent(waitForBlocks, helper.api!.events.uniqueScheduler.PriorityChanged) as any; + const priorityChanged = await helper.wait.expectEvent(waitForBlocks, helper.getApi().events.uniqueScheduler.PriorityChanged) as any; const [blockNumber, index] = priorityChanged.task; expect(blockNumber.toNumber()).to.be.equal(executionBlock); @@ -661,7 +661,7 @@ describe('Negative Test: Scheduling', () => { await expect(helper.scheduler.changePriority(alice, scheduledId, priority)) .to.be.rejectedWith(/BadOrigin/); - await helper.wait.expectEvent(waitForBlocks, helper.api!.events.uniqueScheduler.PriorityChanged); + await helper.wait.expectEvent(waitForBlocks, helper.getApi().events.uniqueScheduler.PriorityChanged); }); }); diff --git a/tests/src/sub/appPromotion/appPromotion.test.ts b/tests/src/sub/appPromotion/appPromotion.test.ts index cd8be33136..fac018442d 100644 --- a/tests/src/sub/appPromotion/appPromotion.test.ts +++ b/tests/src/sub/appPromotion/appPromotion.test.ts @@ -926,7 +926,7 @@ describe('App promotion', () => { await helper.staking.stake(staker, 200n * nominal); const result = await helper.executeExtrinsic(staker, `api.tx.appPromotion.${testCase.method}`, unstakeParams); - const event = Event.expect(result, helper.api!.events.appPromotion.Unstake); + const event = Event.expect(result, helper.getApi().events.appPromotion.Unstake); const unstakerEvents = event.data[0].toString(); const unstakedEvents = event.data[1].toBigInt(); expect(unstakerEvents).to.eq(staker.address); @@ -938,7 +938,7 @@ describe('App promotion', () => { const [staker] = await getAccounts(1); const result = await helper.executeExtrinsic(staker, 'api.tx.appPromotion.stake', [100n * nominal]); - const event = Event.expect(result, helper.api!.events.appPromotion.Stake); + const event = Event.expect(result, helper.getApi().events.appPromotion.Stake); const stakerEvents = event.data[0].toString(); const stakedEvents = event.data[1].toBigInt(); expect(stakerEvents).to.eq(staker.address); diff --git a/tests/src/sub/refungible/repartition.test.ts b/tests/src/sub/refungible/repartition.test.ts index 4240a96bba..d27b6f199b 100644 --- a/tests/src/sub/refungible/repartition.test.ts +++ b/tests/src/sub/refungible/repartition.test.ts @@ -60,7 +60,7 @@ describe('integration test: Refungible functionality:', () => { const token = await collection.mintToken(alice, 100n); await token.repartition(alice, 200n); const chainEvents = helper.chainLog.slice(-1)[0].events; - const event = chainEvents?.find(helper.api!.events.common.ItemCreated.is); + const event = chainEvents?.find(helper.getApi().events.common.ItemCreated.is); expect(event?.eq({ section: 'common', method: 'ItemCreated', @@ -79,7 +79,7 @@ describe('integration test: Refungible functionality:', () => { const token = await collection.mintToken(alice, 100n); await token.repartition(alice, 50n); const chainEvents = helper.chainLog.slice(-1)[0].events; - const event = chainEvents?.find(helper.api!.events.common.ItemDestroyed.is); + const event = chainEvents?.find(helper.getApi().events.common.ItemDestroyed.is); expect(event?.eq({ section: 'common', method: 'ItemDestroyed', diff --git a/tests/src/util/playgrounds/unique.ts b/tests/src/util/playgrounds/unique.ts index bfb3e4948f..bb6d0840b2 100644 --- a/tests/src/util/playgrounds/unique.ts +++ b/tests/src/util/playgrounds/unique.ts @@ -821,7 +821,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionDestroyed.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionDestroyed.is); return this.helper.util.checkEvent(event, collectionId); } @@ -841,7 +841,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionSponsorSet.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionSponsorSet.is); return this.helper.util.checkEvent(event, collectionId); } @@ -860,7 +860,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.SponsorshipConfirmed.is); + const event = result.result.events.find(this.helper.getApi().events.common.SponsorshipConfirmed.is); return this.helper.util.checkEvent(event, collectionId); } @@ -879,7 +879,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionSponsorRemoved.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionSponsorRemoved.is); return this.helper.util.checkEvent(event, collectionId); } @@ -907,7 +907,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionLimitSet.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionLimitSet.is); return this.helper.util.checkEvent(event, collectionId); } @@ -927,7 +927,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionOwnerChanged.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionOwnerChanged.is); return this.helper.util.checkEvent(event, collectionId); } @@ -947,7 +947,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionAdminAdded.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionAdminAdded.is); return this.helper.util.checkEvent(event, collectionId); } @@ -967,7 +967,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionAdminRemoved.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionAdminRemoved.is); return this.helper.util.checkEvent(event, collectionId); } @@ -997,7 +997,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.AllowListAddressAdded.is); + const event = result.result.events.find(this.helper.getApi().events.common.AllowListAddressAdded.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1016,7 +1016,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.AllowListAddressRemoved.is); + const event = result.result.events.find(this.helper.getApi().events.common.AllowListAddressRemoved.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1036,7 +1036,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionPermissionSet.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionPermissionSet.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1081,7 +1081,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionPropertySet.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionPropertySet.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1124,7 +1124,7 @@ class CollectionGroup extends HelperGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.CollectionPropertyDeleted.is); + const event = result.result.events.find(this.helper.getApi().events.common.CollectionPropertyDeleted.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1146,7 +1146,7 @@ class CollectionGroup extends HelperGroup { true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`, ); - return this.helper.util.isTokenTransferSuccess(this.helper.api!, result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount); + return this.helper.util.isTokenTransferSuccess(this.helper.getApi(), result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount); } /** @@ -1168,7 +1168,7 @@ class CollectionGroup extends HelperGroup { 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount], true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`, ); - return this.helper.util.isTokenTransferSuccess(this.helper.api!, result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount); + return this.helper.util.isTokenTransferSuccess(this.helper.getApi(), result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount); } /** @@ -1188,7 +1188,7 @@ class CollectionGroup extends HelperGroup { 'api.tx.unique.burnItem', [collectionId, tokenId, amount], true, // `Unable to burn token for ${label}`, ); - const burnedTokens = this.helper.util.extractTokensFromBurnResult(this.helper.api!, burnResult); + const burnedTokens = this.helper.util.extractTokensFromBurnResult(this.helper.getApi(), burnResult); if(burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens'); return burnedTokens.success; } @@ -1210,7 +1210,7 @@ class CollectionGroup extends HelperGroup { 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount], true, // `Unable to burn token from for ${label}`, ); - const burnedTokens = this.helper.util.extractTokensFromBurnResult(this.helper.api!, burnResult); + const burnedTokens = this.helper.util.extractTokensFromBurnResult(this.helper.getApi(), burnResult); return burnedTokens.success && burnedTokens.tokens.length > 0; } @@ -1231,7 +1231,7 @@ class CollectionGroup extends HelperGroup { true, // `Unable to approve token for ${label}`, ); - const event = approveResult.result.events.find(this.helper.api!.events.common.Approved.is); + const event = approveResult.result.events.find(this.helper.getApi().events.common.Approved.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1253,7 +1253,7 @@ class CollectionGroup extends HelperGroup { true, // `Unable to approve token for ${label}`, ); - const event = approveResult.result.events.find(this.helper.api!.events.common.Approved.is); + const event = approveResult.result.events.find(this.helper.getApi().events.common.Approved.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1451,7 +1451,7 @@ class NFTnRFT extends CollectionGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.PropertyPermissionSet.is); + const event = result.result.events.find(this.helper.getApi().events.common.PropertyPermissionSet.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1484,7 +1484,7 @@ class NFTnRFT extends CollectionGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.TokenPropertySet.is); + const event = result.result.events.find(this.helper.getApi().events.common.TokenPropertySet.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1517,7 +1517,7 @@ class NFTnRFT extends CollectionGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.TokenPropertyDeleted.is); + const event = result.result.events.find(this.helper.getApi().events.common.TokenPropertyDeleted.is); return this.helper.util.checkEvent(event, collectionId); } @@ -1552,7 +1552,7 @@ class NFTnRFT extends CollectionGroup { 'api.tx.unique.createCollectionEx', [collectionOptions], true, // errorLabel, ); - return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(this.helper.api!, creationResult)); + return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(this.helper.getApi(), creationResult)); } getCollectionObject(_collectionId: number): any { @@ -1587,7 +1587,7 @@ class NFTnRFT extends CollectionGroup { true, ); - const event = result.result.events.find(this.helper.api!.events.common.ApprovedForAll.is); + const event = result.result.events.find(this.helper.getApi().events.common.ApprovedForAll.is); return this.helper.util.checkEvent(event, collectionId); } } @@ -1709,7 +1709,7 @@ class NFTGroup extends NFTnRFT { }], true, ); - const createdTokens = this.helper.util.extractTokensFromCreationResult(this.helper.api!, creationResult); + const createdTokens = this.helper.util.extractTokensFromCreationResult(this.helper.getApi(), creationResult); if(createdTokens.tokens.length > 1) throw Error('Minted multiple tokens'); if(createdTokens.tokens.length < 1) throw Error('No tokens minted'); return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId); @@ -1737,7 +1737,7 @@ class NFTGroup extends NFTnRFT { true, ); const collection = this.getCollectionObject(collectionId); - return this.helper.util.extractTokensFromCreationResult(this.helper.api!, creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); + return this.helper.util.extractTokensFromCreationResult(this.helper.getApi(), creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); } /** @@ -1770,7 +1770,7 @@ class NFTGroup extends NFTnRFT { true, ); const collection = this.getCollectionObject(collectionId); - return this.helper.util.extractTokensFromCreationResult(this.helper.api!, creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); + return this.helper.util.extractTokensFromCreationResult(this.helper.getApi(), creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); } /** @@ -1897,7 +1897,7 @@ class RFTGroup extends NFTnRFT { }], true, ); - const createdTokens = this.helper.util.extractTokensFromCreationResult(this.helper.api!, creationResult); + const createdTokens = this.helper.util.extractTokensFromCreationResult(this.helper.getApi(), creationResult); if(createdTokens.tokens.length > 1) throw Error('Minted multiple tokens'); if(createdTokens.tokens.length < 1) throw Error('No tokens minted'); return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId); @@ -1911,7 +1911,7 @@ class RFTGroup extends NFTnRFT { true, // `Unable to mint RFT tokens for ${label}`, ); const collection = this.getCollectionObject(collectionId); - return this.helper.util.extractTokensFromCreationResult(this.helper.api!, creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); + return this.helper.util.extractTokensFromCreationResult(this.helper.getApi(), creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); } /** @@ -1935,7 +1935,7 @@ class RFTGroup extends NFTnRFT { true, ); const collection = this.getCollectionObject(collectionId); - return this.helper.util.extractTokensFromCreationResult(this.helper.api!, creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); + return this.helper.util.extractTokensFromCreationResult(this.helper.getApi(), creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId)); } /** @@ -2010,11 +2010,11 @@ class RFTGroup extends NFTnRFT { if(!currentAmount) throw Error("Token doens't exist"); if(currentAmount < amount) { - const event = repartitionResult.result.events.find(this.helper.api!.events.common.ItemCreated.is); + const event = repartitionResult.result.events.find(this.helper.getApi().events.common.ItemCreated.is); return this.helper.util.checkEvent(event, collectionId); } - const event = repartitionResult.result.events.find(this.helper.api!.events.common.ItemDestroyed.is); + const event = repartitionResult.result.events.find(this.helper.getApi().events.common.ItemDestroyed.is); return this.helper.util.checkEvent(event, collectionId); } } @@ -2056,7 +2056,7 @@ class FTGroup extends CollectionGroup { 'api.tx.unique.createCollectionEx', [collectionOptions], true, ); - return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(this.helper.api!, creationResult)); + return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(this.helper.getApi(), creationResult)); } /** @@ -2079,7 +2079,7 @@ class FTGroup extends CollectionGroup { true, // `Unable to mint fungible tokens for ${label}`, ); - const event = creationResult.result.events.find(this.helper.api!.events.common.ItemCreated.is); + const event = creationResult.result.events.find(this.helper.getApi().events.common.ItemCreated.is); return this.helper.util.checkEvent(event, collectionId); } @@ -2103,7 +2103,7 @@ class FTGroup extends CollectionGroup { true, ); - const event = creationResult.result.events.find(this.helper.api!.events.common.ItemCreated.is); + const event = creationResult.result.events.find(this.helper.getApi().events.common.ItemCreated.is); return this.helper.util.checkEvent(event, collectionId); } @@ -2301,7 +2301,7 @@ export class SubstrateBalanceGroup extends HelperGrou async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise { const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/); - const event = result.result.events.filter(this.helper.api!.events.balances.Transfer.is).at(-1)!; + const event = result.result.events.filter(this.helper.getApi().events.balances.Transfer.is).at(-1)!; const transfer = { from: this.helper.address.normalizeSubstrate(event.data[0].toString()), to: this.helper.address.normalizeSubstrate(event.data[1].toString()), @@ -2362,7 +2362,7 @@ export class EthereumBalanceGroup extends HelperGroup async transferToEthereum(signer: TSigner, address: TEthereumAccount, amount: bigint | string): Promise { const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true); - const event = result.result.events.filter(this.helper.api!.events.balances.Transfer.is).at(-1)!; + const event = result.result.events.filter(this.helper.getApi().events.balances.Transfer.is).at(-1)!; const transfer = { from: event.data[0].toString(), to: event.data[1].toString(), @@ -2473,7 +2473,7 @@ class BalanceGroup extends HelperGroup { async forceTransferToSubstrate(signer: TSigner, from: TSubstrateAccount, to: TSubstrateAccount, amount: bigint | string): Promise { const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.forceTransfer', [from, to, amount], true); - const event = result.result.events.filter(this.helper.api!.events.balances.Transfer.is).at(-1)!; + const event = result.result.events.filter(this.helper.getApi().events.balances.Transfer.is).at(-1)!; const transfer = { from: this.helper.address.normalizeSubstrate(event.data[0].toString()), to: this.helper.address.normalizeSubstrate(event.data[1].toString()), @@ -2495,7 +2495,7 @@ class BalanceGroup extends HelperGroup { async vestedTransfer(signer: TSigner, address: TSubstrateAccount, schedule: { start: number, period: number, periodCount: number, perPeriod: bigint }): Promise { const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.vestedTransfer', [address, schedule]); const event = result.result.events - .filter(this.helper.api!.events.vesting.VestingScheduleAdded.is) + .filter(this.helper.getApi().events.vesting.VestingScheduleAdded.is) .find(event => this.helper.address.normalizeSubstrate(event.data[0].toString()) === signer.address); if(!event) throw Error('Cannot find transfer in events'); } @@ -2516,7 +2516,7 @@ class BalanceGroup extends HelperGroup { async claim(signer: TSigner) { const result = await this.helper.executeExtrinsic(signer, 'api.tx.vesting.claim', []); const event = result.result.events - .filter(this.helper.api!.events.vesting.Claimed.is) + .filter(this.helper.getApi().events.vesting.Claimed.is) .find(event => this.helper.address.normalizeSubstrate(event.data[0].toString()) === signer.address); if(!event) throw Error('Cannot find claim in events'); } @@ -2797,7 +2797,7 @@ class PreimageGroup extends HelperGroup { */ async notePreimageHash(signer: TSigner, bytes: string | Uint8Array) { const result = await this.helper.executeExtrinsic(signer, 'api.tx.preimage.notePreimage', [bytes]); - const event = result.result.events.find(this.helper.api!.events.preimage.Noted.is); + const event = result.result.events.find(this.helper.getApi().events.preimage.Noted.is); if(!event) throw new Error('"Noted" event not found'); return event?.data.hash_.toHex(); @@ -3020,9 +3020,7 @@ export class UniqueNFTCollection extends UniqueBaseCollection { async getTokenPropertiesConsumedSpace(tokenId: number): Promise { const api = this.helper.getApi(); - const props = (await api.query.nonfungible.tokenProperties(this.collectionId, tokenId)).toJSON(); - - return (props! as any).consumedSpace; + return (await api.query.nonfungible.tokenProperties(this.collectionId, tokenId)).consumedSpace.toNumber(); } async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId) { @@ -3125,9 +3123,7 @@ export class UniqueRFTCollection extends UniqueBaseCollection { async getTokenPropertiesConsumedSpace(tokenId: number): Promise { const api = this.helper.getApi(); - const props = (await api.query.refungible.tokenProperties(this.collectionId, tokenId)).toJSON(); - - return (props! as any).consumedSpace; + return (await api.query.refungible.tokenProperties(this.collectionId, tokenId)).consumedSpace.toNumber(); } async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount = 1n) { diff --git a/tests/src/xcm/xcm.types.ts b/tests/src/xcm/xcm.types.ts index 3544f0cb54..f5bca8994b 100644 --- a/tests/src/xcm/xcm.types.ts +++ b/tests/src/xcm/xcm.types.ts @@ -4,6 +4,7 @@ import {expect, usingAcalaPlaygrounds, usingAstarPlaygrounds, usingKaruraPlaygro import {DevUniqueHelper} from '../util/playgrounds/unique.dev'; import config from '../config'; import { XcmV3TraitsOutcome } from '@unique-nft/opal-testnet-types'; +import { Context } from 'mocha'; export const UNIQUE_CHAIN = +(process.env.RELAY_UNIQUE_ID || 2037); export const STATEMINT_CHAIN = +(process.env.RELAY_STATEMINT_ID || 1000); @@ -62,22 +63,22 @@ export const uniqueAssetId = { }; export const expectFailedToTransact = async (helper: DevUniqueHelper, messageHash: string | undefined) => { - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == messageHash + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == messageHash && event.error.isFailedToTransactAsset); }; export const expectUntrustedReserveLocationFail = async (helper: DevUniqueHelper, messageHash: string | undefined) => { - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == messageHash + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == messageHash && event.error.isUntrustedReserveLocation); }; export const expectDownwardXcmNoPermission = async (helper: DevUniqueHelper) => { // The correct messageHash for downward messages can't be reliably obtained - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.dmpQueue.ExecutedDownward, event => event.outcome.asIncomplete[1].isNoPermission); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.dmpQueue.ExecutedDownward, event => event.outcome.asIncomplete[1].isNoPermission); }; export const expectDownwardXcmComplete = async (helper: DevUniqueHelper) => { // The correct messageHash for downward messages can't be reliably obtained - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.dmpQueue.ExecutedDownward, event => event.outcome.isComplete); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.dmpQueue.ExecutedDownward, event => event.outcome.isComplete); }; export const NETWORKS = { @@ -260,7 +261,7 @@ export class XcmTestHelper { const feeAssetItem = 0; await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited'); - const messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + const messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); this._balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address); this._unqFees = this._balanceUniqueTokenInit - this._balanceUniqueTokenMiddle - TRANSFER_AMOUNT; @@ -279,9 +280,9 @@ export class XcmTestHelper { it matches what was sent. */ if(networkName == 'polkadex') { - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash == messageSent.messageHash); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash == messageSent.messageHash); } else { - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Success, event => event.messageHash == messageSent.messageHash); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Success, event => event.messageHash == messageSent.messageHash); } }); @@ -317,17 +318,17 @@ export class XcmTestHelper { await targetPlayground(networkUrl, async (helper) => { if('getSudo' in helper) { await helper.getSudo().xcm.send(sudoer, this._runtimeVersionedMultilocation(), xcmProgram); - xcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + xcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } else if('fastDemocracy' in helper) { //const xcmSend = helper.constructApiCall('api.tx.polkadotXcm.send', [this._runtimeVersionedMultilocation(), xcmProgram]); // Needed to bypass the call filter. //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal(`sending ${networkName} -> Unique via XCM program`, batchCall); - xcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + xcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Success, event => event.messageHash == xcmProgramSent.messageHash); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Success, event => event.messageHash == xcmProgramSent.messageHash); this._balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccountOnUnq.address); @@ -369,13 +370,13 @@ export class XcmTestHelper { await targetPlayground(networkUrl, async (helper) => { if('getSudo' in helper) { await helper.getSudo().xcm.send(sudoer, this._runtimeVersionedMultilocation(), maliciousXcmProgram); - maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } else if('fastDemocracy' in helper) { //const xcmSend = helper.constructApiCall('api.tx.polkadotXcm.send', [this._runtimeVersionedMultilocation(), maliciousXcmProgram]); // Needed to bypass the call filter. //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal(`sending ${networkName} -> Unique via XCM program`, batchCall); - maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } }); @@ -428,7 +429,7 @@ export class XcmTestHelper { await targetPlayground(networkUrl, async (helper) => { if('getSudo' in helper) { await helper.getSudo().xcm.send(sudoer, this._runtimeVersionedMultilocation(), maliciousXcmProgramFullId); - maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } // Moonbeam case else if('fastDemocracy' in helper) { @@ -437,7 +438,7 @@ export class XcmTestHelper { //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal(`${networkName} try to act like a reserve location for UNQ using path asset identification`,batchCall); - maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } }); @@ -451,7 +452,7 @@ export class XcmTestHelper { await targetPlayground(networkUrl, async (helper) => { if('getSudo' in helper) { await helper.getSudo().xcm.send(sudoer, this._runtimeVersionedMultilocation(), maliciousXcmProgramHereId); - maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } else if('fastDemocracy' in helper) { //const xcmSend = helper.constructApiCall('api.tx.polkadotXcm.send', [this._runtimeVersionedMultilocation(), maliciousXcmProgramHereId]); @@ -459,7 +460,7 @@ export class XcmTestHelper { //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal(`${networkName} try to act like a reserve location for UNQ using "here" asset identification`, batchCall); - maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } }); @@ -493,14 +494,14 @@ export class XcmTestHelper { await targetPlayground(networkUrl, async (helper) => { if('getSudo' in helper) { await helper.getSudo().xcm.send(sudoerOnTargetChain, this._runtimeVersionedMultilocation(), maliciousXcmProgramFullId); - messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } else if('fastDemocracy' in helper) { //const xcmSend = helper.constructApiCall('api.tx.polkadotXcm.send', [this._runtimeVersionedMultilocation(), maliciousXcmProgramFullId]); // Needed to bypass the call filter. //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal(`${networkName} sending native tokens to the Unique via fast democracy`, batchCall); - messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); } }); await expectFailedToTransact(helper, messageSent); @@ -562,7 +563,7 @@ export class XcmTestHelper { await expectDownwardXcmComplete(helper); for(const kv of kvs) { - const forcedValue = await helper.callRpc('api.rpc.state.getStorage', [kv.key]); + const forcedValue = await helper.callRpc('api.rpc.state.getStorage', [kv.key]) as Context; expect(hexToString(forcedValue.toHex())).to.be.equal(kv.val); } }); diff --git a/tests/src/xcm/xcmQuartz.test.ts b/tests/src/xcm/xcmQuartz.test.ts index d08d33a14d..f5c3f95784 100644 --- a/tests/src/xcm/xcmQuartz.test.ts +++ b/tests/src/xcm/xcmQuartz.test.ts @@ -677,10 +677,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => { await usingKaruraPlaygrounds(karuraUrl, async (helper) => { await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent && event.error.isFailedToTransactAsset); targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -758,10 +758,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => { await usingKaruraPlaygrounds(karuraUrl, async (helper) => { await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgramFullId); - maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent && event.error.isUntrustedReserveLocation); let accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -771,10 +771,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => { await usingKaruraPlaygrounds(karuraUrl, async (helper) => { await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgramHereId); - maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent && event.error.isUntrustedReserveLocation); accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -850,7 +850,7 @@ describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => { }); const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: string | undefined) => { - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == messageSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == messageSent && event.error.isFailedToTransactAsset); }; @@ -862,7 +862,7 @@ describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => { const destination = quartzCombinedMultilocation; await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited'); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -874,7 +874,7 @@ describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => { const destination = quartzCombinedMultilocation; await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited'); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -906,7 +906,7 @@ describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => { feeAssetItem, ]); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -1162,10 +1162,10 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => { //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal('try to spend more QTZ than Moonriver has', batchCall); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent && event.error.isFailedToTransactAsset); targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1252,10 +1252,10 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => { // const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal('try to act like a reserve location for QTZ using path asset identification', batchCall); - maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent && event.error.isUntrustedReserveLocation); let accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1269,10 +1269,10 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => { // const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal('try to act like a reserve location for QTZ using "here" asset identification', batchCall); - maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent && event.error.isUntrustedReserveLocation); accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1531,10 +1531,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => { await usingShidenPlaygrounds(shidenUrl, async (helper) => { await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent && event.error.isFailedToTransactAsset); targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1612,10 +1612,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => { await usingShidenPlaygrounds(shidenUrl, async (helper) => { await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgramFullId); - maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent && event.error.isUntrustedReserveLocation); let accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1625,10 +1625,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => { await usingShidenPlaygrounds(shidenUrl, async (helper) => { await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgramHereId); - maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent && event.error.isUntrustedReserveLocation); accountBalance = await helper.balance.getSubstrate(targetAccount.address); diff --git a/tests/src/xcm/xcmUnique.test.ts b/tests/src/xcm/xcmUnique.test.ts index 348ce82e75..7e6d99ff29 100644 --- a/tests/src/xcm/xcmUnique.test.ts +++ b/tests/src/xcm/xcmUnique.test.ts @@ -678,10 +678,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Acala', () => { await usingAcalaPlaygrounds(acalaUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueVersionedMultilocation, maliciousXcmProgram); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent && event.error.isFailedToTransactAsset); targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -750,10 +750,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Acala', () => { await usingAcalaPlaygrounds(acalaUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramFullId); - maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent && event.error.isUntrustedReserveLocation); let accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -763,10 +763,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Acala', () => { await usingAcalaPlaygrounds(acalaUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramHereId); - maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent && event.error.isUntrustedReserveLocation); accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -862,7 +862,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => { const feeAssetItem = 0; await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited'); - const messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + const messageSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address); unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT; @@ -880,7 +880,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => { since the hash is being checked to ensure it matches what was sent. */ - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash == messageSent.messageHash); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash == messageSent.messageHash); }); }); @@ -899,10 +899,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => { await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueVersionedMultilocation, xcmProgram); - xcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + xcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Success, event => event.messageHash.unwrapOr(null)?.toUtf8() == xcmProgramSent); + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Success, event => event.messageHash.unwrapOr(null)?.toUtf8() == xcmProgramSent); balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccount.address); @@ -934,7 +934,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => { await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueVersionedMultilocation, maliciousXcmProgram); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, maliciousXcmProgramSent); @@ -983,7 +983,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => { await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramFullId); - maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); }); await expectUntrustedReserveLocationFail(helper, maliciousXcmProgramFullIdSent); @@ -995,7 +995,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => { await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramHereId); - maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent); + maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent); }); await expectUntrustedReserveLocationFail(helper, maliciousXcmProgramHereIdSent); @@ -1092,7 +1092,7 @@ describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => { const destination = uniqueCombinedMultilocationAcala; await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited'); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -1104,7 +1104,7 @@ describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => { const destination = uniqueCombinedMultilocation; await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited'); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -1136,7 +1136,7 @@ describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => { feeAssetItem, ]); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -1161,7 +1161,7 @@ describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => { await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueParachainMultilocation, maliciousXcmProgramFullId); - messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + messageSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); await expectFailedToTransact(helper, messageSent); @@ -1408,10 +1408,10 @@ describeXCM('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => { //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal('try to spend more UNQ than Moonbeam has', batchCall); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent && event.error.isFailedToTransactAsset); targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1478,10 +1478,10 @@ describeXCM('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => { //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal('try to act like a reserve location for UNQ using path asset identification', batchCall); - maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent && event.error.isUntrustedReserveLocation); let accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1495,10 +1495,10 @@ describeXCM('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => { //const batchCall = helper.encodeApiCall('api.tx.utility.batch', [[xcmSend]]); //await helper.fastDemocracy.executeProposal('try to act like a reserve location for UNQ using "here" asset identification', batchCall); - maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent && event.error.isUntrustedReserveLocation); accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1563,8 +1563,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => { }, }, }, - }, - //}; + }; //await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, UNQ_ASSET_ID_ON_ASTAR]); @@ -1748,10 +1747,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => { await usingAstarPlaygrounds(astarUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueVersionedMultilocation, maliciousXcmProgram); - maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramSent && event.error.isFailedToTransactAsset); targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1809,10 +1808,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => { await usingAstarPlaygrounds(astarUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueVersionedMultilocation, maliciousXcmProgramFullId); - maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramFullIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramFullIdSent && event.error.isUntrustedReserveLocation); let accountBalance = await helper.balance.getSubstrate(targetAccount.address); @@ -1822,10 +1821,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => { await usingAstarPlaygrounds(astarUrl, async (helper) => { await helper.getSudo().xcm.send(alice, uniqueVersionedMultilocation, maliciousXcmProgramHereId); - maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); + maliciousXcmProgramHereIdSent = (await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.XcmpMessageSent)).messageHash.unwrapOr(null)?.toUtf8(); }); - await helper.wait.expectEvent(maxWaitBlocks, helper.api!.events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent + await helper.wait.expectEvent(maxWaitBlocks, helper.getApi().events.xcmpQueue.Fail, event => event.messageHash.unwrapOr(null)?.toUtf8() == maliciousXcmProgramHereIdSent && event.error.isUntrustedReserveLocation); accountBalance = await helper.balance.getSubstrate(targetAccount.address); diff --git a/tests/yarn.lock b/tests/yarn.lock index fd9e85bcba..2191cbe8d3 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -623,7 +623,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/types-codec@npm:10.9.1": +"@polkadot/types-codec@npm:10.9.1, @polkadot/types-codec@npm:^10.9.1": version: 10.9.1 resolution: "@polkadot/types-codec@npm:10.9.1" dependencies: @@ -669,7 +669,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/types@npm:10.9.1": +"@polkadot/types@npm:10.9.1, @polkadot/types@npm:^10.9.1": version: 10.9.1 resolution: "@polkadot/types@npm:10.9.1" dependencies: @@ -6258,6 +6258,8 @@ __metadata: "@polkadot/api": 10.9.1 "@polkadot/rpc-core": ^10.9.1 "@polkadot/typegen": 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