-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E tests: split transactions test and use more before all instead of…
… beforeEach (#2190) # Goal The goal of this PR is to clean up some some small things about the e2e tests Part of #2154 # Discussion - Reduce the number of per test transactions by moving some `beforeEach` actions to the `before` all - Add some additional comments and logs for debugging errors - Split up the transaction.test.ts file for parallelization # Testing `make e2e-tests`
- Loading branch information
Showing
6 changed files
with
162 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import '@frequency-chain/api-augment'; | ||
import { KeyringPair } from '@polkadot/keyring/types'; | ||
import { Bytes, u64, u16 } from '@polkadot/types'; | ||
import { u8aToHex } from '@polkadot/util/u8a/toHex'; | ||
import { u8aWrapBytes } from '@polkadot/util'; | ||
import assert from 'assert'; | ||
import { AddProviderPayload, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers'; | ||
import { | ||
createKeys, | ||
createMsaAndProvider, | ||
generateDelegationPayload, | ||
getBlockNumber, | ||
signPayloadSr25519, | ||
stakeToProvider, | ||
DOLLARS, | ||
getTestHandle, | ||
} from '../scaffolding/helpers'; | ||
import { getFundingSource } from '../scaffolding/funding'; | ||
|
||
const FUNDS_AMOUNT: bigint = 50n * DOLLARS; | ||
const fundingSource = getFundingSource('capacity-transactions-batch'); | ||
|
||
describe('Capacity Transactions Batch', function () { | ||
describe('pay_with_capacity_batch_all', function () { | ||
let capacityProviderKeys: KeyringPair; | ||
let capacityProvider: u64; | ||
let schemaId: u16; | ||
let defaultPayload: AddProviderPayload; | ||
const amountStaked = 9n * DOLLARS; | ||
|
||
beforeEach(async function () { | ||
capacityProviderKeys = createKeys('CapacityProviderKeys'); | ||
capacityProvider = await createMsaAndProvider( | ||
fundingSource, | ||
capacityProviderKeys, | ||
'CapacityProvider', | ||
FUNDS_AMOUNT | ||
); | ||
defaultPayload = { | ||
authorizedMsaId: capacityProvider, | ||
schemaIds: [schemaId], | ||
}; | ||
}); | ||
|
||
it('successfully pays with Capacity for a batch of eligible transactions - [createSponsoredAccountWithDelegation, claimHandle]', async function () { | ||
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked)); | ||
|
||
const addProviderPayload = await generateDelegationPayload({ ...defaultPayload }); | ||
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload); | ||
const delegatorKeys = createKeys('delegatorKeys'); | ||
const createSponsoredAccountWithDelegation = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation( | ||
delegatorKeys.publicKey, | ||
signPayloadSr25519(delegatorKeys, addProviderData), | ||
addProviderPayload | ||
); | ||
|
||
const handle = getTestHandle(); | ||
const handle_vec = new Bytes(ExtrinsicHelper.api.registry, handle); | ||
const expiration = (await getBlockNumber()) + 5; | ||
const handlePayload = { | ||
baseHandle: handle_vec, | ||
expiration: expiration, | ||
}; | ||
const claimHandlePayload: any = ExtrinsicHelper.api.registry.createType( | ||
'CommonPrimitivesHandlesClaimHandlePayload', | ||
handlePayload | ||
); | ||
const claimHandleProof = { | ||
Sr25519: u8aToHex(delegatorKeys.sign(u8aWrapBytes(claimHandlePayload.toU8a()))), | ||
}; | ||
|
||
const claimHandle = ExtrinsicHelper.api.tx.handles.claimHandle( | ||
delegatorKeys.publicKey, | ||
claimHandleProof, | ||
claimHandlePayload | ||
); | ||
const calls = [createSponsoredAccountWithDelegation, claimHandle]; | ||
|
||
const payWithCapacityBatchAllOp = ExtrinsicHelper.payWithCapacityBatchAll(capacityProviderKeys, calls); | ||
|
||
const { target: batchCompletedEvent, eventMap } = await payWithCapacityBatchAllOp.signAndSend(); | ||
|
||
if (batchCompletedEvent && !ExtrinsicHelper.api.events.utility.BatchCompleted.is(batchCompletedEvent)) { | ||
assert.fail('should return a BatchCompletedEvent'); | ||
} | ||
|
||
assert.notEqual(eventMap['msa.DelegationGranted'], undefined, 'should have returned DelegationGranted event'); | ||
assert.notEqual(eventMap['handles.HandleClaimed'], undefined, 'should have returned HandleClaimed event'); | ||
}); | ||
|
||
it('batch fails if one transaction fails - [createSponsoredAccountWithDelegation, claimHandle]', async function () { | ||
await assert.doesNotReject(stakeToProvider(fundingSource, fundingSource, capacityProvider, amountStaked)); | ||
|
||
const addProviderPayload = await generateDelegationPayload({ ...defaultPayload }); | ||
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload); | ||
const delegatorKeys = createKeys('delegatorKeys'); | ||
const createSponsoredAccountWithDelegation = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation( | ||
delegatorKeys.publicKey, | ||
signPayloadSr25519(delegatorKeys, addProviderData), | ||
addProviderPayload | ||
); | ||
|
||
const handle = 'test_handle_that_exceeds_the_byte_limit'; | ||
const handle_vec = new Bytes(ExtrinsicHelper.api.registry, handle); | ||
const expiration = (await getBlockNumber()) + 5; | ||
const handlePayload = { | ||
baseHandle: handle_vec, | ||
expiration: expiration, | ||
}; | ||
const claimHandlePayload: any = ExtrinsicHelper.api.registry.createType( | ||
'CommonPrimitivesHandlesClaimHandlePayload', | ||
handlePayload | ||
); | ||
const calimHandleProof = { | ||
Sr25519: u8aToHex(delegatorKeys.sign(u8aWrapBytes(claimHandlePayload.toU8a()))), | ||
}; | ||
|
||
const claimHandle = ExtrinsicHelper.api.tx.handles.claimHandle( | ||
delegatorKeys.publicKey, | ||
calimHandleProof, | ||
claimHandlePayload | ||
); | ||
const calls = [createSponsoredAccountWithDelegation, claimHandle]; | ||
|
||
const payWithCapacityBatchAllOp = ExtrinsicHelper.payWithCapacityBatchAll(capacityProviderKeys, calls); | ||
|
||
await assert.rejects(payWithCapacityBatchAllOp.signAndSend(), { | ||
name: 'InvalidHandleByteLength', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters