-
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
More e2e Cleanups and Improvements #1756
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83cc656
Serialize BigInts for Mocha
wilwade 8dc3534
getCapacity and DrainCapacity Improvements
wilwade 579d388
Replace the rxjs with the apiPromise for rpc and state queries
wilwade e5c1e81
createMsa helper for invalid MSAs
wilwade 5699b16
Test handles for > 90 runs
wilwade ec79cc5
Staking calls should always use signAndSend
wilwade bf0648a
Move some msa tests into a separate file
wilwade 8cfaf3e
Correctly name time release test
wilwade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,8 @@ import { | |
createKeys, createMsaAndProvider, | ||
stakeToProvider, | ||
getNextEpochBlock, TEST_EPOCH_LENGTH, | ||
CENTS, DOLLARS, createAndFundKeypair | ||
} | ||
from "../scaffolding/helpers"; | ||
import { firstValueFrom } from "rxjs"; | ||
CENTS, DOLLARS, createAndFundKeypair, getCapacity, createMsa | ||
} from "../scaffolding/helpers"; | ||
import { isDev } from "../scaffolding/env"; | ||
import { getFundingSource } from "../scaffolding/funding"; | ||
|
||
|
@@ -45,7 +43,7 @@ describe("Capacity Staking Tests", function () { | |
assert.equal(stakedAcctInfo.data.frozen, tokenMinStake, `expected ${tokenMinStake} frozen balance, got ${stakedAcctInfo.data.frozen}`) | ||
|
||
// Confirm that the capacity was added to the stakeProviderId using the query API | ||
const capacityStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const capacityStaked = await getCapacity(stakeProviderId); | ||
assert.equal(capacityStaked.remainingCapacity, capacityMin, `expected capacityLedger.remainingCapacity = 1CENT, got ${capacityStaked.remainingCapacity}`); | ||
assert.equal(capacityStaked.totalTokensStaked, tokenMinStake, `expected capacityLedger.totalTokensStaked = 1CENT, got ${capacityStaked.totalTokensStaked}`); | ||
assert.equal(capacityStaked.totalCapacityIssued, capacityMin, `expected capacityLedger.totalCapacityIssued = 1CENT, got ${capacityStaked.totalCapacityIssued}`); | ||
|
@@ -54,12 +52,12 @@ describe("Capacity Staking Tests", function () { | |
|
||
it("successfully unstakes the minimum amount", async function () { | ||
const stakeObj = ExtrinsicHelper.unstake(stakeKeys, stakeProviderId, tokenMinStake); | ||
const { target: unStakeEvent } = await stakeObj.fundAndSend(fundingSource); | ||
const { target: unStakeEvent } = await stakeObj.signAndSend(); | ||
assert.notEqual(unStakeEvent, undefined, "should return an UnStaked event"); | ||
assert.equal(unStakeEvent?.data.capacity, capacityMin, "should return an UnStaked event with 1 CENT reduced capacity"); | ||
|
||
// Confirm that the tokens were unstaked in the stakeProviderId account using the query API | ||
const capacityStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const capacityStaked = await getCapacity(stakeProviderId); | ||
assert.equal(capacityStaked.remainingCapacity, 0, "should return a capacityLedger with 0 remainingCapacity"); | ||
assert.equal(capacityStaked.totalTokensStaked, 0, "should return a capacityLedger with 0 total tokens staked"); | ||
assert.equal(capacityStaked.totalCapacityIssued, 0, "should return a capacityLedger with 0 capacity issued"); | ||
|
@@ -76,7 +74,7 @@ describe("Capacity Staking Tests", function () { | |
await ExtrinsicHelper.runToBlock(newEpochBlock + TEST_EPOCH_LENGTH + 1); | ||
|
||
const withdrawObj = ExtrinsicHelper.withdrawUnstaked(stakeKeys); | ||
const { target: withdrawEvent } = await withdrawObj.fundAndSend(fundingSource); | ||
const { target: withdrawEvent } = await withdrawObj.signAndSend(); | ||
assert.notEqual(withdrawEvent, undefined, "should return a StakeWithdrawn event"); | ||
|
||
const amount = withdrawEvent!.data.amount; | ||
|
@@ -87,7 +85,7 @@ describe("Capacity Staking Tests", function () { | |
assert.equal(unStakedAcctInfo.data.frozen, 0, "should return an account with 0 frozen balance") | ||
|
||
// Confirm that the staked capacity was removed from the stakeProviderId account using the query API | ||
const capacityStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const capacityStaked = await getCapacity(stakeProviderId); | ||
assert.equal(capacityStaked.remainingCapacity, 0, "should return a capacityLedger with 0 remainingCapacity"); | ||
assert.equal(capacityStaked.totalTokensStaked, 0, "should return a capacityLedger with 0 total tokens staked"); | ||
assert.equal(capacityStaked.totalCapacityIssued, 0, "should return a capacityLedger with 0 capacity issued"); | ||
|
@@ -99,7 +97,7 @@ describe("Capacity Staking Tests", function () { | |
it("successfully increases the amount that was targeted to provider", async function () { | ||
await assert.doesNotReject(stakeToProvider(fundingSource, stakeKeys, stakeProviderId, tokenMinStake)); | ||
|
||
const capacityStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const capacityStaked = await getCapacity(stakeProviderId); | ||
assert.equal(capacityStaked.remainingCapacity, capacityMin, | ||
`expected capacityStaked.remainingCapacity = ${capacityMin}, got ${capacityStaked.remainingCapacity}`); | ||
assert.equal(capacityStaked.totalTokensStaked, tokenMinStake, | ||
|
@@ -135,13 +133,13 @@ describe("Capacity Staking Tests", function () { | |
// Confirm that the staked capacity of the original stakeProviderId account is unchanged | ||
// stakeProviderId should still have 1M from first test case in this describe. | ||
// otherProvider should now have 1M | ||
const origStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const origStaked = await getCapacity(stakeProviderId); | ||
assert.equal(origStaked.remainingCapacity, expectedCapacity, `expected 1/50 CENT remaining capacity, got ${origStaked.remainingCapacity}`); | ||
assert.equal(origStaked.totalTokensStaked, 1n * CENTS, `expected 1 CENT staked, got ${origStaked.totalTokensStaked}`); | ||
assert.equal(origStaked.totalCapacityIssued, expectedCapacity, `expected 1/50 CENT capacity issued, got ${origStaked.totalCapacityIssued}`); | ||
|
||
// Confirm that the staked capacity was added to the otherProviderId account using the query API | ||
const capacityStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(otherProviderId))).unwrap(); | ||
const capacityStaked = await getCapacity(otherProviderId); | ||
assert.equal(capacityStaked.remainingCapacity, expectedCapacity, "should return a capacityLedger with 1/50M remainingCapacity"); | ||
assert.equal(capacityStaked.totalTokensStaked, 1n * CENTS, "should return a capacityLedger with 1M total tokens staked"); | ||
assert.equal(capacityStaked.totalCapacityIssued, expectedCapacity, "should return a capacityLedger with 1/50M capacity issued"); | ||
|
@@ -153,11 +151,11 @@ describe("Capacity Staking Tests", function () { | |
|
||
// get the current account info | ||
let currentAcctInfo = await ExtrinsicHelper.getAccountInfo(additionalKeys.address); | ||
const currentStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const currentStaked = await getCapacity(stakeProviderId); | ||
|
||
await assert.doesNotReject(stakeToProvider(fundingSource, additionalKeys, stakeProviderId, tokenMinStake)); | ||
|
||
const capacityStaked = (await firstValueFrom(ExtrinsicHelper.api.query.capacity.capacityLedger(stakeProviderId))).unwrap(); | ||
const capacityStaked = await getCapacity(stakeProviderId); | ||
assert.equal( | ||
capacityStaked.remainingCapacity, | ||
currentStaked.remainingCapacity.toBigInt() + capacityMin, | ||
|
@@ -189,13 +187,13 @@ describe("Capacity Staking Tests", function () { | |
|
||
describe("when staking and targeting an InvalidTarget", async function () { | ||
it("fails to stake", async function () { | ||
const maxMsaId = (await ExtrinsicHelper.getCurrentMsaIdentifierMaximum()).toNumber(); | ||
|
||
const stakeAmount = 10n * CENTS; | ||
const stakeKeys = await createAndFundKeypair(fundingSource, stakeAmount + 1n, "StakeKeys"); | ||
const stakeKeys = await createAndFundKeypair(fundingSource, accountBalance, "StakeKeys"); | ||
|
||
const [notProviderMsaId] = await createMsa(fundingSource); | ||
|
||
const failStakeObj = ExtrinsicHelper.stake(stakeKeys, maxMsaId + 1, stakeAmount); | ||
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. Because this test is running in parallel, it cannot just use maxMsaId + 1 as other msas are being created and might be providers. |
||
await assert.rejects(failStakeObj.fundAndSend(fundingSource), { name: "InvalidTarget" }); | ||
const failStakeObj = ExtrinsicHelper.stake(stakeKeys, notProviderMsaId, stakeAmount); | ||
await assert.rejects(failStakeObj.signAndSend(), { name: "InvalidTarget" }); | ||
}); | ||
}); | ||
|
||
|
@@ -206,28 +204,28 @@ describe("Capacity Staking Tests", function () { | |
let stakeAmount = 1500n; | ||
|
||
const failStakeObj = ExtrinsicHelper.stake(stakingKeys, providerId, stakeAmount); | ||
await assert.rejects(failStakeObj.fundAndSend(fundingSource), { name: "InsufficientStakingAmount" }); | ||
await assert.rejects(failStakeObj.signAndSend(), { name: "InsufficientStakingAmount" }); | ||
}); | ||
}); | ||
|
||
describe("when attempting to stake a zero amount", async function () { | ||
it("fails to stake and errors ZeroAmountNotAllowed", async function () { | ||
let stakingKeys = createKeys("stakingKeys"); | ||
let providerId = await createMsaAndProvider(fundingSource, stakingKeys, "stakingKeys", ); | ||
let providerId = await createMsaAndProvider(fundingSource, stakingKeys, "stakingKeys", 10n * CENTS); | ||
|
||
const failStakeObj = ExtrinsicHelper.stake(stakingKeys, providerId, 0); | ||
await assert.rejects(failStakeObj.fundAndSend(fundingSource), { name: "ZeroAmountNotAllowed" }); | ||
await assert.rejects(failStakeObj.signAndSend(), { name: "ZeroAmountNotAllowed" }); | ||
}); | ||
}); | ||
|
||
describe("when staking an amount and account balance is too low", async function () { | ||
it("fails to stake and errors BalanceTooLowtoStake", async function () { | ||
let stakingKeys = createKeys("stakingKeys"); | ||
let providerId = await createMsaAndProvider(fundingSource, stakingKeys, "stakingKeys"); | ||
let providerId = await createMsaAndProvider(fundingSource, stakingKeys, "stakingKeys", 10n * CENTS); | ||
let stakingAmount = 1n * DOLLARS; | ||
|
||
const failStakeObj = ExtrinsicHelper.stake(stakingKeys, providerId, stakingAmount); | ||
await assert.rejects(failStakeObj.fundAndSend(fundingSource), { name: "BalanceTooLowtoStake" }); | ||
await assert.rejects(failStakeObj.signAndSend(), { name: "BalanceTooLowtoStake" }); | ||
}); | ||
}); | ||
|
||
|
@@ -245,14 +243,14 @@ describe("Capacity Staking Tests", function () { | |
describe("when attempting to unstake a Zero amount", async function () { | ||
it("errors with UnstakedAmountIsZero", async function () { | ||
const failUnstakeObj = ExtrinsicHelper.unstake(unstakeKeys, providerId, 0); | ||
await assert.rejects(failUnstakeObj.fundAndSend(fundingSource), { name: "UnstakedAmountIsZero" }); | ||
await assert.rejects(failUnstakeObj.signAndSend(), { name: "UnstakedAmountIsZero" }); | ||
}); | ||
}) | ||
|
||
describe("when account has not staked", async function () { | ||
it("errors with StakingAccountNotFound", async function () { | ||
const failUnstakeObj = ExtrinsicHelper.unstake(unstakeKeys, providerId, tokenMinStake); | ||
await assert.rejects(failUnstakeObj.fundAndSend(fundingSource), { name: "NotAStakingAccount" }); | ||
await assert.rejects(failUnstakeObj.signAndSend(), { name: "NotAStakingAccount" }); | ||
}); | ||
}); | ||
}); | ||
|
@@ -264,11 +262,11 @@ describe("Capacity Staking Tests", function () { | |
let providerId: u64 = await createMsaAndProvider(fundingSource, stakingKeys, "stakingKeys", accountBalance); | ||
|
||
const stakeObj = ExtrinsicHelper.stake(stakingKeys, providerId, tokenMinStake); | ||
const { target: stakeEvent } = await stakeObj.fundAndSend(fundingSource); | ||
const { target: stakeEvent } = await stakeObj.signAndSend(); | ||
assert.notEqual(stakeEvent, undefined, "should return a Stake event"); | ||
|
||
const withdrawObj = ExtrinsicHelper.withdrawUnstaked(stakingKeys); | ||
await assert.rejects(withdrawObj.fundAndSend(fundingSource), { name: "NoUnstakedTokensAvailable" }); | ||
await assert.rejects(withdrawObj.signAndSend(), { name: "NoUnstakedTokensAvailable" }); | ||
}); | ||
}) | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice, I didn't know you could do that.