From 9fefcf0a24156c24e5376998371f12ecd260c2d7 Mon Sep 17 00:00:00 2001 From: anilhelvaci Date: Mon, 22 Jan 2024 14:30:44 +0300 Subject: [PATCH] chore(liquidationVisibility): #4 implement `assertNodeInStorage` --- .../test/liquidationVisibility/assertions.js | 12 ++++++ .../test-liquidationVisibility.js | 8 +++- .../test-visibilityAssertions.js | 37 +++++++++++++++++++ .../test/liquidationVisibility/tools.js | 4 ++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 packages/inter-protocol/test/liquidationVisibility/test-visibilityAssertions.js diff --git a/packages/inter-protocol/test/liquidationVisibility/assertions.js b/packages/inter-protocol/test/liquidationVisibility/assertions.js index 786a101264f..c2a1f4c656d 100644 --- a/packages/inter-protocol/test/liquidationVisibility/assertions.js +++ b/packages/inter-protocol/test/liquidationVisibility/assertions.js @@ -7,6 +7,8 @@ import { makeRatio, } from '@agoric/zoe/src/contractSupport/index.js'; import { headValue } from '../supports.js'; +import exp from "constants"; +import { getDataFromVstorage } from "./tools.js"; export const assertBidderPayout = async ( t, @@ -213,3 +215,13 @@ export const assertVaultData = async ( const auctioneerBookData = await E(vaultDataSubscriber).getUpdateSince(); t.deepEqual(auctioneerBookData.value, vaultDataVstorage[0][1]); }; + +export const assertNodeInStorage = async ({ + t, + rootNode, + desiredNode, + expected, +}) => { + const [...storageData] = await getDataFromVstorage(rootNode, desiredNode); + t.is(storageData.length !== 0, expected); +}; diff --git a/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js b/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js index 089c0c77890..d7cd5fd1493 100644 --- a/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js +++ b/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js @@ -29,8 +29,8 @@ import { openVault, getMetricTrackers, adjustVault, - closeVault, -} from './tools.js'; + closeVault, getDataFromVstorage +} from "./tools.js"; import { assertBidderPayout, assertCollateralProceeds, @@ -103,8 +103,12 @@ test('liq-result-scenario-1', async t => { aethTestPriceAuthority, reserveKit: { reserveCreatorFacet, reservePublicFacet }, auctioneerKit, + chainStorage, } = services; + const storageData = await getDataFromVstorage(chainStorage, 'whatever'); + t.log(storageData); + const { reserveTracker } = await getMetricTrackers({ t, collateralManager: aethCollateralManager, diff --git a/packages/inter-protocol/test/liquidationVisibility/test-visibilityAssertions.js b/packages/inter-protocol/test/liquidationVisibility/test-visibilityAssertions.js new file mode 100644 index 00000000000..7926216625a --- /dev/null +++ b/packages/inter-protocol/test/liquidationVisibility/test-visibilityAssertions.js @@ -0,0 +1,37 @@ +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; +import { E } from '@endo/far'; +import { makeImportContext} from "@agoric/smart-wallet/src/marshal-contexts.js"; +import { makeMockChainStorageRoot } from '../supports.js'; +import { getDataFromVstorage } from './tools.js'; +import { assertNodeInStorage } from "./assertions.js"; + +const { + fromBoard: { toCapData }, +} = makeImportContext(); + +const writeToStorage = async (storageNode, data) => { + await E(storageNode).setValue( + JSON.stringify(toCapData(JSON.stringify(data))), + ); +}; + +test('storage-node-created', async t => { + const storageRoot = makeMockChainStorageRoot(); + + await assertNodeInStorage({ + t, + rootNode: storageRoot, + desiredNode: 'test', + expected: false, + }); + + const testNode = await E(storageRoot).makeChildNode('test'); + await writeToStorage(testNode, { dummy: 'foo' }); + + await assertNodeInStorage({ + t, + rootNode: storageRoot, + desiredNode: 'test', + expected: true, + }); +}); diff --git a/packages/inter-protocol/test/liquidationVisibility/tools.js b/packages/inter-protocol/test/liquidationVisibility/tools.js index ceed4411071..7b8c1ea7c78 100644 --- a/packages/inter-protocol/test/liquidationVisibility/tools.js +++ b/packages/inter-protocol/test/liquidationVisibility/tools.js @@ -151,6 +151,7 @@ export const setupServices = async ( * AuctioneerKit, * ManualPriceAuthority, * CollateralManager, + * chainStorage, * ]} */ const [ @@ -161,6 +162,7 @@ export const setupServices = async ( auctioneerKit, priceAuthority, aethCollateralManager, + chainStorage, ] = await Promise.all([ E(consume.agoricNames).lookup('instance', 'VaultFactoryGovernor'), vaultFactoryCreatorFacetP, @@ -169,6 +171,7 @@ export const setupServices = async ( consume.auctioneerKit, /** @type {Promise} */ (consume.priceAuthority), E(aethVaultManagerP).getPublicFacet(), + space.consume.chainStorage, ]); trace(t, 'pa', { governorInstance, @@ -205,6 +208,7 @@ export const setupServices = async ( auctioneerKit, priceAuthorityAdmin, aethTestPriceAuthority, + chainStorage, }; };