-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E2E Testing fixes and cleanup #1765
Changes from all commits
eac7df1
87b2c0d
855da00
448d6a1
fb506b3
d7d283f
fef2fdb
59e8fec
1d1466a
fe9372b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,9 @@ import { | |
generatePaginatedUpsertSignaturePayloadV2, | ||
generatePaginatedDeleteSignaturePayloadV2, | ||
getCapacity, | ||
getTestHandle | ||
getTestHandle, | ||
assertHasMessage, | ||
assertAddNewKey | ||
} from "../scaffolding/helpers"; | ||
import { FeeDetails } from "@polkadot/types/interfaces"; | ||
import { ipfsCid } from "../messages/ipfs"; | ||
|
@@ -60,16 +62,6 @@ describe("Capacity Transactions", function () { | |
assert.notEqual(schemaId, undefined, "setup should populate schemaId"); | ||
}); | ||
|
||
async function assertAddNewKey(capacityKeys: KeyringPair, addKeyPayload: AddKeyData, newControlKeypair: KeyringPair) { | ||
const addKeyPayloadCodec: Codec = ExtrinsicHelper.api.registry.createType("PalletMsaAddKeyData", addKeyPayload); | ||
const ownerSig: Sr25519Signature = signPayloadSr25519(capacityKeys, addKeyPayloadCodec); | ||
const newSig: Sr25519Signature = signPayloadSr25519(newControlKeypair, addKeyPayloadCodec); | ||
const addPublicKeyOp = ExtrinsicHelper.addPublicKeyToMsa(capacityKeys, ownerSig, newSig, addKeyPayload); | ||
const { eventMap } = await addPublicKeyOp.signAndSend(); | ||
assertEvent(eventMap, "system.ExtrinsicSuccess"); | ||
assertEvent(eventMap, "msa.PublicKeyAdded"); | ||
} | ||
|
||
function getCapacityFee(chainEvents: EventMap): bigint { | ||
if (chainEvents["capacity.CapacityWithdrawn"] && | ||
ExtrinsicHelper.api.events.capacity.CapacityWithdrawn.is(chainEvents["capacity.CapacityWithdrawn"])) { | ||
|
@@ -118,6 +110,7 @@ describe("Capacity Transactions", function () { | |
before(async function () { | ||
capacityKeys = createKeys("CapacityKeys"); | ||
capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, "CapacityProvider", FUNDS_AMOUNT); | ||
// Stake enough for all transactions | ||
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, stakedForMsa)); | ||
}) | ||
|
||
|
@@ -186,11 +179,11 @@ describe("Capacity Transactions", function () { | |
assertEvent(eventMap, "capacity.CapacityWithdrawn"); | ||
assertEvent(eventMap, "msa.DelegationGranted"); | ||
|
||
let fee = getCapacityFee(eventMap); | ||
const fee = getCapacityFee(eventMap); | ||
// assuming no other txns charged against capacity (b/c of async tests), this should be the maximum amount left. | ||
const maximumExpectedRemaining = stakedForMsa / TokenPerCapacity - fee | ||
|
||
let remaining = capacityStaked.remainingCapacity.toBigInt(); | ||
const remaining = capacityStaked.remainingCapacity.toBigInt(); | ||
assert(remaining <= maximumExpectedRemaining, `expected ${remaining} to be <= ${maximumExpectedRemaining}`); | ||
assert.equal(capacityStaked.totalTokensStaked.toBigInt(), stakedForMsa); | ||
assert.equal(capacityStaked.totalCapacityIssued.toBigInt(), stakedForMsa / TokenPerCapacity); | ||
|
@@ -209,6 +202,7 @@ describe("Capacity Transactions", function () { | |
|
||
beforeEach(async function () { | ||
starting_block = (await ExtrinsicHelper.apiPromise.rpc.chain.getHeader()).number.toNumber(); | ||
// Stake each time so that we always have enough capacity to do the call | ||
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked)); | ||
}); | ||
|
||
|
@@ -240,8 +234,7 @@ describe("Capacity Transactions", function () { | |
page_size: 999 | ||
} | ||
); | ||
const response: MessageResponse = get.content[get.content.length - 1]; | ||
assert.equal(response.payload, "0xdeadbeef", "payload should be 0xdeadbeef"); | ||
assertHasMessage(get, x => x.payload.isSome && x.payload.toString() === "0xdeadbeef"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New Helper |
||
}); | ||
}); | ||
|
||
|
@@ -254,8 +247,10 @@ describe("Capacity Transactions", function () { | |
before(async function () { | ||
capacityKeys = createKeys("CapacityKeys"); | ||
capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, "CapacityProvider", FUNDS_AMOUNT); | ||
}) | ||
}); | ||
|
||
beforeEach(async function () { | ||
// Stake each time so that we always have enough capacity to do the call | ||
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to stake before each |
||
}); | ||
|
||
|
@@ -480,7 +475,8 @@ describe("Capacity Transactions", function () { | |
before(async function () { | ||
capacityKeys = createKeys("CapacityKeys"); | ||
capacityProvider = await createMsaAndProvider(fundingSource, capacityKeys, "CapacityProvider", FUNDS_AMOUNT); | ||
}) | ||
}); | ||
|
||
it("successfully pays with Capacity for eligible transaction - claimHandle", async function () { | ||
await assert.doesNotReject(stakeToProvider(fundingSource, capacityKeys, capacityProvider, amountStaked)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import assert from "assert"; | ||
import { KeyringPair } from "@polkadot/keyring/types"; | ||
import { ExtrinsicHelper } from "../scaffolding/extrinsicHelpers"; | ||
import { createAndFundKeypair, getNonce } from "../scaffolding/helpers"; | ||
import { DOLLARS, createAndFundKeypair } from "../scaffolding/helpers"; | ||
import { ApiTypes, SubmittableExtrinsic } from "@polkadot/api/types"; | ||
import { getFundingSource } from "../scaffolding/funding"; | ||
|
||
|
@@ -11,10 +11,9 @@ describe("Utility Batch Filtering", function () { | |
|
||
const fundingSource = getFundingSource("misc-util-batch"); | ||
|
||
before(async function () { | ||
let nonce = await getNonce(fundingSource); | ||
sender = await createAndFundKeypair(fundingSource, 50_000_000n, "utility-sender", nonce++); | ||
recipient = await createAndFundKeypair(fundingSource, 50_000_000n, "utility-recipient", nonce++); | ||
beforeEach(async function () { | ||
sender = await createAndFundKeypair(fundingSource, 5n * DOLLARS, 'utility-sender'); | ||
recipient = await createAndFundKeypair(fundingSource, 5n * DOLLARS, 'utility-recipient'); | ||
}); | ||
|
||
it("should successfully execute ✅ batch with allowed calls", async function () { | ||
|
@@ -44,11 +43,10 @@ describe("Utility Batch Filtering", function () { | |
const batchAll = ExtrinsicHelper.executeUtilityBatchAll(sender, badBatch); | ||
try { | ||
await batchAll.fundAndSend(fundingSource); | ||
assert.fail("batchAll should have caused an error"); | ||
} catch (err) { | ||
error = err; | ||
assert.notEqual(error, undefined, " batchAll should return an error"); | ||
assert.notEqual(err, undefined, " batchAll should return an error"); | ||
} | ||
assert.notEqual(error, undefined, " batchAll should return an error"); | ||
Comment on lines
+46
to
-51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the best way to do an error assertion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, any objection to using Also, I wonder if at some point (not now) we should switch these to Jest (as all of our other Node projects are using it for testing)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, if we want to keep using Mocha here, I'd be in favor of eventually swapping out the standard Node There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right. Assert rejects likely would be better. I was just updating it to still match the existing pattern, but that would be better. Next time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: Jest We might be able to, but I wasn't willing to make the switch yet. |
||
}); | ||
|
||
it("should fail to execute ❌ batch with disallowed calls", async function () { | ||
|
@@ -88,44 +86,38 @@ describe("Utility Batch Filtering", function () { | |
const badBatch: SubmittableExtrinsic<ApiTypes>[] = []; | ||
badBatch.push(ExtrinsicHelper.api.tx.msa.retireMsa()) | ||
const batch = ExtrinsicHelper.executeUtilityBatchAll(sender, badBatch); | ||
let error: any; | ||
try { | ||
await batch.fundAndSend(fundingSource); | ||
assert.fail("batch should have caused an error"); | ||
} catch (err) { | ||
error = err; | ||
assert.notEqual(error, undefined, "should return an error"); | ||
assert.notEqual(err, undefined, "should return an error"); | ||
} | ||
assert.notEqual(error, undefined, "should return an error"); | ||
}); | ||
|
||
it("should fail to execute ❌ batch with `Pays::Yes` `create_provider`call blocked by Frequency", async function () { | ||
// bad batch: with frequency related Pays::Yes call | ||
const badBatch: SubmittableExtrinsic<ApiTypes>[] = []; | ||
badBatch.push(ExtrinsicHelper.api.tx.msa.createProvider("I am a ba(tch)d provider")) | ||
const batch = ExtrinsicHelper.executeUtilityBatchAll(sender, badBatch); | ||
let error: any; | ||
try { | ||
await batch.fundAndSend(fundingSource); | ||
assert.fail("batch should have caused an error"); | ||
} catch (err) { | ||
error = err; | ||
assert.notEqual(error, undefined, "should return an error"); | ||
assert.notEqual(err, undefined, "should return an error"); | ||
} | ||
assert.notEqual(error, undefined, "should return an error"); | ||
}); | ||
|
||
it("should fail to execute ❌ batch with `Pays::Yes` `create_schema` call blocked by Frequency", async function () { | ||
// bad batch: with frequency related Pays::Yes call | ||
const badBatch: SubmittableExtrinsic<ApiTypes>[] = []; | ||
badBatch.push(ExtrinsicHelper.api.tx.msa.createProvider("I am a ba(tch)d provider")) | ||
const batch = ExtrinsicHelper.executeUtilityBatchAll(sender, badBatch); | ||
let error: any; | ||
try { | ||
await batch.fundAndSend(fundingSource); | ||
assert.fail("batch should have caused an error"); | ||
} catch (err) { | ||
error = err; | ||
assert.notEqual(error, undefined, "should return an error"); | ||
assert.notEqual(err, undefined, "should return an error"); | ||
} | ||
assert.notEqual(error, undefined, "should return an error"); | ||
}); | ||
|
||
it("should fail to execute ❌ batch with nested batch", async function () { | ||
|
@@ -136,13 +128,11 @@ describe("Utility Batch Filtering", function () { | |
innerBatch.push(ExtrinsicHelper.api.tx.system.remark("Hello From Batch")) | ||
nestedBatch.push(ExtrinsicHelper.api.tx.utility.batch(innerBatch)) | ||
const batch = ExtrinsicHelper.executeUtilityBatchAll(sender, nestedBatch); | ||
let error: any; | ||
try { | ||
await batch.fundAndSend(fundingSource); | ||
assert.fail("batch should have caused an error"); | ||
} catch (err) { | ||
error = err; | ||
assert.notEqual(error, undefined, "should return an error"); | ||
assert.notEqual(err, undefined, "should return an error"); | ||
} | ||
assert.notEqual(error, undefined, "should return an error"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import { u64 } from "@polkadot/types"; | |
import { Codec } from "@polkadot/types/types"; | ||
import { getFundingSource } from "../scaffolding/funding"; | ||
|
||
const maxU64 = 18_446_744_073_709_551_615n; | ||
|
||
describe("MSA Key management", function () { | ||
const fundingSource = getFundingSource("msa-key-management"); | ||
|
||
|
@@ -75,7 +77,7 @@ describe("MSA Key management", function () { | |
it("should fail to add public key if origin does not own MSA (NotMsaOwner)", async function () { | ||
const newPayload = await generateAddKeyPayload({ | ||
...defaultPayload, | ||
msaId: new u64(ExtrinsicHelper.api.registry, 999), // If we create more than 999 MSAs in our test suites, this will fail | ||
msaId: new u64(ExtrinsicHelper.api.registry, maxU64), | ||
}); | ||
addKeyData = ExtrinsicHelper.api.registry.createType("PalletMsaAddKeyData", newPayload); | ||
ownerSig = signPayloadSr25519(keys, addKeyData); | ||
|
@@ -155,7 +157,7 @@ describe("MSA Key management", function () { | |
assert.notEqual(event, undefined, 'should have added public key'); | ||
|
||
// Cleanup | ||
await assert.doesNotReject(ExtrinsicHelper.deletePublicKey(keys, thirdKey.publicKey).signAndSend()); | ||
await assert.doesNotReject(ExtrinsicHelper.deletePublicKey(keys, thirdKey.publicKey).signAndSend('current')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important fix. |
||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to helpers