From f7a4fc837ec47ef5b86abdda65f44638e82e3c2f Mon Sep 17 00:00:00 2001 From: Pandelis Symeonidis Date: Wed, 8 Nov 2023 14:15:40 +0100 Subject: [PATCH] vstorage market tests --- .../bootstrap/bootstrap-market.js | 57 ++++++++++++++++++- .../bootstrap/bootstrap-upgradable.js | 28 ++++++--- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/agoric/contract/test/swingsetTests/bootstrap/bootstrap-market.js b/agoric/contract/test/swingsetTests/bootstrap/bootstrap-market.js index 204103a46..67cd7e317 100644 --- a/agoric/contract/test/swingsetTests/bootstrap/bootstrap-market.js +++ b/agoric/contract/test/swingsetTests/bootstrap/bootstrap-market.js @@ -1,12 +1,13 @@ import { AmountMath } from '@agoric/ertp'; import { E } from '@endo/eventual-send'; import { flow } from '../flow.js'; -import { makeCopyBag } from '@agoric/store'; +import { makeCopyBag, mustMatch } from '@agoric/store'; import { addCharacterToContext, addItemToContext } from './utils.js'; import { makeKreadUser } from './make-bootstrap-users.js'; import { errors } from '../../../src/kreadV2/errors.js'; import { multiplyBy } from '@agoric/zoe/src/contractSupport/ratio.js'; import { defaultItems } from '../items.js'; +import { TimerBrandShape } from '@agoric/time'; export async function setupMarketTests(context) { await addCharacterToContext(context); @@ -58,6 +59,10 @@ export async function sellCharacter(context) { zoe, users: { bob }, paymentAsset, + getFromVStorage, + royaltyRate, + platformFeeRate, + storageKit, } = context; const { market: { @@ -109,12 +114,27 @@ export async function sellCharacter(context) { 1, 'Character was not added to market', ); - assert.equal( (await bob.getCharacters()).length, 0, "Character is still in bob's wallet", ); + const vStorageCharacterMarket = getFromVStorage( + `kread.market-characters.character-${characterToSell.name}`, + ); + // + mustMatch(vStorageCharacterMarket.asset, harden({...characterToSell, date: {...characterToSell.date, timerBrand: TimerBrandShape}})); + assert.equal(vStorageCharacterMarket.id, characterToSell.name); + assert.equal(vStorageCharacterMarket.askingPrice.value, priceAmount.value); + assert.equal( + vStorageCharacterMarket.royalty.value, + multiplyBy(priceAmount, royaltyRate).value, + ); + assert.equal( + vStorageCharacterMarket.platformFee.value, + multiplyBy(priceAmount, platformFeeRate).value, + ); + assert.equal(vStorageCharacterMarket.isFirstSale, false); } export async function buyCharacterOfferLessThanAskingPrice(context) { @@ -188,6 +208,7 @@ export async function buyCharacter(context) { platformFeePurse, royaltyRate, platformFeeRate, + getFromVStorage } = context; const { @@ -265,6 +286,13 @@ export async function buyCharacter(context) { platformFeePursePre + multiplyBy(characterToBuy.askingPrice, platformFeeRate).value, ); + try { + getFromVStorage( + `kread.market-characters.character-${characterToBuy.asset.name}`, + ); + } catch (error) { + assert.equal(error.message, `no data for "kread.market-characters.character-${characterToBuy.asset.name}"`) + } } export async function buyCharacterNotOnMarket(context) { @@ -328,6 +356,9 @@ export async function sellItem(context) { zoe, users: { bob }, paymentAsset, + getFromVStorage, + royaltyRate, + platformFeeRate } = context; const itemToSellValue = (await bob.getItems()).find( @@ -361,6 +392,19 @@ export async function sellItem(context) { 0, "Item is still in bob's wallet", ); + const vStorageItemMarket = getFromVStorage(`kread.market-items.item-0`) // this is the first item on sale so we know it will be assigned id 0 + mustMatch(vStorageItemMarket.asset, itemToSellValue); + assert.equal(vStorageItemMarket.id, 0); + assert.equal(vStorageItemMarket.askingPrice.value, priceAmount.value); + assert.equal( + vStorageItemMarket.royalty.value, + multiplyBy(priceAmount, royaltyRate).value, + ); + assert.equal( + vStorageItemMarket.platformFee.value, + multiplyBy(priceAmount, platformFeeRate).value, + ); + assert.equal(vStorageItemMarket.isFirstSale, false); } export async function buyItemOfferLessThanAskingPrice(context) { @@ -421,6 +465,7 @@ export async function buyItem(context) { contractAssets, zoe, users: { bob, alice }, + getFromVStorage } = context; let itemsForSale = await E(publicFacet).getItemsForSale(); @@ -473,6 +518,14 @@ export async function buyItem(context) { itemsForSale = await E(publicFacet).getItemsForSale(); assert.equal(itemsForSale.length, 0, 'Item was not removed from market'); + + try { + getFromVStorage( + `kread.market-items.item-0`, + ); + } catch (error) { + assert.equal(error.message, `no data for "kread.market-items.item-0"`) + } } export async function buyItemNotOnMarket(context) { diff --git a/agoric/contract/test/swingsetTests/bootstrap/bootstrap-upgradable.js b/agoric/contract/test/swingsetTests/bootstrap/bootstrap-upgradable.js index e9eec517a..9182ad15b 100644 --- a/agoric/contract/test/swingsetTests/bootstrap/bootstrap-upgradable.js +++ b/agoric/contract/test/swingsetTests/bootstrap/bootstrap-upgradable.js @@ -1,8 +1,11 @@ -import { Far, deeplyFulfilled } from '@endo/marshal'; +import { Far, deeplyFulfilled, makeMarshal } from '@endo/marshal'; import { E } from '@endo/eventual-send'; import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils'; import { buildManualTimer } from '@agoric/swingset-vat/tools/manual-timer'; -import { makeFakeBoard } from '@agoric/vats/tools/board-utils'; +import { + makeFakeBoard, + slotToBoardRemote, +} from '@agoric/vats/tools/board-utils'; import { makeTracer } from '@agoric/internal'; import { Fail, NonNullish } from '@agoric/assert'; import { makeIssuerKit } from '@agoric/ertp'; @@ -165,11 +168,20 @@ export const buildRootObject = async () => { /** * Reads the data from the vstorage at the given path * Will throw an error if path doesnt exist - * @param {string} path + * @param {string} path */ const getFromVStorage = (path) => { - return unmarshalFromVstorage(storageKit.data, path, marshaller.fromCapData.bind(marshaller)) - } + const { fromCapData } = makeMarshal( + undefined, + (slot, iface) => { + return Far((iface ?? '').replace(/^Alleged: /, ''), {}); + }, + { + serializeBodyFormat: 'smallcaps', + }, + ); + return unmarshalFromVstorage(storageKit.data, path, fromCapData); + }; const committeeName = 'KREAd Committee'; @@ -283,10 +295,7 @@ export const buildRootObject = async () => { governorFacets.creatorFacet, ).getCreatorFacet(); - await E(creatorFacet).initializeBaseAssets( - baseCharacters, - baseItems, - ); + await E(creatorFacet).initializeBaseAssets(baseCharacters, baseItems); await E(creatorFacet).initializeCharacterNamesEntries(); await E(creatorFacet).initializeMetrics(); @@ -297,6 +306,7 @@ export const buildRootObject = async () => { } = terms; context = { + storageKit, getFromVStorage, contractAssets: { character: { issuer: characterIssuer, brand: characterBrand },