-
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.
Browse files
Browse the repository at this point in the history
# Goal The goal of this PR is to implement the `change_staking_target` extrinsic as specified in the Staking Rewards design document. The design document is updated as part of this PR to account for needed changes discovered during this implementation phase. Closes #1570
- Loading branch information
1 parent
d2614ff
commit 62fdf8c
Showing
26 changed files
with
790 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import "@frequency-chain/api-augment"; | ||
import { KeyringPair } from "@polkadot/keyring/types"; | ||
import { u64, } from "@polkadot/types"; | ||
import assert from "assert"; | ||
import { ExtrinsicHelper, } from "../scaffolding/extrinsicHelpers"; | ||
import { | ||
devAccounts, createKeys, createMsaAndProvider, | ||
stakeToProvider, CHAIN_ENVIRONMENT, | ||
TEST_EPOCH_LENGTH, setEpochLength, | ||
CENTS, DOLLARS, createAndFundKeypair, createProviderKeysAndId | ||
} | ||
from "../scaffolding/helpers"; | ||
import { firstValueFrom } from "rxjs"; | ||
import { MessageSourceId} from "@frequency-chain/api-augment/interfaces"; | ||
|
||
describe.only("change_staking_target tests", () => { | ||
const tokenMinStake: bigint = 1n * CENTS; | ||
const capacityMin: bigint = tokenMinStake / 50n; | ||
|
||
const unusedMsaId = async () => { | ||
const maxMsaId = (await ExtrinsicHelper.getCurrentMsaIdentifierMaximum()).toNumber(); | ||
return maxMsaId + 99; | ||
} | ||
|
||
before(async () => { | ||
if (process.env.CHAIN_ENVIRONMENT === CHAIN_ENVIRONMENT.DEVELOPMENT) { | ||
await setEpochLength(devAccounts[0].keys, TEST_EPOCH_LENGTH); | ||
} | ||
}); | ||
|
||
it("happy path succeeds", async () => { | ||
const providerBalance = 2n * DOLLARS; | ||
const stakeKeys = createKeys("staker"); | ||
const oldProvider = await createMsaAndProvider(stakeKeys, "Provider1", providerBalance); | ||
const [_unused, newProvider] = await createProviderKeysAndId(); | ||
|
||
await assert.doesNotReject(stakeToProvider(stakeKeys, oldProvider, tokenMinStake*3n)); | ||
|
||
const call = ExtrinsicHelper.changeStakingTarget(stakeKeys, oldProvider, newProvider, tokenMinStake); | ||
const [events] = await call.signAndSend(); | ||
assert.notEqual(events, undefined); | ||
}); | ||
|
||
// not intended to be exhaustive, just check one error case | ||
it("fails if 'to' is not a Provider", async () => { | ||
const providerBalance = 2n * DOLLARS; | ||
const stakeKeys = createKeys("staker"); | ||
const notAProvider = await unusedMsaId(); | ||
const oldProvider = await createMsaAndProvider(stakeKeys, "Provider1", providerBalance); | ||
await assert.doesNotReject(stakeToProvider(stakeKeys, oldProvider, tokenMinStake*3n)); | ||
const call = ExtrinsicHelper.changeStakingTarget(stakeKeys, oldProvider, notAProvider, tokenMinStake); | ||
await assert.rejects(call.signAndSend(), {name: "InvalidTarget"}) | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.