Skip to content

Bounties e2e test#399

Merged
rockbmb merged 68 commits intoopen-web3-stack:masterfrom
dhirajs0:bounties-e2e
Oct 7, 2025
Merged

Bounties e2e test#399
rockbmb merged 68 commits intoopen-web3-stack:masterfrom
dhirajs0:bounties-e2e

Conversation

@dhirajs0
Copy link
Copy Markdown
Contributor

@dhirajs0 dhirajs0 commented Sep 9, 2025

Added end-to-end tests to cover the main flows of the pallet_bounties module.

Key scenarios covered:

  • Creating a bounty
  • Curator assignment and acceptance
  • Funding and extending a bounty
  • Awarding and claiming a bounty
  • Bounty closure and payout
  • Handling bounty rejection or cancellation

Closes #292 .

Comment thread packages/shared/src/bounties.ts Outdated
Comment thread packages/shared/src/bounties.ts Outdated
Comment thread packages/shared/src/bounties.ts Outdated
@dhirajs0
Copy link
Copy Markdown
Contributor Author

dhirajs0 commented Sep 9, 2025

Thanks for the early feedback. I will incorporate the suggested changes.

@rockbmb
Copy link
Copy Markdown
Collaborator

rockbmb commented Sep 9, 2025

I am aware this is a draft PR; whenever it's ready, ping me for a full review.

Comment thread packages/shared/src/bounties.ts Outdated
@dhirajs0 dhirajs0 marked this pull request as ready for review September 19, 2025 16:33
@dhirajs0 dhirajs0 requested a review from rockbmb September 19, 2025 16:33
@rockbmb
Copy link
Copy Markdown
Collaborator

rockbmb commented Sep 22, 2025

Will take a look later in the week!

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ensureSpendPeriodAvailable function is incorrectly called with the client object instead of lastSpendPeriodBlock in two different tests. This will lead to test failures. Otherwise, the changes look good and provide comprehensive test coverage for the bounties pallet.

Comment thread packages/shared/src/bounties.ts Outdated
Comment thread packages/shared/src/bounties.ts Outdated
Comment thread packages/shared/src/bounties.ts Outdated
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The submitted code is well-structured and provides extensive test coverage for the bounties pallet. However, there are a few issues that need to be addressed, including an incorrect null check, a misleading comment, and several typos in comments and snapshot names. Addressing these points will improve the code's correctness and maintainability.


Suggestions that couldn't be attached to a specific line

packages/shared/src/bounties.ts:1568, 1726

There is a typo in the comments on these lines. 'amout' should be 'amount'.

Comment thread packages/shared/src/bounties.ts Outdated
Comment thread packages/shared/src/bounties.ts Outdated
// verify the transfer event
await checkSystemEvents(client, { section: 'balances', method: 'Transfer' })
.redact({ redactKeys: /from|to/ })
.toMatchSnapshot('bounty value transfered to treasury')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the snapshot name: 'bounty value transfered to treasury'. 'transfered' should be 'transferred'.

Comment thread packages/shared/src/bounties.ts Outdated
expect(bountyStatus.status.isActive).toBe(true)

// Charlie (public user) tries to unassign curator immediately (premature)
// Using scheduleInlineCallWithOrigin to simulate public call
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment // Using scheduleInlineCallWithOrigin to simulate public call is misleading. The test actually uses sendTransaction on line 2165 to send a transaction from a regular account (charlie), not scheduleInlineCallWithOrigin. Please update the comment to accurately reflect that a public user is attempting the action, for example: // Charlie (a public user) tries to unassign the curator.

Copy link
Copy Markdown
Collaborator

@rockbmb rockbmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

  • Every bounties pallet's extrinsic is exercised at least once
    • pokeDeposit still not available
  • Every event type appears at least once
    • DepositPoked still not available, either
  • Almost every variant of the Error<T> enum is checked at least once
    • 100% coverage is a distraction, but exercising each at least once is desirable
  • snapshots redact temporal data, as they should
  • Broad selection of scenarios

The PR is already large enough, feel free to address my comments in a future PR.

Comment thread packages/polkadot/src/__snapshots__/polkadot.bounties.e2e.test.ts.snap Outdated
Comment thread packages/polkadot/src/__snapshots__/polkadot.bounties.e2e.test.ts.snap Outdated
await client.dev.newBlock()

// claim the bounty
const claimBountyTx = client.api.tx.bounties.claimBounty(bountyIndex)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the successful case, which is good to cover.

However, the failure code path is not exercised, which would also be good:
https://github.com/paritytech/polkadot-sdk/blob/c3f62bf918ef6879390dc6a2cf9f91caac23f5b5/substrate/frame/bounties/src/lib.rs#L734-L736

				if let BountyStatus::PendingPayout { curator, beneficiary, unlock_at } =
					bounty.status
				{
...
				} else {
                // This arm of the conditional
					Err(Error::<T, I>::UnexpectedStatus.into())
				}

Can be left to a future PR.

Copy link
Copy Markdown
Contributor Author

@dhirajs0 dhirajs0 Oct 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the failure code in the latest commits

Comment thread packages/shared/src/bounties.ts Outdated
* Test: Bounty closure in PendingPayout state (should fail)
*
* Verifies:
* - Bounty closure fails with PendingPayout error when in PendingPayout state (GeneralAdmin must unassign curator first)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - Bounty closure fails with PendingPayout error when in PendingPayout state (GeneralAdmin must unassign curator first)
* - Bounty closure fails with `PendingPayout` error when in `PendingPayout` state (`GeneralAdmin` must unassign curator first)

This is pedantry on my part, but backticks (``) when referring to code in comments are preferable, imo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, i am updating it.

Copy link
Copy Markdown
Contributor Author

@dhirajs0 dhirajs0 Oct 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added backticks for code in all the opening comments.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Like I said, it's not important, but it makes comments slightly easier to read.

Comment thread packages/shared/src/bounties.ts Outdated
const updateDueBefore = bountyForExtending.status.asActive.updateDue.toNumber()

// extend the bounty expiry
const extendBountyTx = client.api.tx.bounties.extendBountyExpiry(bountyIndex, 'Testing the bounty extension')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the successful case;

A few others would be interesting to test: https://github.com/paritytech/polkadot-sdk/blob/c3f62bf918ef6879390dc6a2cf9f91caac23f5b5/substrate/frame/bounties/src/lib.rs#L855-L862

				match bounty.status {
					BountyStatus::Active { ref curator, ref mut update_due } => {
                    // A check to the caller. Really basic, but the compiler can't catch these things.
						ensure!(*curator == signer, Error::<T, I>::RequireCurator);
						*update_due = Self::treasury_block_number()
							.saturating_add(T::BountyUpdatePeriod::get())
							.max(*update_due);
					},
                    // A check that exercises this code path
					_ => return Err(Error::<T, I>::UnexpectedStatus.into()),

As my other such comments, this can be left to a future PR.

Copy link
Copy Markdown
Contributor Author

@dhirajs0 dhirajs0 Oct 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As my other such comments, this can be left to a future PR.

Sure. Will add in a future PR

Comment thread packages/shared/src/bounties.ts Outdated
Comment thread packages/shared/src/bounties.ts Outdated
/// -------

// initial funding balance for accounts
const TEST_ACCOUNT_BALANCE = 100000000000000n
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is going to be run on post-AHM KAH (in fact, it already can; remind me to ping you this week to pair on this; will be useful later), and soon, post-migration PAH.

Could you make this a large multiple of const.balances.existentialDeposit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dhirajs0
Copy link
Copy Markdown
Contributor Author

dhirajs0 commented Oct 5, 2025

  • Every bounties pallet's extrinsic is exercised at least once

    • pokeDeposit still not available
  • Every event type appears at least once

    • DepositPoked still not available, either

pokeDeposit and DepositPoked is not available as I was using the bounties code from the branch in the ahm dryrun repo, should have taken the latest code from polkadot-sdk .

The PR is already large enough, feel free to address my comments in a future PR.

Sure, I will address these in a future PR

@dhirajs0
Copy link
Copy Markdown
Contributor Author

dhirajs0 commented Oct 5, 2025

Thank you very much for all the suggestions, I'm excited to put these best practices into action on my next PR.

@rockbmb
Copy link
Copy Markdown
Collaborator

rockbmb commented Oct 6, 2025

pokeDeposit and DepositPoked is not available

I know, and now I know that you know! I was just commenting for future reference i.e. that at the time this PR was written, these were not available, in other words, that coverage is complete (until those come online)

@rockbmb rockbmb merged commit 9e80e3c into open-web3-stack:master Oct 7, 2025
247 of 258 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add E2E tests for Bounties

2 participants