@@ -71,7 +71,7 @@ describe('Capacity Transactions', function () {
71
71
const capacityKeys = createKeys ( 'CapacityKeysNSF' ) ;
72
72
const capacityProvider = await createMsaAndProvider ( fundingSource , capacityKeys , 'CapProvNSF' , FUNDS_AMOUNT ) ;
73
73
// 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 ) ) ;
75
75
76
76
// As current owner, add a new set of control keys that do not have a balance.
77
77
const newControlKeypair = createKeys ( 'NewKeyNoBalance' ) ;
@@ -112,7 +112,7 @@ describe('Capacity Transactions', function () {
112
112
capacityKeys = createKeys ( 'CapacityKeys' ) ;
113
113
capacityProvider = await createMsaAndProvider ( fundingSource , capacityKeys , 'CapacityProvider' , FUNDS_AMOUNT ) ;
114
114
// Stake enough for all transactions
115
- await assert . doesNotReject ( stakeToProvider ( fundingSource , capacityKeys , capacityProvider , stakedForMsa ) ) ;
115
+ await assert . doesNotReject ( stakeToProvider ( fundingSource , fundingSource , capacityProvider , stakedForMsa ) ) ;
116
116
} ) ;
117
117
118
118
beforeEach ( async function ( ) {
@@ -204,7 +204,7 @@ describe('Capacity Transactions', function () {
204
204
beforeEach ( async function ( ) {
205
205
starting_block = ( await ExtrinsicHelper . apiPromise . rpc . chain . getHeader ( ) ) . number . toNumber ( ) ;
206
206
// 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 ) ) ;
208
208
} ) ;
209
209
210
210
it ( 'successfully pays with Capacity for eligible transaction - addIPFSMessage' , async function ( ) {
@@ -245,11 +245,15 @@ describe('Capacity Transactions', function () {
245
245
before ( async function ( ) {
246
246
capacityKeys = createKeys ( 'CapacityKeys' ) ;
247
247
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' ) ;
248
252
} ) ;
249
253
250
254
beforeEach ( async function ( ) {
251
255
// 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 ) ) ;
253
257
} ) ;
254
258
255
259
it ( 'successfully pays with Capacity for eligible transaction - applyItemActions' , async function ( ) {
@@ -317,11 +321,6 @@ describe('Capacity Transactions', function () {
317
321
// Create a schema for Itemized PayloadLocation
318
322
const itemizedSchemaId : SchemaId = await getOrCreateAvroChatMessageItemizedSchema ( fundingSource ) ;
319
323
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
-
325
324
// Add and update actions
326
325
const payload_1 = new Bytes ( ExtrinsicHelper . api . registry , 'Hello World From Frequency' ) ;
327
326
const add_action = {
@@ -366,11 +365,6 @@ describe('Capacity Transactions', function () {
366
365
// Create a schema for Itemized PayloadLocation
367
366
const itemizedSchemaId : SchemaId = await getOrCreateAvroChatMessageItemizedSchema ( fundingSource ) ;
368
367
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
-
374
368
// Add and update actions
375
369
const payload_1 = new Bytes ( ExtrinsicHelper . api . registry , 'Hello World From Frequency' ) ;
376
370
const add_action = {
@@ -413,11 +407,6 @@ describe('Capacity Transactions', function () {
413
407
it ( 'successfully pays with Capacity for eligible transaction - upsertPageWithSignature; deletePageWithSignature' , async function ( ) {
414
408
const paginatedSchemaId : SchemaId = await getOrCreateAvroChatMessagePaginatedSchema ( fundingSource ) ;
415
409
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
-
421
410
const page_id = new u16 ( ExtrinsicHelper . api . registry , 1 ) ;
422
411
423
412
// Add and update actions
@@ -480,11 +469,6 @@ describe('Capacity Transactions', function () {
480
469
it ( 'successfully pays with Capacity for eligible transaction - upsertPageWithSignatureV2; deletePageWithSignatureV2' , async function ( ) {
481
470
const paginatedSchemaId : SchemaId = await getOrCreateAvroChatMessagePaginatedSchema ( fundingSource ) ;
482
471
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
-
488
472
const page_id = new u16 ( ExtrinsicHelper . api . registry , 1 ) ;
489
473
490
474
// Add and update actions
@@ -553,7 +537,7 @@ describe('Capacity Transactions', function () {
553
537
} ) ;
554
538
555
539
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 ) ) ;
557
541
558
542
const handle = getTestHandle ( ) ;
559
543
const expiration = ( await getBlockNumber ( ) ) + 10 ;
@@ -583,7 +567,7 @@ describe('Capacity Transactions', function () {
583
567
capacityProvider = await createMsaAndProvider ( fundingSource , capacityKeys , 'CapacityProvider' , FUNDS_AMOUNT ) ;
584
568
} ) ;
585
569
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 ( ) {
587
571
await assert . doesNotReject ( stakeToProvider ( fundingSource , capacityKeys , capacityProvider , amountStaked ) ) ;
588
572
// Empty the account to ensure the balance is less than ED
589
573
await ExtrinsicHelper . emptyAccount ( capacityKeys , fundingSource . address ) . signAndSend ( ) ;
@@ -640,19 +624,17 @@ describe('Capacity Transactions', function () {
640
624
// and is NOT eligible to replenish Capacity, it should error and be dropped
641
625
// from the transaction pool.
642
626
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 ) ;
645
627
const noCapacityKeys = createKeys ( 'noCapacityKeys' ) ;
646
- const _providerId = await createMsaAndProvider ( fundingSource , noCapacityKeys , 'NoCapProvider' ) ;
628
+ const noCapacityProvider = await createMsaAndProvider ( fundingSource , noCapacityKeys , 'NoCapProvider' ) ;
647
629
648
630
const delegatorKeys = createKeys ( 'delegatorKeys' ) ;
649
631
650
632
const payload = await generateDelegationPayload ( {
651
- authorizedMsaId : capacityProvider ,
633
+ authorizedMsaId : noCapacityProvider ,
652
634
schemaIds : [ schemaId ] ,
653
635
} ) ;
654
636
const addProviderData = ExtrinsicHelper . api . registry . createType ( 'PalletMsaAddProvider' , payload ) ;
655
- const grantDelegationOp = ExtrinsicHelper . grantDelegation (
637
+ const grantDelegationOp = ExtrinsicHelper . createSponsoredAccountWithDelegation (
656
638
delegatorKeys ,
657
639
noCapacityKeys ,
658
640
signPayloadSr25519 ( noCapacityKeys , addProviderData ) ,
@@ -670,9 +652,9 @@ describe('Capacity Transactions', function () {
670
652
const capacityKeys = createKeys ( 'CapKeysUnder' ) ;
671
653
const capacityProvider = await createMsaAndProvider ( fundingSource , capacityKeys , 'CapProvUnder' , FUNDS_AMOUNT ) ;
672
654
const noTokensKeys = createKeys ( 'noTokensKeys' ) ;
673
- const delegatorKeys = await createAndFundKeypair ( fundingSource , 2n * DOLLARS , 'delegatorKeys' ) ;
655
+ const delegatorKeys = createKeys ( 'delegatorKeys' ) ;
674
656
675
- await assert . doesNotReject ( stakeToProvider ( fundingSource , capacityKeys , capacityProvider , 1n * DOLLARS ) ) ;
657
+ await assert . doesNotReject ( stakeToProvider ( fundingSource , fundingSource , capacityProvider , 1n * DOLLARS ) ) ;
676
658
677
659
// Add new key
678
660
const newKeyPayload : AddKeyData = await generateAddKeyPayload ( {
@@ -688,16 +670,12 @@ describe('Capacity Transactions', function () {
688
670
const { target : publicKeyEvent } = await addPublicKeyOp . fundAndSend ( fundingSource ) ;
689
671
assert . notEqual ( publicKeyEvent , undefined , 'should have added public key' ) ;
690
672
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
-
695
673
const payload = await generateDelegationPayload ( {
696
674
authorizedMsaId : capacityProvider ,
697
675
schemaIds : [ schemaId ] ,
698
676
} ) ;
699
677
const addProviderData = ExtrinsicHelper . api . registry . createType ( 'PalletMsaAddProvider' , payload ) ;
700
- const grantDelegationOp = ExtrinsicHelper . grantDelegation (
678
+ const grantDelegationOp = ExtrinsicHelper . createSponsoredAccountWithDelegation (
701
679
delegatorKeys ,
702
680
noTokensKeys ,
703
681
signPayloadSr25519 ( delegatorKeys , addProviderData ) ,
@@ -802,7 +780,7 @@ describe('Capacity Transactions', function () {
802
780
} ) ;
803
781
804
782
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 ) ) ;
806
784
807
785
const addProviderPayload = await generateDelegationPayload ( { ...defaultPayload } ) ;
808
786
const addProviderData = ExtrinsicHelper . api . registry . createType ( 'PalletMsaAddProvider' , addProviderPayload ) ;
@@ -848,7 +826,7 @@ describe('Capacity Transactions', function () {
848
826
} ) ;
849
827
850
828
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 ) ) ;
852
830
853
831
const addProviderPayload = await generateDelegationPayload ( { ...defaultPayload } ) ;
854
832
const addProviderData = ExtrinsicHelper . api . registry . createType ( 'PalletMsaAddProvider' , addProviderPayload ) ;
0 commit comments