|
| 1 | +import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; |
| 2 | + |
| 3 | +import type { TestFn } from 'ava'; |
| 4 | +import type { FastUSDCKit } from '@agoric/fast-usdc/src/fast-usdc.start.js'; |
| 5 | +import { Fail } from '@endo/errors'; |
| 6 | +import { unmarshalFromVstorage } from '@agoric/internal/src/marshal.js'; |
| 7 | +import { makeMarshal } from '@endo/marshal'; |
| 8 | +import { |
| 9 | + makeWalletFactoryContext, |
| 10 | + type WalletFactoryTestContext, |
| 11 | +} from '../bootstrapTests/walletFactory.js'; |
| 12 | + |
| 13 | +const test: TestFn<WalletFactoryTestContext> = anyTest; |
| 14 | + |
| 15 | +test.before('bootstrap', async t => { |
| 16 | + const config = '@agoric/vm-config/decentral-itest-orchestration-config.json'; |
| 17 | + t.context = await makeWalletFactoryContext(t, config); |
| 18 | +}); |
| 19 | +test.after.always(t => t.context.shutdown?.()); |
| 20 | + |
| 21 | +test.serial('oracles provision before contract deployment', async t => { |
| 22 | + const { walletFactoryDriver: wd } = t.context; |
| 23 | + const watcherWallet = await wd.provideSmartWallet('agoric1watcher1'); |
| 24 | + t.truthy(watcherWallet); |
| 25 | +}); |
| 26 | + |
| 27 | +test.serial( |
| 28 | + 'contract starts; adds to agoricNames; sends invitation', |
| 29 | + async t => { |
| 30 | + const { |
| 31 | + agoricNamesRemotes, |
| 32 | + evalProposal, |
| 33 | + buildProposal, |
| 34 | + refreshAgoricNamesRemotes, |
| 35 | + storage, |
| 36 | + walletFactoryDriver: wd, |
| 37 | + } = t.context; |
| 38 | + |
| 39 | + const watcherWallet = await wd.provideSmartWallet('agoric1watcher1'); |
| 40 | + |
| 41 | + const materials = buildProposal( |
| 42 | + '@agoric/builders/scripts/fast-usdc/init-fast-usdc.js', |
| 43 | + ['--oracle', 'a:agoric1watcher1'], |
| 44 | + ); |
| 45 | + await evalProposal(materials); |
| 46 | + |
| 47 | + // update now that fastUsdc is instantiated |
| 48 | + refreshAgoricNamesRemotes(); |
| 49 | + t.truthy(agoricNamesRemotes.instance.fastUsdc); |
| 50 | + t.truthy(agoricNamesRemotes.brand.FastLP); |
| 51 | + |
| 52 | + const { EV } = t.context.runUtils; |
| 53 | + const agoricNames = await EV.vat('bootstrap').consumeItem('agoricNames'); |
| 54 | + const board = await EV.vat('bootstrap').consumeItem('board'); |
| 55 | + const getBoardAux = async name => { |
| 56 | + const brand = await EV(agoricNames).lookup('brand', name); |
| 57 | + const id = await EV(board).getId(brand); |
| 58 | + t.truthy(storage.data.get(`published.boardAux.${id}`)); |
| 59 | + return unmarshalFromVstorage( |
| 60 | + storage.data, |
| 61 | + `published.boardAux.${id}`, |
| 62 | + makeMarshal().fromCapData, |
| 63 | + -1, |
| 64 | + ); |
| 65 | + }; |
| 66 | + t.like( |
| 67 | + await getBoardAux('FastLP'), |
| 68 | + { |
| 69 | + allegedName: 'PoolShares', // misnomer, in some contexts |
| 70 | + displayInfo: { |
| 71 | + assetKind: 'nat', |
| 72 | + decimalPlaces: 6, |
| 73 | + }, |
| 74 | + }, |
| 75 | + 'brand displayInfo available in boardAux', |
| 76 | + ); |
| 77 | + |
| 78 | + const current = watcherWallet.getCurrentWalletRecord(); |
| 79 | + |
| 80 | + // XXX We should be able to compare objects by identity like this: |
| 81 | + // |
| 82 | + // const invitationPurse = current.purses.find( |
| 83 | + // p => p.brand === agoricNamesRemotes.brand.Invitation, |
| 84 | + // ); |
| 85 | + // |
| 86 | + // But agoricNamesRemotes and walletFactoryDriver |
| 87 | + // don't share a marshal context. |
| 88 | + // We should be able to map between them using |
| 89 | + // const walletStuff = w.fromCapData(a.toCapData(aStuff)) |
| 90 | + // but the marshallers don't even preserve identity within themselves. |
| 91 | + |
| 92 | + current.purses.length === 1 || Fail`test limited to 1 purse`; |
| 93 | + const [thePurse] = current.purses; |
| 94 | + const details = thePurse.balance.value as Array<any>; |
| 95 | + Array.isArray(details) || Fail`expected SET value`; |
| 96 | + t.is(details.length, 1, 'oracle wallet has 1 invitation'); |
| 97 | + t.is(details[0].description, 'oracle operator invitation'); |
| 98 | + // XXX t.is(details.instance, agoricNames.instance.fastUsdc) should work |
| 99 | + }, |
| 100 | +); |
| 101 | + |
| 102 | +test.serial('restart contract', async t => { |
| 103 | + const { EV } = t.context.runUtils; |
| 104 | + await null; |
| 105 | + const kit = await EV.vat('bootstrap').consumeItem('fastUsdcKit'); |
| 106 | + const actual = await EV(kit.adminFacet).restartContract(kit.privateArgs); |
| 107 | + t.deepEqual(actual, { incarnationNumber: 1 }); |
| 108 | +}); |
0 commit comments