Skip to content

Commit

Permalink
feat(vats): Mock ERTP face on mock orch assets
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Nov 18, 2024
1 parent d1562a1 commit a04f8e6
Show file tree
Hide file tree
Showing 12 changed files with 1,131 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { M } from '@endo/patterns';

import { AmountShape, PaymentShape } from '@agoric/ertp';
import { AnyNatAmountShape } from '../../typeGuards.js';
import { mockIssuerInterfaces } from './typeGuards.js';
import { MockOrchAccountShape } from '../mock-orch/typeGuards.js';

export const RecoverySetShape = M.remotable('RecoverySet');
export const RecoveryFacetShape = M.remotable('RecoverFacet');

export const PaymentLedgerEntryShape = harden({
keyShape: PaymentShape,
valueShape: AnyNatAmountShape,
});

export const PaymentRecoveryEntryShape = harden({
keyShape: PaymentShape,
valueShape: RecoveryFacetShape,
});

/**
* @param {Pattern} [brandShape]
* @param {Pattern} [assetKindShape]
* @param {Pattern} [amountShape]
*/
export const mockIssuerInterfacesPlus = (
brandShape = undefined,
assetKindShape = undefined,
amountShape = AmountShape,
) => {
const {
IssuerI,
MintI,
PaymentI,
PurseIKit: MockPurseIKit,
} = mockIssuerInterfaces(brandShape, assetKindShape, amountShape);

const RecoveryFacetI = M.interface('RecoveryFacet', {
initPayment: M.call(PaymentShape).returns(),
deletePayment: M.call(PaymentShape).returns(),
getRecoverySetStore: M.call().returns(RecoverySetShape),
getCurrentEncumberedBalance: M.call().returns(amountShape),
encumber: M.call(amountShape).returns(),
unencumber: M.call(amountShape).returns(),
getOrchAcct: M.call().returns(MockOrchAccountShape),
});

const MockPurseIKitPlus = {
...MockPurseIKit,
recoveryFacet: RecoveryFacetI,
};

return harden({
IssuerI,
MintI,
PaymentI,
PurseIKit: MockPurseIKitPlus,
});
};
harden(mockIssuerInterfacesPlus);
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { WeakMapStore, SetStore } from '@agoric/store';

import type { Payment, Amount } from '@agoric/ertp';
import type { MockOrchAccount } from '../mock-orch/types.ts';

export type PaymentLedgerMap = WeakMapStore<Payment, Amount>;

export type RecoverySet = SetStore<Payment>;

export type RecoveryFacet = {
/**
*
*/
initPayment: (payment: Payment) => void;

/**
*
*/
deletePayment: (payment: Payment) => void;

/**
* Awkward name because `getRecoverSet` is already a method of purse that
* return a copySet.
*/
getRecoverySetStore: () => RecoverySet;

/**
* Get the amount contained all payments still in the recoverySet at this moment
*/
getCurrentEncumberedBalance: () => Amount;

/**
*
*/
encumber: (amount: Amount) => void;

/**
*
*/
unencumber: (amount: Amount) => void;

/**
*
*/
getOrchAcct: () => MockOrchAccount;
};

export type PaymentRecoveryMap = WeakMapStore<Payment, RecoveryFacet>;
Loading

0 comments on commit a04f8e6

Please sign in to comment.