diff --git a/contract/test/market-actors.js b/contract/test/market-actors.js index c9188ab6..56856ab3 100644 --- a/contract/test/market-actors.js +++ b/contract/test/market-actors.js @@ -69,6 +69,21 @@ export const payerPete = async ( } }; +const trackDeposits = async (t, initial, purseNotifier, toSend) => + allValues( + fromEntries( + entries(initial).map(([name, _update]) => { + const amtP = purseNotifier[name].next().then(u => { + const expected = AmountMath.add(initial[name], toSend[name]); + t.log('updated balance', name, u.value); + t.deepEqual(u.value, expected); + return u.value; + }); + return [name, amtP]; + }), + ), + ); + /** * Rose expects to receive `shared.toSend` amounts. * She expects initial balances to be empty; @@ -93,19 +108,7 @@ export const receiverRose = async (t, { wallet }, { toSend }) => { t.log('Rose initial', initial); t.deepEqual(keys(initial), keys(toSend)); - const done = await allValues( - fromEntries( - entries(initial).map(([name, _update]) => { - const amtP = purseNotifier[name].next().then(u => { - const expected = AmountMath.add(initial[name], toSend[name]); - t.log('Rose updated balance', name, u.value); - t.deepEqual(u.value, expected); - return u.value; - }); - return [name, amtP]; - }), - ), - ); + const done = await trackDeposits(t, initial, purseNotifier, toSend); t.log('Rose got balance updates', keys(done)); t.deepEqual(keys(done), keys(toSend)); }; @@ -125,20 +128,8 @@ export const receiverRex = async (t, { wallet }, { toSend }) => { const initial = await allValues(mapValues(purseUpdates, pn => E(pn).next())); - const done = await allValues( - fromEntries( - keys(initial).map(name => { - const amtP = E(purseUpdates[name]) - .next() - .then(u => { - t.log('Rex rxd', u.value); - t.deepEqual(u.value, toSend[name]); - return u.value; - }); - return [name, amtP]; - }), - ), - ); + const done = await trackDeposits(t, initial, purseUpdates, toSend); + t.log('Rex got balance updates', keys(done)); t.deepEqual(keys(done), keys(toSend)); };