-
Notifications
You must be signed in to change notification settings - Fork 17
Treasury e2e follow up #321
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
71 changes: 71 additions & 0 deletions
71
packages/polkadot/src/__snapshots__/polkadot.treasury.e2e.test.ts.snap
This file contains hidden or 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,71 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`Polkadot Treasury > Foreign asset spend from Relay treasury is reflected on AssetHub > payout events 1`] = ` | ||
| [ | ||
| { | ||
| "data": { | ||
| "index": "(redacted)", | ||
| "paymentId": "(redacted)", | ||
| }, | ||
| "method": "Paid", | ||
| "section": "treasury", | ||
| }, | ||
| ] | ||
| `; | ||
|
|
||
| exports[`Polkadot Treasury > Foreign asset spend from Relay treasury is reflected on AssetHub > treasury spend approval events 1`] = ` | ||
| [ | ||
| { | ||
| "data": { | ||
| "amount": "123,123,123,123", | ||
| "assetKind": { | ||
| "V4": { | ||
| "assetId": { | ||
| "interior": { | ||
| "X2": [ | ||
| { | ||
| "PalletInstance": "50", | ||
| }, | ||
| { | ||
| "GeneralIndex": "1,984", | ||
| }, | ||
| ], | ||
| }, | ||
| "parents": "0", | ||
| }, | ||
| "location": { | ||
| "interior": { | ||
| "X1": [ | ||
| { | ||
| "Parachain": "1,000", | ||
| }, | ||
| ], | ||
| }, | ||
| "parents": "0", | ||
| }, | ||
| }, | ||
| }, | ||
| "beneficiary": { | ||
| "V4": { | ||
| "interior": { | ||
| "X1": [ | ||
| { | ||
| "AccountId32": { | ||
| "id": "(hash)", | ||
| "network": null, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| "parents": "0", | ||
| }, | ||
| }, | ||
| "expireAt": "(redacted)", | ||
| "index": "(redacted)", | ||
| "validFrom": "(redacted)", | ||
| }, | ||
| "method": "AssetSpendApproved", | ||
| "section": "treasury", | ||
| }, | ||
| ] | ||
| `; |
This file contains hidden or 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 hidden or 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,4 @@ | ||
| import { assetHubPolkadot, polkadot } from '@e2e-test/networks/chains' | ||
| import { treasuryE2ETests } from '@e2e-test/shared' | ||
|
|
||
| treasuryE2ETests(polkadot, assetHubPolkadot, { testSuiteName: 'Polkadot Treasury', addressEncoding: 0 }) |
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| import { assert, describe, expect, test } from 'vitest' | ||
|
|
||
| import { sendTransaction } from '@acala-network/chopsticks-testing' | ||
| import { type Chain, defaultAccountsSr25519 as devAccounts } from '@e2e-test/networks' | ||
| import { setupNetworks } from '@e2e-test/shared' | ||
|
|
||
| import { checkEvents, checkSystemEvents, scheduleInlineCallWithOrigin } from './helpers/index.js' | ||
|
|
||
| /** | ||
| * Test that a foreign asset spend from the Relay treasury is reflected on the AssetHub. | ||
| * | ||
| * 1. Approve a spend from the Relay treasury | ||
| * 2. Payout the spend from the Relay treasury | ||
| * 3. Check that the spend shows in the AssetHub | ||
| */ | ||
| export async function treasurySpendForeignAssetTest< | ||
| TCustom extends Record<string, unknown> | undefined, | ||
| TInitStoragesRelay extends Record<string, Record<string, any>> | undefined, | ||
| TInitStoragesPara extends Record<string, Record<string, any>> | undefined, | ||
| >(relayChain: Chain<TCustom, TInitStoragesRelay>, ahChain: Chain<TCustom, TInitStoragesPara>) { | ||
| const [relayClient, assetHubClient] = await setupNetworks(relayChain, ahChain) | ||
|
|
||
| await relayClient.dev.setStorage({ | ||
| System: { | ||
| account: [ | ||
| // give Alice some DOTs so that she can sign a payout transaction. | ||
| [[devAccounts.alice.address], { providers: 1, data: { free: 10000e10 } }], | ||
| ], | ||
| }, | ||
| }) | ||
| const USDT_ID = 1984 | ||
| const balanceBefore = await assetHubClient.api.query.assets.account(USDT_ID, devAccounts.alice.address) | ||
|
|
||
| // amount is encoded into the call | ||
| const amount = 123123123123n | ||
| const treasurySpendCall = | ||
| '0x130504000100a10f0002043205011f07b3c3b5aa1c0400010100d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00' | ||
| await scheduleInlineCallWithOrigin(relayClient, treasurySpendCall, { system: 'Root' }) | ||
| await relayClient.dev.newBlock() | ||
| await checkSystemEvents(relayClient, { section: 'treasury', method: 'AssetSpendApproved' }) | ||
| // values (e.g. index) inside data increase over time, | ||
| // PET framework often rounds them. | ||
| // Tests will be flaky if we don't redact them. | ||
| .redact({ | ||
| redactKeys: /expireAt|validFrom|index/, | ||
| number: false, | ||
| }) | ||
| .toMatchSnapshot('treasury spend approval events') | ||
|
|
||
| // filter events to find an index to payout | ||
| const [assetSpendApprovedEvent] = (await relayClient.api.query.system.events()).filter( | ||
| ({ event }) => event.section === 'treasury' && event.method === 'AssetSpendApproved', | ||
| ) | ||
| expect(assetSpendApprovedEvent).toBeDefined() | ||
| assert(relayClient.api.events.treasury.AssetSpendApproved.is(assetSpendApprovedEvent.event)) | ||
| const spendIndex = assetSpendApprovedEvent.event.data.index.toNumber() | ||
|
|
||
| // payout | ||
| const payoutEvents = await sendTransaction( | ||
| relayClient.api.tx.treasury.payout(spendIndex).signAsync(devAccounts.alice), | ||
| ) | ||
|
|
||
| // create blocks on RC and AH to ensure that payout is properly processed | ||
| await relayClient.dev.newBlock() | ||
| await checkEvents(payoutEvents, { section: 'treasury', method: 'Paid' }) | ||
| .redact({ redactKeys: /paymentId|index/ }) | ||
| .toMatchSnapshot('payout events') | ||
| const [paidEvent] = (await relayClient.api.query.system.events()).filter( | ||
| ({ event }) => event.section === 'treasury' && event.method === 'Paid', | ||
| ) | ||
| expect(paidEvent).toBeDefined() | ||
| assert(relayClient.api.events.treasury.Paid.is(paidEvent.event)) | ||
| const payoutIndex = paidEvent.event.data.index.toNumber() | ||
| expect(payoutIndex).toBe(spendIndex) | ||
|
|
||
| // treasury spend does not emit any event on AH so we need to check that Alice's balance is increased by the `amount` directly | ||
| await assetHubClient.dev.newBlock() | ||
| const balanceAfter = await assetHubClient.api.query.assets.account(USDT_ID, devAccounts.alice.address) | ||
| const balanceAfterAmount = balanceAfter.isNone ? 0n : balanceAfter.unwrap().balance.toBigInt() | ||
| const balanceBeforeAmount = balanceBefore.isNone ? 0n : balanceBefore.unwrap().balance.toBigInt() | ||
| expect(balanceAfterAmount - balanceBeforeAmount).toBe(amount) | ||
| } | ||
|
|
||
| export function treasuryE2ETests< | ||
| TCustom extends Record<string, unknown> | undefined, | ||
| TInitStoragesRelay extends Record<string, Record<string, any>> | undefined, | ||
| TInitStoragesPara extends Record<string, Record<string, any>> | undefined, | ||
| >( | ||
| relayChain: Chain<TCustom, TInitStoragesRelay>, | ||
| ahChain: Chain<TCustom, TInitStoragesPara>, | ||
| testConfig: { testSuiteName: string; addressEncoding: number }, | ||
| ) { | ||
| describe(testConfig.testSuiteName, () => { | ||
| test('Foreign asset spend from Relay treasury is reflected on AssetHub', async () => { | ||
| await treasurySpendForeignAssetTest(relayChain, ahChain) | ||
| }) | ||
| }) | ||
| } | ||
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.
Wouldn’t one of these be sufficient? I may not fully understand the value that PET snapshots provide — if you could elaborate on that, I’d really appreciate it @rockbmb