Skip to content

Commit

Permalink
test: makeFakeBankManagerKit
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 24, 2024
1 parent 65dad73 commit ce7886e
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 110 deletions.
16 changes: 6 additions & 10 deletions packages/inter-protocol/test/provisionPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
import committeeBundle from '@agoric/governance/bundles/bundle-committee.js';
import { WalletName } from '@agoric/internal';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { publishDepositFacet } from '@agoric/smart-wallet/src/walletFactory.js';
import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js';
import { makeScalarBigMapStore } from '@agoric/vat-data';
import centralSupplyBundle from '@agoric/vats/bundles/bundle-centralSupply.js';
import { makeNameHubKit } from '@agoric/vats/src/nameHub.js';
import { buildRootObject as buildBankRoot } from '@agoric/vats/src/vat-bank.js';
import { PowerFlags } from '@agoric/vats/src/walletFlags.js';
import { makeFakeBankKit } from '@agoric/vats/tools/bank-utils.js';
import {
makeFakeBankKit,
makeFakeBankManagerKit,
} from '@agoric/vats/tools/bank-utils.js';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
import { E, Far } from '@endo/far';
import path from 'path';
import { publishDepositFacet } from '@agoric/smart-wallet/src/walletFactory.js';
import { makeBridgeProvisionTool } from '../src/provisionPoolKit.js';
import {
makeMockChainStorageRoot,
Expand Down Expand Up @@ -275,12 +276,7 @@ test('provisionPool trades provided assets for IST', async t => {
* @param {string[]} addresses
*/
const makeWalletFactoryKitForAddresses = async addresses => {
const baggage = makeScalarBigMapStore('bank baggage');
const bankManager = await buildBankRoot(
undefined,
undefined,
baggage,
).makeBankManager();
const { bankManager } = await makeFakeBankManagerKit();

const feeKit = makeIssuerKit('FEE');
const fees = withAmountUtils(feeKit);
Expand Down
1 change: 0 additions & 1 deletion packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const makeLocalChainFacade = localchain => {
return {
deposit(payment) {
console.log('deposit got', payment);
// XXX yet again tripped up on remote methods looking local statically
return E(account).deposit(payment);
},
transferSteps(amount, msg) {
Expand Down
14 changes: 5 additions & 9 deletions packages/orchestration/test/examples/swapExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import path from 'path';
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { makeHeapZone } from '@agoric/zone';
import { prepareLocalChainTools } from '@agoric/vats/src/localchain.js';
import { buildRootObject as buildBankVatRoot } from '@agoric/vats/src/vat-bank.js';
import { withAmountUtils } from '@agoric/zoe/tools/test-utils.js';
import { makeFakeBankBridge } from '@agoric/vats/tools/fake-bridge.js';
import { makeFakeBankManagerKit } from '@agoric/vats/tools/bank-utils.js';
import { LOCALCHAIN_DEFAULT_ADDRESS } from '@agoric/vats/tools/fake-bridge.js';
import { makeFakeLocalchainBridge } from '../supports.js';

const dirname = path.dirname(new URL(import.meta.url).pathname);
Expand All @@ -28,11 +28,7 @@ test('start', async t => {
const zone = makeHeapZone();
const { makeLocalChain } = prepareLocalChainTools(zone.subZone('localchain'));

const bankManager = await buildBankVatRoot(
undefined,
undefined,
zone.mapStore('bankManager'),
).makeBankManager(makeFakeBankBridge(zone));
const { bankManager, pourPayment } = await makeFakeBankManagerKit();

await E(bankManager).addAsset('uist', 'IST', 'Inter Stable Token', issuerKit);

Expand Down Expand Up @@ -70,7 +66,7 @@ test('start', async t => {
);

const bank = await E(bankManager).getBankForAddress(
'agoric1fakeBridgeAddress',
LOCALCHAIN_DEFAULT_ADDRESS,
);

const istPurse = await E(bank).getPurse(issuerKit.brand);
Expand All @@ -81,7 +77,7 @@ test('start', async t => {
const userSeat = await E(zoe).offer(
inv,
{ give: { Stable: ten } },
{ Stable: stable.mint.mintPayment(ten) },
{ Stable: await pourPayment(ten) },
{
staked: ten,
validator: {
Expand Down
7 changes: 2 additions & 5 deletions packages/orchestration/test/examples/unbondExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { withAmountUtils } from '@agoric/zoe/tools/test-utils.js';
import { makeHeapZone } from '@agoric/zone';
import { E } from '@endo/far';
import path from 'path';
import { makeFakeBankManagerKit } from '@agoric/vats/tools/bank-utils.js';
import { makeFakeLocalchainBridge } from '../supports.js';

const dirname = path.dirname(new URL(import.meta.url).pathname);
Expand All @@ -26,11 +27,7 @@ test('start', async t => {

const zone = makeHeapZone();
const { makeLocalChain } = prepareLocalChainTools(zone.subZone('localchain'));
const bankManager = await buildBankVatRoot(
undefined,
undefined,
zone.mapStore('bankManager'),
).makeBankManager();
const { bankManager } = await makeFakeBankManagerKit();

await E(bankManager).addAsset('uist', 'IST', 'Inter Stable Token', issuerKit);

Expand Down
10 changes: 3 additions & 7 deletions packages/smart-wallet/test/addAsset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/* eslint @typescript-eslint/no-floating-promises: "warn" */
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { E, Far } from '@endo/far';
import { buildRootObject as buildBankVatRoot } from '@agoric/vats/src/vat-bank.js';
import { AmountMath, makeIssuerKit } from '@agoric/ertp';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { makeCopyBag, makeScalarMapStore } from '@agoric/store';
import { makeCopyBag } from '@agoric/store';
import { makePromiseKit } from '@endo/promise-kit';
import bundleSource from '@endo/bundle-source';
import { makeMarshal } from '@endo/marshal';
import { resolve as importMetaResolve } from 'import-meta-resolve';
import { makeFakeBankManagerKit } from '@agoric/vats/tools/bank-utils.js';
import { makeDefaultTestContext } from './contexts.js';
import { ActionType, headValue, makeMockTestSpace } from './supports.js';
import { makeImportContext } from '../src/marshal-contexts.js';
Expand All @@ -24,11 +24,7 @@ const test = anyTest;

test.before(async t => {
const withBankManager = async () => {
const noBridge = undefined;
const baggage = makeScalarMapStore('baggage');
const bankManager = E(
buildBankVatRoot(undefined, undefined, baggage),
).makeBankManager(noBridge);
const { bankManager } = await makeFakeBankManagerKit();
const noop = () => {};
const space0 = await makeMockTestSpace(noop);
space0.produce.bankManager.reset();
Expand Down
17 changes: 4 additions & 13 deletions packages/smart-wallet/test/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { setupClientManager } from '@agoric/vats/src/core/chain-behaviors.js';
import { buildRootObject as boardRoot } from '@agoric/vats/src/vat-board.js';
import { buildRootObject as mintsRoot } from '@agoric/vats/src/vat-mints.js';
import { makeFakeBankKit } from '@agoric/vats/tools/bank-utils.js';
import { makeFakeBankManagerKit } from '@agoric/vats/tools/bank-utils.js';
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
import { setUpZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import { E, Far } from '@endo/far';
Expand Down Expand Up @@ -136,18 +136,9 @@ export const makeMockTestSpace = async log => {

produce.testFirstAnchorKit.resolve(makeIssuerKit('AUSD', 'nat'));

const fakeBankKit = makeFakeBankKit([]);

produce.bankManager.resolve(
Promise.resolve(
Far(
'mockBankManager',
/** @type {any} */ ({
getBankForAddress: _a => fakeBankKit.bank,
}),
),
),
);
const { bankManager } = await makeFakeBankManagerKit();

produce.bankManager.resolve(bankManager);

await Promise.all([
// @ts-expect-error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { makeTracer } from '@agoric/internal';
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { makeNameHubKit } from '@agoric/vats';
import { makeAgoricNamesAccess } from '@agoric/vats/src/core/utils.js';
import { makeFakeBankManagerKit } from '@agoric/vats/tools/bank-utils.js';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeFakeBankKit } from '@agoric/vats/tools/bank-utils.js';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { makePromiseKit } from '@endo/promise-kit';
Expand All @@ -20,7 +20,7 @@ const walletAddr = 'agoric1whatever';
const moolaKit = makeIssuerKit('moola');

export const buildRootObject = async () => {
const { bank, addAsset } = makeFakeBankKit([]);
const { bankManager } = await makeFakeBankManagerKit();
const storageKit = makeFakeStorageKit('walletFactoryUpgradeTest');
const statusPath = `walletFactoryUpgradeTest.${walletAddr}`;
const currentPath = `${statusPath}.current`;
Expand All @@ -40,6 +40,8 @@ export const buildRootObject = async () => {
/** @type {import('../../../src/smartWallet.js').SmartWallet} */
let wallet;

const bank = await E(bankManager).getBankForAddress(walletAddr);

// for startInstance
/** @type {Installation<import('../../../src/walletFactory.js').start>} */
let installation;
Expand Down Expand Up @@ -104,7 +106,7 @@ export const buildRootObject = async () => {
).storagePath;
currentStoragePath === currentPath || Fail`bad storage path`;

addAsset('umoola', 'moola', 'moola', moolaKit);
await E(bankManager).addAsset('umoola', 'moola', 'moola', moolaKit);
const depositFacet = E(wallet).getDepositFacet();
const payment = moolaKit.mint.mintPayment(
AmountMath.make(moolaKit.brand, 100n),
Expand Down
4 changes: 4 additions & 0 deletions packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ const prepareBankChannelHandler = zone =>
try {
updater.update(value, nonce);
} catch (e) {
// ??? Is this an invariant that should complain louder?

// NB: this failure does not propagate. The update() method is
// responsible for propagating the errow without side-effects.
console.error('Error updating balance', update, e);
}
}
Expand Down
Loading

0 comments on commit ce7886e

Please sign in to comment.