-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(a3p): extend test coverage for KREAd app on z:acceptance test ph…
…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
Showing
7 changed files
with
576 additions
and
146 deletions.
There are no files selected for viewing
19 changes: 0 additions & 19 deletions
19
a3p-integration/proposals/z:acceptance/create-kread-item-test.sh
This file was deleted.
Oops, something went wrong.
77 changes: 0 additions & 77 deletions
77
a3p-integration/proposals/z:acceptance/generate-kread-item-request.mjs
This file was deleted.
Oops, something went wrong.
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,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', | ||
); | ||
}); |
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
Oops, something went wrong.