Skip to content

Commit

Permalink
test(a3p): extend test coverage for KREAd app on z:acceptance test ph…
Browse files Browse the repository at this point in the history
…ase (#10242)

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](#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](https://github.com/Agoric/BytePitchPartnerEng/issues/10)
  • Loading branch information
mergify[bot] authored Oct 31, 2024
2 parents 25db2b9 + f427d35 commit fae2710
Show file tree
Hide file tree
Showing 7 changed files with 576 additions and 146 deletions.
19 changes: 0 additions & 19 deletions a3p-integration/proposals/z:acceptance/create-kread-item-test.sh

This file was deleted.

This file was deleted.

166 changes: 166 additions & 0 deletions a3p-integration/proposals/z:acceptance/kread.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import test from 'ava';
import {
provisionSmartWallet,
USER1ADDR as Alice,
GOV1ADDR as Bob,
} from '@agoric/synthetic-chain';
import {
buyCharacter,
buyItem,
getCharacterInventory,
getMarketCharactersChildren,
getBalanceFromPurse,
getMarketItem,
getMarketItemsChildren,
mintCharacter,
sellCharacter,
sellItem,
unequipAllItems,
} from './test-lib/kread.js';

test.serial('Alice mints a new Character', async t => {
await provisionSmartWallet(Alice, '200000000ubld');
const characterBalanceBefore = await getBalanceFromPurse(Alice, 'character');
t.is(characterBalanceBefore, null, 'A Character should not exist in purse');

await mintCharacter(Alice);

const characterBalanceAfter = await getBalanceFromPurse(Alice, 'character');
t.is(
characterBalanceAfter.name,
'ephemeral_Ace',
'Minted Character name should be ephemeral_Ace',
);
});

test.serial('Alice unequips all defaults Items', async t => {
const itemBalanceBefore = await getBalanceFromPurse(Alice, 'item');
t.is(itemBalanceBefore, null, 'An Item should not exist in purse');

const characterId = 'ephemeral_Ace';
const characterInventoryBefore = await getCharacterInventory(characterId);
t.is(
characterInventoryBefore.length,
3,
'Character should have 3 items in inventory',
);

await unequipAllItems(Alice);

const characterInventoryAfter = await getCharacterInventory(characterId);
t.is(
characterInventoryAfter.length,
0,
'Character should have 0 items in inventory',
);

const itemBalanceAfter = await getBalanceFromPurse(Alice, 'item');
t.is(
itemBalanceAfter.description,
characterInventoryBefore[0][0].description,
'The unequipped Item should exist in purse',
);
});

test.serial('Alice sells one unequipped Item', async t => {
const itemListBefore = await getMarketItemsChildren();
const itemBefore = await getBalanceFromPurse(Alice, 'item');

await sellItem(Alice);

const itemListAfter = await getMarketItemsChildren();
t.is(
itemListAfter.length,
itemListBefore.length + 1,
'Items market should have 1 more item',
);

const soldItemNode = itemListAfter.filter(
itemNode => !itemListBefore.includes(itemNode),
);
const soldItem = await getMarketItem(soldItemNode);

t.is(
itemBefore.description,
soldItem.asset.description,
'Item on purse should have the same description as the one sold to market',
);
});

test.serial('Bob buys an Item on marketplace', async t => {
const itemListBefore = await getMarketItemsChildren();
const marketItemNode = itemListBefore[0];
const marketItem = await getMarketItem(marketItemNode);

await buyItem(Bob);

const itemListAfter = await getMarketItemsChildren();
t.is(
itemListAfter.length,
itemListBefore.length - 1,
'Items market should have 1 less item',
);

const boughtItemNode = itemListBefore.filter(
itemNode => !itemListAfter.includes(itemNode),
);
t.is(
marketItemNode,
boughtItemNode[0],
'Item bought should have been removed from market',
);

const item = await getBalanceFromPurse(Bob, 'item');
t.is(
item.description,
marketItem.asset.description,
'Item on purse should have the same description as the one bought from market',
);
});

test.serial('Alice sells a Character', async t => {
const characterListBefore = await getMarketCharactersChildren();
t.false(
characterListBefore.includes('character-ephemeral_Ace'),
'Character should not be on market before selling',
);

const characterBalanceBefore = await getBalanceFromPurse(Alice, 'character');
t.is(
characterBalanceBefore.name,
'ephemeral_Ace',
'Character name should be ephemeral_Ace',
);

await sellCharacter(Alice);

const characterListAfter = await getMarketCharactersChildren();
t.true(
characterListAfter.includes('character-ephemeral_Ace'),
'Character should be on market after selling',
);

const characterBalanceAfter = await getBalanceFromPurse(Alice, 'character');
t.is(
characterBalanceAfter,
null,
'Character should not be in purse after selling',
);
});

test.serial('Bob buys a Character on marketplace', async t => {
await buyCharacter(Bob);

const characterListBefore = await getMarketCharactersChildren();
t.false(
characterListBefore.includes('character-ephemeral_Ace'),
'Character should not be on market after buying',
);

const characterBalance = await getBalanceFromPurse(Bob, 'character');
t.is(
characterBalance.name,
'ephemeral_Ace',
'Character name should be ephemeral_Ace',
);
});
1 change: 1 addition & 0 deletions a3p-integration/proposals/z:acceptance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@agoric/ertp": "dev",
"@agoric/internal": "dev",
"@agoric/store": "dev",
"@agoric/synthetic-chain": "^0.3.0",
"@endo/errors": "^1.2.2",
"@endo/far": "^1.1.5",
Expand Down
Loading

0 comments on commit fae2710

Please sign in to comment.