Skip to content

Commit

Permalink
refactor: factor trackDeposits out of Rose, Rex
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Mar 5, 2024
1 parent 486bc8b commit fc97a69
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions contract/test/market-actors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
};
Expand All @@ -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));
};
Expand Down

0 comments on commit fc97a69

Please sign in to comment.