-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/agustin-map-slashes' into jeremy…
…-bench-slashes
- Loading branch information
Showing
6 changed files
with
300 additions
and
1 deletion.
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
84 changes: 84 additions & 0 deletions
84
test/suites/dev-tanssi-relay/slashes/test_slashes_are_acummulated_across_blocks.ts
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,84 @@ | ||
import "@tanssi/api-augment"; | ||
import { describeSuite, expect, beforeAll } from "@moonwall/cli"; | ||
import { ApiPromise } from "@polkadot/api"; | ||
import { KeyringPair, generateKeyringPair } from "@moonwall/util"; | ||
import { Keyring } from "@polkadot/keyring"; | ||
import { jumpToSession } from "../../../util/block"; | ||
import { PRIMARY_GOVERNANCE_CHANNEL_ID } from "../../../util/constants"; | ||
|
||
describeSuite({ | ||
id: "DTR1307", | ||
title: "Slashes are accumulated based on max slashes sent per block", | ||
foundationMethods: "dev", | ||
testCases: ({ it, context }) => { | ||
let polkadotJs: ApiPromise; | ||
let alice: KeyringPair; | ||
let aliceBabePair: KeyringPair; | ||
let aliceStash: KeyringPair; | ||
beforeAll(async () => { | ||
const keyringBabe = new Keyring({ type: "sr25519" }); | ||
aliceBabePair = keyringBabe.addFromUri("//Alice"); | ||
polkadotJs = context.polkadotJs(); | ||
alice = context.keyring.alice; | ||
aliceStash = keyringBabe.addFromUri("//Alice//stash"); | ||
}); | ||
it({ | ||
id: "E01", | ||
title: "Slashes are accumulated across blocks", | ||
test: async function () { | ||
// we need to start at least one sesssion to start eras | ||
await jumpToSession(context, 1); | ||
// Let's inject slashes N+1 slashes, where N is the max slashes to send per block | ||
// With force inject slash, we can inject a slash for any account | ||
const maxSlashesPerMessage = (await polkadotJs.consts.externalValidatorSlashes.queuedSlashesProcessedPerBlock).toNumber(); | ||
const slashesToInject = maxSlashesPerMessage +1; | ||
let aliceNonce = (await polkadotJs.query.system.account(alice.address)).nonce.toNumber(); | ||
|
||
for (let i = 0; i < slashesToInject; i++) { | ||
const randomAccount = generateKeyringPair("sr25519"); | ||
await polkadotJs.tx.sudo | ||
.sudo(polkadotJs.tx.externalValidatorSlashes.forceInjectSlash(0, randomAccount.address, 1000)) | ||
.signAndSend(alice, { nonce: aliceNonce++ }); | ||
} | ||
await context.createBlock(); | ||
|
||
// Slash item should be there | ||
const DeferPeriod = (await polkadotJs.consts.externalValidatorSlashes.slashDeferDuration).toNumber(); | ||
|
||
// scheduled slashes | ||
const expectedSlashes = await polkadotJs.query.externalValidatorSlashes.slashes(DeferPeriod + 1); | ||
expect(expectedSlashes.length).to.be.eq(slashesToInject); | ||
|
||
const sessionsPerEra = await polkadotJs.consts.externalValidators.sessionsPerEra; | ||
|
||
const currentIndex = await polkadotJs.query.session.currentIndex(); | ||
|
||
const targetSession = currentIndex * (sessionsPerEra * (DeferPeriod + 1)); | ||
|
||
await jumpToSession(context, targetSession); | ||
|
||
// scheduled slashes | ||
const expectedSlashesAfterDefer = await polkadotJs.query.externalValidatorSlashes.slashes( | ||
DeferPeriod + 1 | ||
); | ||
// We should have unprocessed messages | ||
const expectedUnprocessedMessages = await polkadotJs.query.externalValidatorSlashes.unreportedSlashesQueue(); | ||
expect (expectedUnprocessedMessages.length).to.be.eq(slashesToInject); | ||
expect(expectedSlashesAfterDefer.length).to.be.eq(slashesToInject); | ||
expect(expectedSlashesAfterDefer[0].confirmed.toHuman()).to.be.true; | ||
|
||
// In the next block we should send the slashes. For this we will confirm: | ||
// A: that the unprocessed slashes decrease | ||
// B: that the nonce of the primary channel increases | ||
const primaryChannelNonceBefore = await polkadotJs.query.ethereumOutboundQueue.nonce(PRIMARY_GOVERNANCE_CHANNEL_ID) | ||
|
||
await context.createBlock(); | ||
const expectedUnprocessedMessagesAfterOneBlock = await polkadotJs.query.externalValidatorSlashes.unreportedSlashesQueue(); | ||
const primaryChannelNonceAfter = await polkadotJs.query.ethereumOutboundQueue.nonce(PRIMARY_GOVERNANCE_CHANNEL_ID); | ||
expect (primaryChannelNonceAfter.toBigInt()).toBe(primaryChannelNonceBefore.toBigInt()+ 1n); | ||
// However we stil should have one unprocessed message | ||
expect (expectedUnprocessedMessagesAfterOneBlock.length).to.be.eq(1); | ||
}, | ||
}); | ||
}, | ||
}); |
88 changes: 88 additions & 0 deletions
88
test/suites/dev-tanssi-relay/slashes/test_slashes_are_acummulated_across_eras.ts
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,88 @@ | ||
import "@tanssi/api-augment"; | ||
import { describeSuite, expect, beforeAll } from "@moonwall/cli"; | ||
import { ApiPromise } from "@polkadot/api"; | ||
import { KeyringPair, generateKeyringPair } from "@moonwall/util"; | ||
import { Keyring } from "@polkadot/keyring"; | ||
import { jumpToSession } from "../../../util/block"; | ||
import { PRIMARY_GOVERNANCE_CHANNEL_ID } from "../../../util/constants"; | ||
|
||
describeSuite({ | ||
id: "DTR1308", | ||
title: "Slashes are accumulated across eras based on max slashes sent per block", | ||
foundationMethods: "dev", | ||
testCases: ({ it, context }) => { | ||
let polkadotJs: ApiPromise; | ||
let alice: KeyringPair; | ||
let aliceBabePair: KeyringPair; | ||
let aliceStash: KeyringPair; | ||
beforeAll(async () => { | ||
const keyringBabe = new Keyring({ type: "sr25519" }); | ||
aliceBabePair = keyringBabe.addFromUri("//Alice"); | ||
polkadotJs = context.polkadotJs(); | ||
alice = context.keyring.alice; | ||
aliceStash = keyringBabe.addFromUri("//Alice//stash"); | ||
}); | ||
it({ | ||
id: "E01", | ||
title: "Slashes are accumulated across eras", | ||
test: async function () { | ||
// we need to start at least one sesssion to start eras | ||
await jumpToSession(context, 1); | ||
// Let's inject slashes N+1 slashes, where N is the max slashes to send per block | ||
// With force inject slash, we can inject a slash for any account | ||
const maxSlashesPerMessage = (await polkadotJs.consts.externalValidatorSlashes.queuedSlashesProcessedPerBlock).toNumber(); | ||
const epochDuration = (await polkadotJs.consts.babe.epochDuration).toNumber(); | ||
const sessionsPerEra = await polkadotJs.consts.externalValidators.sessionsPerEra; | ||
|
||
const slashesToInject = (maxSlashesPerMessage*epochDuration*sessionsPerEra.toNumber()) +1; | ||
let aliceNonce = (await polkadotJs.query.system.account(alice.address)).nonce.toNumber(); | ||
|
||
for (let i = 0; i < slashesToInject; i++) { | ||
const randomAccount = generateKeyringPair("sr25519"); | ||
await polkadotJs.tx.sudo | ||
.sudo(polkadotJs.tx.externalValidatorSlashes.forceInjectSlash(0, randomAccount.address, 1000)) | ||
.signAndSend(alice, { nonce: aliceNonce++ }); | ||
} | ||
await context.createBlock(); | ||
|
||
// Slash item should be there | ||
const DeferPeriod = (await polkadotJs.consts.externalValidatorSlashes.slashDeferDuration).toNumber(); | ||
|
||
// scheduled slashes | ||
const expectedSlashes = await polkadotJs.query.externalValidatorSlashes.slashes(DeferPeriod + 1); | ||
expect(expectedSlashes.length).to.be.eq(slashesToInject); | ||
|
||
|
||
const currentIndex = await polkadotJs.query.session.currentIndex(); | ||
|
||
const targetSession = currentIndex * (sessionsPerEra * (DeferPeriod + 1)); | ||
|
||
await jumpToSession(context, targetSession); | ||
|
||
// scheduled slashes | ||
const expectedSlashesAfterDefer = await polkadotJs.query.externalValidatorSlashes.slashes( | ||
DeferPeriod + 1 | ||
); | ||
// We should have unprocessed messages | ||
const expectedUnprocessedMessages = await polkadotJs.query.externalValidatorSlashes.unreportedSlashesQueue(); | ||
expect (expectedUnprocessedMessages.length).to.be.eq(slashesToInject); | ||
expect(expectedSlashesAfterDefer.length).to.be.eq(slashesToInject); | ||
expect(expectedSlashesAfterDefer[0].confirmed.toHuman()).to.be.true; | ||
|
||
// Now we will jump one entire era | ||
// After one era, we should still have one slash to send | ||
const currentIndexAfterSlashes = await polkadotJs.query.session.currentIndex(); | ||
const targetSessionToNextEra = currentIndexAfterSlashes.toNumber() + sessionsPerEra.toNumber(); | ||
console.log(currentIndexAfterSlashes.toBigInt()) | ||
console.log(sessionsPerEra.toBigInt()) | ||
console.log(targetSessionToNextEra) | ||
|
||
await jumpToSession(context, targetSessionToNextEra); | ||
|
||
// However we stil should have one unprocessed message | ||
const expectedUnprocessedMessagesAfterOneEra = await polkadotJs.query.externalValidatorSlashes.unreportedSlashesQueue(); | ||
expect (expectedUnprocessedMessagesAfterOneEra.length).to.be.eq(1); | ||
}, | ||
}); | ||
}, | ||
}); |
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