Skip to content

Commit 24336ab

Browse files
committed
Major speed improvements on Testnet e2e tests (Savings of ~10 minutes when running in serial mode)
1 parent 02730ee commit 24336ab

File tree

3 files changed

+31
-49
lines changed

3 files changed

+31
-49
lines changed

e2e/capacity/transactions.test.ts

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('Capacity Transactions', function () {
7171
const capacityKeys = createKeys('CapacityKeysNSF');
7272
const capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, 'CapProvNSF', FUNDS_AMOUNT);
7373
// this will first fund 'capacityKeys' before staking
74-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked));
74+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked));
7575

7676
// As current owner, add a new set of control keys that do not have a balance.
7777
const newControlKeypair = createKeys('NewKeyNoBalance');
@@ -112,7 +112,7 @@ describe('Capacity Transactions', function () {
112112
capacityKeys = createKeys('CapacityKeys');
113113
capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, 'CapacityProvider', FUNDS_AMOUNT);
114114
// Stake enough for all transactions
115-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, stakedForMsa));
115+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, stakedForMsa));
116116
});
117117

118118
beforeEach(async function () {
@@ -204,7 +204,7 @@ describe('Capacity Transactions', function () {
204204
beforeEach(async function () {
205205
starting_block = (await ExtrinsicHelper.apiPromise.rpc.chain.getHeader()).number.toNumber();
206206
// Stake each time so that we always have enough capacity to do the call
207-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked));
207+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked));
208208
});
209209

210210
it('successfully pays with Capacity for eligible transaction - addIPFSMessage', async function () {
@@ -245,11 +245,15 @@ describe('Capacity Transactions', function () {
245245
before(async function () {
246246
capacityKeys = createKeys('CapacityKeys');
247247
capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, 'CapacityProvider', FUNDS_AMOUNT);
248+
// Create a MSA for the delegator
249+
[delegatorKeys, delegatorProviderId] = await createDelegator(fundingSource);
250+
assert.notEqual(delegatorKeys, undefined, 'setup should populate delegator_key');
251+
assert.notEqual(delegatorProviderId, undefined, 'setup should populate msa_id');
248252
});
249253

250254
beforeEach(async function () {
251255
// Stake each time so that we always have enough capacity to do the call
252-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked));
256+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked));
253257
});
254258

255259
it('successfully pays with Capacity for eligible transaction - applyItemActions', async function () {
@@ -317,11 +321,6 @@ describe('Capacity Transactions', function () {
317321
// Create a schema for Itemized PayloadLocation
318322
const itemizedSchemaId: SchemaId = await getOrCreateAvroChatMessageItemizedSchema(fundingSource);
319323

320-
// Create a MSA for the delegator
321-
[delegatorKeys, delegatorProviderId] = await createDelegator(fundingSource);
322-
assert.notEqual(delegatorKeys, undefined, 'setup should populate delegator_key');
323-
assert.notEqual(delegatorProviderId, undefined, 'setup should populate msa_id');
324-
325324
// Add and update actions
326325
const payload_1 = new Bytes(ExtrinsicHelper.api.registry, 'Hello World From Frequency');
327326
const add_action = {
@@ -366,11 +365,6 @@ describe('Capacity Transactions', function () {
366365
// Create a schema for Itemized PayloadLocation
367366
const itemizedSchemaId: SchemaId = await getOrCreateAvroChatMessageItemizedSchema(fundingSource);
368367

369-
// Create a MSA for the delegator
370-
[delegatorKeys, delegatorProviderId] = await createDelegator(fundingSource);
371-
assert.notEqual(delegatorKeys, undefined, 'setup should populate delegator_key');
372-
assert.notEqual(delegatorProviderId, undefined, 'setup should populate msa_id');
373-
374368
// Add and update actions
375369
const payload_1 = new Bytes(ExtrinsicHelper.api.registry, 'Hello World From Frequency');
376370
const add_action = {
@@ -413,11 +407,6 @@ describe('Capacity Transactions', function () {
413407
it('successfully pays with Capacity for eligible transaction - upsertPageWithSignature; deletePageWithSignature', async function () {
414408
const paginatedSchemaId: SchemaId = await getOrCreateAvroChatMessagePaginatedSchema(fundingSource);
415409

416-
// Create a MSA for the delegator
417-
[delegatorKeys, delegatorProviderId] = await createDelegator(fundingSource);
418-
assert.notEqual(delegatorKeys, undefined, 'setup should populate delegator_key');
419-
assert.notEqual(delegatorProviderId, undefined, 'setup should populate msa_id');
420-
421410
const page_id = new u16(ExtrinsicHelper.api.registry, 1);
422411

423412
// Add and update actions
@@ -480,11 +469,6 @@ describe('Capacity Transactions', function () {
480469
it('successfully pays with Capacity for eligible transaction - upsertPageWithSignatureV2; deletePageWithSignatureV2', async function () {
481470
const paginatedSchemaId: SchemaId = await getOrCreateAvroChatMessagePaginatedSchema(fundingSource);
482471

483-
// Create a MSA for the delegator
484-
[delegatorKeys, delegatorProviderId] = await createDelegator(fundingSource);
485-
assert.notEqual(delegatorKeys, undefined, 'setup should populate delegator_key');
486-
assert.notEqual(delegatorProviderId, undefined, 'setup should populate msa_id');
487-
488472
const page_id = new u16(ExtrinsicHelper.api.registry, 1);
489473

490474
// Add and update actions
@@ -553,7 +537,7 @@ describe('Capacity Transactions', function () {
553537
});
554538

555539
it('successfully pays with Capacity for eligible transaction - claimHandle', async function () {
556-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked));
540+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked));
557541

558542
const handle = getTestHandle();
559543
const expiration = (await getBlockNumber()) + 10;
@@ -583,7 +567,7 @@ describe('Capacity Transactions', function () {
583567
capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, 'CapacityProvider', FUNDS_AMOUNT);
584568
});
585569

586-
it('successfully pays with Capacity for eligible transaction - claimHandle [balance < ED]', async function () {
570+
it('successfully pays with Capacity for eligible transaction - claimHandle [available balance < ED]', async function () {
587571
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked));
588572
// Empty the account to ensure the balance is less than ED
589573
await ExtrinsicHelper.emptyAccount(capacityKeys, fundingSource.address).signAndSend();
@@ -640,19 +624,17 @@ describe('Capacity Transactions', function () {
640624
// and is NOT eligible to replenish Capacity, it should error and be dropped
641625
// from the transaction pool.
642626
it('fails to pay for a transaction with empty capacity', async function () {
643-
const capacityKeys = createKeys('CapKeysEmpty');
644-
const capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, 'CapProvEmpty', FUNDS_AMOUNT);
645627
const noCapacityKeys = createKeys('noCapacityKeys');
646-
const _providerId = await createMsaAndProvider(fundingSource, noCapacityKeys, 'NoCapProvider');
628+
const noCapacityProvider = await createMsaAndProvider(fundingSource, noCapacityKeys, 'NoCapProvider');
647629

648630
const delegatorKeys = createKeys('delegatorKeys');
649631

650632
const payload = await generateDelegationPayload({
651-
authorizedMsaId: capacityProvider,
633+
authorizedMsaId: noCapacityProvider,
652634
schemaIds: [schemaId],
653635
});
654636
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', payload);
655-
const grantDelegationOp = ExtrinsicHelper.grantDelegation(
637+
const grantDelegationOp = ExtrinsicHelper.createSponsoredAccountWithDelegation(
656638
delegatorKeys,
657639
noCapacityKeys,
658640
signPayloadSr25519(noCapacityKeys, addProviderData),
@@ -670,9 +652,9 @@ describe('Capacity Transactions', function () {
670652
const capacityKeys = createKeys('CapKeysUnder');
671653
const capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, 'CapProvUnder', FUNDS_AMOUNT);
672654
const noTokensKeys = createKeys('noTokensKeys');
673-
const delegatorKeys = await createAndFundKeypair(fundingSource, 2n * DOLLARS, 'delegatorKeys');
655+
const delegatorKeys = createKeys('delegatorKeys');
674656

675-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, 1n * DOLLARS));
657+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, 1n * DOLLARS));
676658

677659
// Add new key
678660
const newKeyPayload: AddKeyData = await generateAddKeyPayload({
@@ -688,16 +670,12 @@ describe('Capacity Transactions', function () {
688670
const { target: publicKeyEvent } = await addPublicKeyOp.fundAndSend(fundingSource);
689671
assert.notEqual(publicKeyEvent, undefined, 'should have added public key');
690672

691-
const createMsaOp = ExtrinsicHelper.createMsa(delegatorKeys);
692-
const { target: MsaCreatedEvent } = await createMsaOp.fundAndSend(fundingSource);
693-
assert.notEqual(MsaCreatedEvent, undefined, 'should have returned MsaCreated event');
694-
695673
const payload = await generateDelegationPayload({
696674
authorizedMsaId: capacityProvider,
697675
schemaIds: [schemaId],
698676
});
699677
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', payload);
700-
const grantDelegationOp = ExtrinsicHelper.grantDelegation(
678+
const grantDelegationOp = ExtrinsicHelper.createSponsoredAccountWithDelegation(
701679
delegatorKeys,
702680
noTokensKeys,
703681
signPayloadSr25519(delegatorKeys, addProviderData),
@@ -802,7 +780,7 @@ describe('Capacity Transactions', function () {
802780
});
803781

804782
it('successfully pays with Capacity for a batch of eligible transactions - [createSponsoredAccountWithDelegation, claimHandle]', async function () {
805-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityProviderKeys, capacityProvider, amountStaked));
783+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked));
806784

807785
const addProviderPayload = await generateDelegationPayload({ ...defaultPayload });
808786
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload);
@@ -848,7 +826,7 @@ describe('Capacity Transactions', function () {
848826
});
849827

850828
it('batch fails if one transaction fails - [createSponsoredAccountWithDelegation, claimHandle]', async function () {
851-
await assert.doesNotReject(stakeToProvider(fundingSource, capacityProviderKeys, capacityProvider, amountStaked));
829+
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked));
852830

853831
const addProviderPayload = await generateDelegationPayload({ ...defaultPayload });
854832
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload);

e2e/scaffolding/extrinsicHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export interface ParsedEventResult<C extends Codec[] = Codec[], N = unknown> {
163163

164164
export class Extrinsic<N = unknown, T extends ISubmittableResult = ISubmittableResult, C extends Codec[] = Codec[]> {
165165
private event?: IsEvent<C, N>;
166-
private extrinsic: () => SubmittableExtrinsic<'rxjs', T>;
166+
public readonly extrinsic: () => SubmittableExtrinsic<'rxjs', T>;
167167
private keys: KeyringPair;
168168
public api: ApiRx;
169169

e2e/scaffolding/helpers.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,22 @@ export async function createMsaAndProvider(
390390
providerName: string,
391391
amount: bigint | undefined = undefined
392392
): Promise<u64> {
393+
const createMsaOp = ExtrinsicHelper.createMsa(keys);
394+
const createProviderOp = ExtrinsicHelper.createProvider(keys, providerName);
395+
const minimumFund = (
396+
await Promise.all([getExistentialDeposit(), createMsaOp.getEstimatedTxFee(), createProviderOp.getEstimatedTxFee()])
397+
).reduce((i, j) => i + j, 100_000n);
393398
// Create and fund a keypair with stakeAmount
394399
// Use this keypair for stake operations
395-
await fundKeypair(source, keys, amount || (await getExistentialDeposit()));
396-
const createMsaOp = ExtrinsicHelper.createMsa(keys);
397-
const { target: MsaCreatedEvent } = await createMsaOp.fundAndSend(source);
398-
assert.notEqual(MsaCreatedEvent, undefined, 'createMsaAndProvider: should have returned MsaCreated event');
400+
await fundKeypair(source, keys, amount || minimumFund);
399401

400-
const createProviderOp = ExtrinsicHelper.createProvider(keys, providerName);
401-
const { target: providerCreatedEvent } = await createProviderOp.fundAndSend(source);
402-
assert.notEqual(providerCreatedEvent, undefined, 'createMsaAndProvider: should have returned ProviderCreated event');
402+
const { eventMap } = await ExtrinsicHelper.executeUtilityBatchAll(keys, [
403+
createMsaOp.extrinsic(),
404+
createProviderOp.extrinsic(),
405+
]).signAndSend();
403406

404-
if (providerCreatedEvent) {
407+
const providerCreatedEvent = eventMap['msa.ProviderCreated'];
408+
if (ExtrinsicHelper.api.events.msa.ProviderCreated.is(providerCreatedEvent)) {
405409
return providerCreatedEvent.data.providerId;
406410
}
407411
return Promise.reject('Did not create provider with msa.ProviderCreated event');

0 commit comments

Comments
 (0)