@@ -884,7 +884,7 @@ const setupPlanner = async t => {
884884 const planner1 = plannerClientMock ( walletPlanner , started . instance , ( ) =>
885885 readPublished ( `wallet.agoric1planner` ) ,
886886 ) ;
887- return { common, zoe, started, trader1, planner1 } ;
887+ return { common, zoe, started, trader1, planner1, readPublished } ;
888888} ;
889889
890890test ( 'redeem, use planner invitation' , async t => {
@@ -1227,3 +1227,66 @@ test('simple rebalance using planner', async t => {
12271227 ] ) ;
12281228 t . is ( 833332500n , ( 3333330000n * 25n ) / 100n ) ;
12291229} ) ;
1230+
1231+ test ( 'create+deposit using planner' , async t => {
1232+ const { common, trader1, planner1, readPublished } = await setupPlanner ( t ) ;
1233+ const { usdc } = common . brands ;
1234+
1235+ await planner1 . redeem ( ) ;
1236+
1237+ const traderP = ( async ( ) => {
1238+ const Deposit = usdc . units ( 1_000 ) ;
1239+ await Promise . all ( [
1240+ trader1 . openPortfolio ( t , { Deposit } , { targetAllocation : { USDN : 1n } } ) ,
1241+ ackNFA ( common . utils ) ,
1242+ ] ) ;
1243+ t . log ( 'trader created with deposit' , Deposit ) ;
1244+ } ) ( ) ;
1245+
1246+ const plannerP = ( async ( ) => {
1247+ const getStatus = async pId => {
1248+ // NOTE: readPublished uses eventLoopIteration() to let vstorage writes settle
1249+ const x = await readPublished ( `portfolios.portfolio${ pId } ` ) ;
1250+ return x as unknown as StatusFor [ 'portfolio' ] ;
1251+ } ;
1252+
1253+ const pId = 0 ;
1254+ const {
1255+ flowsRunning = { } ,
1256+ policyVersion,
1257+ rebalanceCount,
1258+ } = await getStatus ( pId ) ;
1259+ t . is ( keys ( flowsRunning ) . length , 1 ) ;
1260+ const [ [ flowId , detail ] ] = Object . entries ( flowsRunning ) ;
1261+ const fId = Number ( flowId . replace ( 'flow' , '' ) ) ;
1262+
1263+ // narrow the type
1264+ if ( detail . type !== 'deposit' ) throw t . fail ( detail . type ) ;
1265+
1266+ // XXX brand from vstorage isn't suitable for use in call to kit
1267+ const amount = AmountMath . make ( usdc . brand , detail . amount . value ) ;
1268+
1269+ const plan : MovementDesc [ ] = [
1270+ { src : '<Deposit>' , dest : '@agoric' , amount } ,
1271+ ] ;
1272+ await E ( planner1 . stub ) . resolvePlan (
1273+ pId ,
1274+ fId ,
1275+ plan ,
1276+ policyVersion ,
1277+ rebalanceCount ,
1278+ ) ;
1279+ t . log ( 'planner resolved plan' ) ;
1280+ } ) ( ) ;
1281+
1282+ await Promise . all ( [ traderP , plannerP ] ) ;
1283+
1284+ const bankTraffic = common . utils . inspectBankBridge ( ) ;
1285+ const { accountIdByChain } = await trader1 . getPortfolioStatus ( ) ;
1286+ const [ _ns , _ref , addr ] = accountIdByChain . agoric ! . split ( ':' ) ;
1287+ const myVBankIO = bankTraffic . filter ( obj =>
1288+ [ obj . sender , obj . recipient ] . includes ( addr ) ,
1289+ ) ;
1290+ t . log ( 'bankBridge for' , addr , myVBankIO ) ;
1291+ t . like ( myVBankIO , [ { type : 'VBANK_GIVE' , amount : '1000000000' } ] ) ;
1292+ } ) ;
0 commit comments