-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix authority leak in wallet by adding attenuatedPursesNotifier (
- Loading branch information
Showing
4 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// @ts-check | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@agoric/install-ses'; // calls lockdown() | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import test from 'ava'; | ||
|
||
import { makeIssuerKit } from '@agoric/ertp'; | ||
import { makeZoe } from '@agoric/zoe'; | ||
import fakeVatAdmin from '@agoric/zoe/src/contractFacet/fakeVatAdmin'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { makeBoard } from '@agoric/cosmic-swingset/lib/ag-solo/vats/lib-board'; | ||
import { makeWallet } from '../src/lib-wallet'; | ||
|
||
import '../src/types'; | ||
|
||
const setup = async () => { | ||
const zoe = makeZoe(fakeVatAdmin); | ||
const board = makeBoard(); | ||
|
||
const pursesStateChangeHandler = _data => {}; | ||
const inboxStateChangeHandler = _data => {}; | ||
|
||
const { admin: wallet, initialized } = makeWallet({ | ||
zoe, | ||
board, | ||
pursesStateChangeHandler, | ||
inboxStateChangeHandler, | ||
}); | ||
await initialized; | ||
const MOOLA_ISSUER_PETNAME = 'moola'; | ||
const moolaKit = makeIssuerKit(MOOLA_ISSUER_PETNAME); | ||
|
||
const MOOLA_PURSE_PETNAME = 'fun money'; | ||
|
||
const issuerManager = wallet.getIssuerManager(); | ||
await issuerManager.add(MOOLA_ISSUER_PETNAME, moolaKit.issuer); | ||
await wallet.makeEmptyPurse(MOOLA_ISSUER_PETNAME, MOOLA_PURSE_PETNAME); | ||
return { wallet, moolaKit, MOOLA_ISSUER_PETNAME, MOOLA_PURSE_PETNAME }; | ||
}; | ||
|
||
test('getPursesNotifier', async t => { | ||
const { | ||
wallet, | ||
moolaKit, | ||
MOOLA_ISSUER_PETNAME, | ||
MOOLA_PURSE_PETNAME, | ||
} = await setup(); | ||
const pursesNotifier = wallet.getPursesNotifier(); | ||
const update = await pursesNotifier.getUpdateSince(); | ||
t.is(update.updateCount, 7); | ||
// Has the default Zoe invitation purse and a moola purse | ||
t.is(update.value.length, 2); | ||
const moolaPurseInfo = update.value[1]; | ||
t.truthy(moolaPurseInfo.actions); | ||
t.is(moolaPurseInfo.brand, moolaKit.brand); | ||
t.is(moolaPurseInfo.brandBoardId, '1532665031'); | ||
t.is(moolaPurseInfo.brandPetname, MOOLA_ISSUER_PETNAME); | ||
t.deepEqual(moolaPurseInfo.currentAmount, { | ||
brand: { kind: 'brand', petname: 'moola' }, // not a real amount | ||
value: 0, | ||
}); | ||
t.deepEqual(moolaPurseInfo.currentAmountSlots, { | ||
body: | ||
'{"brand":{"@qclass":"slot","iface":"Alleged: moola brand","index":0},"value":0}', | ||
slots: [ | ||
{ | ||
kind: 'brand', | ||
petname: 'moola', | ||
}, | ||
], | ||
}); | ||
t.deepEqual(moolaPurseInfo.displayInfo, { | ||
amountMathKind: 'nat', | ||
}); | ||
const moolaPurse = wallet.getPurse(MOOLA_PURSE_PETNAME); | ||
t.is(moolaPurseInfo.purse, moolaPurse); | ||
t.is(moolaPurseInfo.pursePetname, MOOLA_PURSE_PETNAME); | ||
t.is(moolaPurseInfo.value, 0); | ||
}); | ||
|
||
test('getAttenuatedPursesNotifier', async t => { | ||
const { wallet, MOOLA_ISSUER_PETNAME, MOOLA_PURSE_PETNAME } = await setup(); | ||
const pursesNotifier = wallet.getAttenuatedPursesNotifier(); | ||
const update = await pursesNotifier.getUpdateSince(); | ||
t.is(update.updateCount, 7); | ||
// Has the default Zoe invitation purse and a moola purse | ||
t.is(update.value.length, 2); | ||
const moolaPurseInfo = update.value[1]; | ||
// @ts-ignore | ||
t.is(moolaPurseInfo.actions, undefined); | ||
// @ts-ignore | ||
t.is(moolaPurseInfo.brand, undefined); | ||
t.is(moolaPurseInfo.brandBoardId, '1532665031'); | ||
t.is(moolaPurseInfo.brandPetname, MOOLA_ISSUER_PETNAME); | ||
t.deepEqual(moolaPurseInfo.currentAmount, { | ||
brand: { kind: 'brand', petname: 'moola' }, // not a real amount | ||
value: 0, | ||
}); | ||
t.deepEqual(moolaPurseInfo.currentAmountSlots, { | ||
body: | ||
'{"brand":{"@qclass":"slot","iface":"Alleged: moola brand","index":0},"value":0}', | ||
slots: [ | ||
{ | ||
kind: 'brand', | ||
petname: 'moola', | ||
}, | ||
], | ||
}); | ||
t.deepEqual(moolaPurseInfo.displayInfo, { | ||
amountMathKind: 'nat', | ||
}); | ||
|
||
// @ts-ignore | ||
t.is(moolaPurseInfo.purse, undefined); | ||
t.is(moolaPurseInfo.pursePetname, MOOLA_PURSE_PETNAME); | ||
t.is(moolaPurseInfo.value, 0); | ||
}); |