Skip to content
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

test(a3p): extend test coverage for KREAd app on z:acceptance test phase #10242

Merged
merged 12 commits into from
Oct 31, 2024

Conversation

Jorge-Lopes
Copy link
Collaborator

@Jorge-Lopes Jorge-Lopes commented Oct 8, 2024

closes: https://github.com/Agoric/BytePitchPartnerEng/issues/12
refs: https://github.com/Agoric/BytePitchPartnerEng/issues/9

Description

The existing test of the KREAd application on the z:acceptance test phase was limited to the feature allowing users to mint a new KREAd Character.

This PR extends the existing test coverage to include the following cases:

  • minting a new Character
  • unequip all defaults Items
  • sell unequipped Item
  • buy an Item on marketplace
  • sell a Character
  • buy a Character on marketplace

Along with the kread.test.js file, this PR includes a new file, /test-lib/kread.js, that provides all the required helper functions for the test cases above, allowing a cleaner and scalable design for KREAd tests.

Since the test coverage of the new file overlaps with the existing one, I opted for removing both:

  • create-kread-item-test.sh
  • generate-kread-item-request.mjs

Security Considerations

No security considerations were identified.

Scaling Considerations

No scaling considerations were identified.

Documentation Considerations

No documentation considerations were identified.

Testing Considerations

I have confirmed that this works fine with existing a3p tests locally, there is still an improvement that may be useful to ensure that the user wallet's purse balance for the desired KREAd asset was updated accordingly.

For this purpose, we intend to use one feature included in the currently open PR #10171 , which is the sync-tools method retryUntilCondition().

However, we hope to address those changes in a different PR that will be the result of the effort put into the currently open ticket

@Jorge-Lopes Jorge-Lopes requested a review from a team as a code owner October 8, 2024 17:40
Copy link

cloudflare-workers-and-pages bot commented Oct 8, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: f427d35
Status: ✅  Deploy successful!
Preview URL: https://64c39d45.agoric-sdk.pages.dev
Branch Preview URL: https://jorge-acceptance-kread-test.agoric-sdk.pages.dev

View logs

@Jorge-Lopes Jorge-Lopes force-pushed the jorge/acceptance-kread-test branch 2 times, most recently from 55f9a44 to a05465b Compare October 11, 2024 18:08
Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

Looks pretty good. I'd like to see an additional helper, and more use of Amounts.

a3p-integration/proposals/z:acceptance/test-lib/kread.js Outdated Show resolved Hide resolved
Comment on lines 186 to 265
const path = `:published.kread.market-characters.${charactersMarket[0]}`;
const rawCharacterData = await agoric.follow('-lF', path, '-o', 'text');
const marketCharacter = marshaller.fromCapData(JSON.parse(rawCharacterData));
Copy link
Contributor

Choose a reason for hiding this comment

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

please write a helper that will unmarshall from vstorage to Amounts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the effort to keep the new helper function getAssetAmount agnostic to the asset provided as an argument, I left the query to Vstorage unchanged and used marketCharacter as the argument.
Does this approach work for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with passing marketCharacter to totalAssetPriceAmount, but I'd still prefer that there be a function for the 4 lines above. (perhaps getMarketCharacterFromVstorage()).
is 0 a parameter saying which child, or is it always ':published.kread.market-characters.${charactersMarket[0]}'?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I addressed the requested change by implementing the new getMarketCharacterFromVstorage helper function.

In this case, there is no need to provide the market-characters children node dynamically because, for the test case built, we only need to ensure that a character is available on the market.
For that reason, I am using the static child index 0.

a3p-integration/proposals/z:acceptance/kread.test.js Outdated Show resolved Hide resolved
a3p-integration/proposals/z:acceptance/test-lib/kread.js Outdated Show resolved Hide resolved
a3p-integration/proposals/z:acceptance/test-lib/kread.js Outdated Show resolved Hide resolved
const assetValue = makeCopyBag([[asset, 1n]]);
const assetAmount = AmountMath.make(
brand,
//@ts-expect-error casting
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be necessary. AmountMath.make takes CopyBagAmounts by default, so you should be able to declare a type for assetValue and not have to expect an error. The following worked for me

/** @import {Brand, CopyBagAmount} from '@agoric/ertp'; */

/**
 * @param {Brand} brand
 * @param {any} asset
 * @returns {CopyBagAmount<'item'>}
 */
export const getAssetAmount = (brand, asset) => {
  const assetValue = makeCopyBag([[asset, 1n]]);
  return AmountMath.make(brand, assetValue);
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Requested change addressed

@Jorge-Lopes
Copy link
Collaborator Author

@Chris-Hibbert I am sorry for having requested your re-review yesterday before noticing the linting issues.

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

This is on the right track. Just a few requests, not all required.

Comment on lines 186 to 265
const path = `:published.kread.market-characters.${charactersMarket[0]}`;
const rawCharacterData = await agoric.follow('-lF', path, '-o', 'text');
const marketCharacter = marshaller.fromCapData(JSON.parse(rawCharacterData));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with passing marketCharacter to totalAssetPriceAmount, but I'd still prefer that there be a function for the 4 lines above. (perhaps getMarketCharacterFromVstorage()).
is 0 a parameter saying which child, or is it always ':published.kread.market-characters.${charactersMarket[0]}'?

a3p-integration/proposals/z:acceptance/kread.test.js Outdated Show resolved Hide resolved
kreadCharacter2,
);

const id = `KREAd-unequip-all-items-acceptance-test`;
Copy link
Contributor

Choose a reason for hiding this comment

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

just a suggestion: I give a separate name to values like this if I'm going to use them more than once, or if pulling them out will make the formatting take fewer lines. Why do you prefer this over

   id: `KREAd-unequip-all-items-acceptance-test`,

inside offer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the suggestion—I've made the change.

I don't have a strong preference; it was simply a habit of mine.
I now understand your reasoning for when to declare the offer ID outside of the offer body.
I’ll adopt that approach moving forward.

@Jorge-Lopes
Copy link
Collaborator Author

I'm fine with passing marketCharacter to totalAssetPriceAmount, but I'd still prefer that there be a function for the 4 lines above. (perhaps getMarketCharacterFromVstorage()).
is 0 a parameter saying which child, or is it always ':published.kread.market-characters.${charactersMarket[0]}'?

Change requested addressed by implementing the getMarketCharacterFromVstorage helper function.

In this case, there is no need to provide the market-characters children node dynamically because, for the test case built, we only need to ensure that a character is available on the market. For that reason, I am using the static the child index 0.

@Jorge-Lopes
Copy link
Collaborator Author

@Chris-Hibbert while addressing the conflicts in order to rebase this branch into master, I mistakenly included commits that were not done at this branch.
I am currently trying to clean the commit history.

Meaning that most of the comments you just raised regards code the I did not do it.
Regarding the agoric packages versions, I will change to "dev" as you suggested.

@Jorge-Lopes Jorge-Lopes changed the base branch from master to jorge/verify-pushed-price October 29, 2024 09:42
@Jorge-Lopes Jorge-Lopes changed the base branch from jorge/verify-pushed-price to master October 29, 2024 09:42
Copy link

Base branch is changed to master. Please re-run the integration tests by adding 'force:integration' label.

@Jorge-Lopes Jorge-Lopes changed the base branch from master to jorge/acceptance-wallet-test-sync-tools October 29, 2024 11:02
@Jorge-Lopes Jorge-Lopes changed the base branch from jorge/acceptance-wallet-test-sync-tools to master October 29, 2024 11:02
Copy link

Base branch is changed to master. Please re-run the integration tests by adding 'force:integration' label.

@Jorge-Lopes Jorge-Lopes added the force:integration Force integration tests to run on PR label Oct 29, 2024
@Jorge-Lopes
Copy link
Collaborator Author

Greetings @Chris-Hibbert

As I mentioned before, while addressing the conflicts after rebasing to master, the commit history displayed unexpected behavior. It showed duplicated commits as well as commits that had already been merged on the master.

While trying different approaches to solving the issue, one suggested editing the landing branch to a different one and then back to the original, which is why you can see that change in the conversation and the reason why I added the 'force:integration' label to re-run the integration tests.

I was able to solve the problems by doing an interactive rebase, having now a clean commit history, and maintaining the changes that you requested during this review.

Thank you for your time and sorry for any inconvenience.

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

LGTM.

please add one comment before merging.

@Jorge-Lopes Jorge-Lopes added automerge:rebase Automatically rebase updates, then merge and removed force:integration Force integration tests to run on PR labels Oct 31, 2024
@mergify mergify bot merged commit fae2710 into master Oct 31, 2024
89 of 97 checks passed
@mergify mergify bot deleted the jorge/acceptance-kread-test branch October 31, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants