Skip to content

Commit

Permalink
chain storage market metric tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandelis Symeonidis committed Nov 8, 2023
1 parent 2edfba0 commit 8d17e4d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function sellCharacter(context, user, characterName, askingPrice) {
proposal,
payment,
);
await E(userSeat).getOfferResult()
await E(userSeat).getOfferResult();

user.setMarketSeat(userSeat);

Expand Down Expand Up @@ -100,7 +100,7 @@ export async function setupMarketMetricsTests(context) {

export async function initialization(context) {
/** @type {Context} */
const { publicFacet } = context;
const { publicFacet, getFromVStorage } = context;

const metrics = await E(publicFacet).getMarketMetrics();

Expand All @@ -109,6 +109,15 @@ export async function initialization(context) {
assert.equal(value, 0);
}
}
const vStorageCharacterMetrics = getFromVStorage('kread.market-metrics-character');
for (const value of Object.values(vStorageCharacterMetrics)) {
assert.equal(value, 0);
}

const vStorageItemMetrics = getFromVStorage('kread.market-metrics-item');
for (const value of Object.values(vStorageItemMetrics)) {
assert.equal(value, 0);
}
}

export async function collectionSize(context) {
Expand All @@ -118,6 +127,7 @@ export async function collectionSize(context) {
paymentAsset,
zoe,
users: { bob },
getFromVStorage
} = context;

const { give, offerArgs } = flow.mintCharacter.expected;
Expand Down Expand Up @@ -149,12 +159,19 @@ export async function collectionSize(context) {
const metrics = await E(publicFacet).getMarketMetrics();
assert.equal(metrics.character.collectionSize, 1);
assert.equal(metrics.item.collectionSize, 3);

const vStorageCharacterMetrics = getFromVStorage('kread.market-metrics-character');
assert.equal(vStorageCharacterMetrics.collectionSize, 1)

const vStorageItemMetrics = getFromVStorage('kread.market-metrics-item');
assert.equal(vStorageItemMetrics.collectionSize, 3)
}

export async function averageLevelsCharacter(context) {
/** @type {Context} */
const {
publicFacet,
getFromVStorage,
users: { bob },
} = context;

Expand All @@ -171,7 +188,7 @@ export async function averageLevelsCharacter(context) {
);

await sellCharacter(context, bob, characterName, 40n);

const metrics = await E(publicFacet).getMarketMetrics();
const characterLevel = await E(publicFacet).getCharacterLevel(characterName);
assert.equal(metrics.character.averageLevel, character.level);
Expand All @@ -181,13 +198,22 @@ export async function averageLevelsCharacter(context) {
const defaultItemsAverageLevel = 0;

assert.equal(metrics.item.averageLevel, defaultItemsAverageLevel);

const vStorageCharacterMetrics = getFromVStorage('kread.market-metrics-character');
assert.equal(vStorageCharacterMetrics.averageLevel, character.level)
assert.equal(vStorageCharacterMetrics.marketplaceAverageLevel, characterLevel)
assert.equal(vStorageCharacterMetrics.putForSaleCount, 1)

const vStorageItemMetrics = getFromVStorage('kread.market-metrics-item');
assert.equal(vStorageItemMetrics.averageLevel, defaultItemsAverageLevel)
}

export async function amountSoldCharacter(context) {
/** @type {Context} */
const {
publicFacet,
users: { bob },
getFromVStorage
} = context;

const {
Expand All @@ -212,13 +238,24 @@ export async function amountSoldCharacter(context) {

assert.equal(metrics.item.amountSold, 0);
assert.equal(metrics.item.latestSalePrice, 0);

const vStorageCharacterMetrics = getFromVStorage('kread.market-metrics-character');
assert.equal(vStorageCharacterMetrics.averageLevel, character.level)
assert.equal(vStorageCharacterMetrics.marketplaceAverageLevel, 0)
assert.equal(vStorageCharacterMetrics.amountSold, 1)
assert.equal(vStorageCharacterMetrics.latestSalePrice, 40)

const vStorageItemMetrics = getFromVStorage('kread.market-metrics-item');
assert.equal(vStorageItemMetrics.amountSold, 0)
assert.equal(vStorageItemMetrics.latestSalePrice, 0)
}

export async function latestSalePriceCharacter(context) {
/** @type {Context} */
const {
publicFacet,
users: { bob },
getFromVStorage
} = context;

const {
Expand Down Expand Up @@ -247,4 +284,15 @@ export async function latestSalePriceCharacter(context) {

assert.equal(metrics.item.amountSold, 0);
assert.equal(metrics.item.latestSalePrice, 0);

const vStorageCharacterMetrics = getFromVStorage('kread.market-metrics-character');
assert.equal(vStorageCharacterMetrics.averageLevel, character.level)
assert.equal(vStorageCharacterMetrics.marketplaceAverageLevel, 0)
assert.equal(vStorageCharacterMetrics.amountSold, 2)
assert.equal(vStorageCharacterMetrics.putForSaleCount, 2)
assert.equal(vStorageCharacterMetrics.latestSalePrice, 20)

const vStorageItemMetrics = getFromVStorage('kread.market-metrics-item');
assert.equal(vStorageItemMetrics.amountSold, 0)
assert.equal(vStorageItemMetrics.latestSalePrice, 0)
}
2 changes: 1 addition & 1 deletion agoric/contract/test/swingsetTests/test-market-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.before(async (t) => {
});

test.serial('---| METRICS - Initialization', async (t) => {
const [result] = await run('setupMarketMetricsTests');
const [result] = await run('initialization');
t.is(result, 'fulfilled');
});

Expand Down

0 comments on commit 8d17e4d

Please sign in to comment.