Skip to content

Commit

Permalink
fix: set the simpleExchange notifier's initial order book state
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 11, 2020
1 parent 39275c2 commit 70c17fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/zoe/src/contracts/simpleExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { makeZoeHelpers, defaultAcceptanceMsg } from '../contractSupport';
const makeContract = zcf => {
let sellOfferHandles = [];
let buyOfferHandles = [];
const { notifier, updater } = produceNotifier();
// eslint-disable-next-line no-use-before-define
const { notifier, updater } = produceNotifier(getBookOrders());

const {
rejectOffer,
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/test/swingsetTests/zoe/test-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ test('zoe - simpleExchange - valid inputs', async t => {

const expectedSimpleExchangeNotificationLog = [
'=> alice, bob, carol and dave are set up',
'',
'{"buys":[],"sells":[]}',
'{"buys":[],"sells":[{"want":{"Price":{"brand":{},"extent":4}},"give":{"Asset":{"brand":{},"extent":3}}}]}',
'The offer has been accepted. Once the contract has been completed, please check your payout',
'{"buys":[],"sells":[]}',
Expand Down
35 changes: 32 additions & 3 deletions packages/zoe/test/unitTests/contracts/test-simpleExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { makeGetInstanceHandle } from '../../../src/clientSupport';
const simpleExchange = `${__dirname}/../../../src/contracts/simpleExchange`;

test('simpleExchange with valid offers', async t => {
t.plan(14);
t.plan(17);
const {
moolaIssuer,
simoleanIssuer,
Expand Down Expand Up @@ -52,6 +52,13 @@ test('simpleExchange with valid offers', async t => {
Price: simoleanIssuer,
});

const initialOrders = publicAPI.getNotifier().getCurrentUpdate().value;
t.deepEquals(
initialOrders,
{ buys: [], sells: [] },
`order notifier is initialized`,
);

const aliceInvite = publicAPI.makeInvite();

// 2: Alice escrows with zoe to create a sell order. She wants to
Expand All @@ -70,9 +77,24 @@ test('simpleExchange with valid offers', async t => {
offerHandle: aliceOfferHandle,
} = await zoe.offer(aliceInvite, aliceSellOrderProposal, alicePayments);

const afterAliceOrders = publicAPI.getNotifier().getCurrentUpdate().value;
t.deepEquals(
afterAliceOrders,
{
buys: [],
sells: [
{
want: aliceSellOrderProposal.want,
give: aliceSellOrderProposal.give,
},
],
},
`order notifier is updated with Alices sell order`,
);

aliceOfferHandle.then(handle => {
const aliceNotifier = zoe.getOfferNotifier(handle);
const firstUpdate = aliceNotifier.getUpdateSince();
const firstUpdate = aliceNotifier.getCurrentUpdate();
t.notOk(firstUpdate.value, 'notifier start state is empty');
t.notOk(firstUpdate.done, 'notifier start state is not done');
t.ok(firstUpdate.updateHandle, 'notifier start state has handle');
Expand Down Expand Up @@ -123,6 +145,13 @@ test('simpleExchange with valid offers', async t => {
bobPayments,
);

const afterBobOrders = publicAPI.getNotifier().getCurrentUpdate().value;
t.deepEquals(
afterBobOrders,
{ buys: [], sells: [] },
`order notifier is updated when Bob fulfills the order`,
);

t.equals(
await bobOutcomeP,
'The offer has been accepted. Once the contract has been completed, please check your payout',
Expand Down Expand Up @@ -259,7 +288,7 @@ test('simpleExchange with multiple sell offers', async t => {
],
};
t.deepEquals(
publicAPI.getNotifier().getUpdateSince().value,
publicAPI.getNotifier().getCurrentUpdate().value,
expectedBook,
);
});
Expand Down

0 comments on commit 70c17fd

Please sign in to comment.