Skip to content

Commit

Permalink
chore(liquidationVisibility): #4 implement assertNodeInStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
anilhelvaci committed Jan 22, 2024
1 parent 89db737 commit 9fefcf0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/inter-protocol/test/liquidationVisibility/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
openVault,
getMetricTrackers,
adjustVault,
closeVault,
} from './tools.js';
closeVault, getDataFromVstorage
} from "./tools.js";
import {
assertBidderPayout,
assertCollateralProceeds,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
});
});
4 changes: 4 additions & 0 deletions packages/inter-protocol/test/liquidationVisibility/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const setupServices = async (
* AuctioneerKit,
* ManualPriceAuthority,
* CollateralManager,
* chainStorage,
* ]}
*/
const [
Expand All @@ -161,6 +162,7 @@ export const setupServices = async (
auctioneerKit,
priceAuthority,
aethCollateralManager,
chainStorage,
] = await Promise.all([
E(consume.agoricNames).lookup('instance', 'VaultFactoryGovernor'),
vaultFactoryCreatorFacetP,
Expand All @@ -169,6 +171,7 @@ export const setupServices = async (
consume.auctioneerKit,
/** @type {Promise<ManualPriceAuthority>} */ (consume.priceAuthority),
E(aethVaultManagerP).getPublicFacet(),
space.consume.chainStorage,
]);
trace(t, 'pa', {
governorInstance,
Expand Down Expand Up @@ -205,6 +208,7 @@ export const setupServices = async (
auctioneerKit,
priceAuthorityAdmin,
aethTestPriceAuthority,
chainStorage,
};
};

Expand Down

0 comments on commit 9fefcf0

Please sign in to comment.