@@ -71,19 +71,32 @@ test('issuer.getAmountMathKind', t => {
71
71
} ) ;
72
72
73
73
test ( 'issuer.makeEmptyPurse' , async t => {
74
- t . plan ( 6 ) ;
74
+ t . plan ( 9 ) ;
75
75
const { issuer, mint, amountMath, brand } = makeIssuerKit ( 'fungible' ) ;
76
76
const purse = issuer . makeEmptyPurse ( ) ;
77
77
const payment = mint . mintPayment ( amountMath . make ( 837 ) ) ;
78
78
79
+ const notifier = purse . getCurrentAmountNotifier ( ) ;
80
+ let nextUpdate = notifier . getUpdateSince ( ) ;
81
+
82
+ const checkNotifier = async ( ) => {
83
+ const { value : balance , updateCount } = await nextUpdate ;
84
+ t . assert (
85
+ amountMath . isEqual ( purse . getCurrentAmount ( ) , balance ) ,
86
+ `the notifier balance is the same as the purse` ,
87
+ ) ;
88
+ nextUpdate = notifier . getUpdateSince ( updateCount ) ;
89
+ } ;
90
+
79
91
t . assert (
80
92
amountMath . isEqual ( purse . getCurrentAmount ( ) , amountMath . getEmpty ( ) ) ,
81
93
`empty purse is empty` ,
82
94
) ;
95
+ await checkNotifier ( ) ;
83
96
t . is ( purse . getAllegedBrand ( ) , brand , `purse's brand is correct` ) ;
84
97
const fungible837 = amountMath . make ( 837 ) ;
85
98
86
- const checkDeposit = newPurseBalance => {
99
+ const checkDeposit = async newPurseBalance => {
87
100
t . assert (
88
101
amountMath . isEqual ( newPurseBalance , fungible837 ) ,
89
102
`the balance returned is the purse balance` ,
@@ -92,11 +105,12 @@ test('issuer.makeEmptyPurse', async t => {
92
105
amountMath . isEqual ( purse . getCurrentAmount ( ) , fungible837 ) ,
93
106
`the new purse balance is the payment's old balance` ,
94
107
) ;
108
+ await checkNotifier ( ) ;
95
109
} ;
96
110
97
111
const performWithdrawal = ( ) => purse . withdraw ( fungible837 ) ;
98
112
99
- const checkWithdrawal = newPayment => {
113
+ const checkWithdrawal = async newPayment => {
100
114
issuer . getAmountOf ( newPayment ) . then ( amount => {
101
115
t . assert (
102
116
amountMath . isEqual ( amount , fungible837 ) ,
@@ -107,6 +121,7 @@ test('issuer.makeEmptyPurse', async t => {
107
121
amountMath . isEqual ( purse . getCurrentAmount ( ) , amountMath . getEmpty ( ) ) ,
108
122
`the purse is empty again` ,
109
123
) ;
124
+ await checkNotifier ( ) ;
110
125
} ;
111
126
112
127
await E ( purse )
@@ -117,21 +132,33 @@ test('issuer.makeEmptyPurse', async t => {
117
132
} ) ;
118
133
119
134
test ( 'purse.deposit' , async t => {
120
- t . plan ( 4 ) ;
135
+ t . plan ( 7 ) ;
121
136
const { issuer, mint, amountMath } = makeIssuerKit ( 'fungible' ) ;
122
137
const fungible0 = amountMath . getEmpty ( ) ;
123
138
const fungible17 = amountMath . make ( 17 ) ;
124
139
const fungible25 = amountMath . make ( 25 ) ;
125
140
const fungibleSum = amountMath . add ( fungible17 , fungible25 ) ;
126
141
127
142
const purse = issuer . makeEmptyPurse ( ) ;
143
+ const notifier = purse . getCurrentAmountNotifier ( ) ;
128
144
const payment17 = mint . mintPayment ( fungible17 ) ;
129
145
const payment25 = mint . mintPayment ( fungible25 ) ;
130
146
147
+ let nextUpdate = notifier . getUpdateSince ( ) ;
148
+
149
+ const checkNotifier = async ( ) => {
150
+ const { value : balance , updateCount } = await nextUpdate ;
151
+ t . assert (
152
+ amountMath . isEqual ( purse . getCurrentAmount ( ) , balance ) ,
153
+ `the notifier balance is the same as the purse` ,
154
+ ) ;
155
+ nextUpdate = notifier . getUpdateSince ( updateCount ) ;
156
+ } ;
157
+
131
158
const checkDeposit = (
132
159
expectedOldBalance ,
133
160
expectedNewBalance ,
134
- ) => depositResult => {
161
+ ) => async depositResult => {
135
162
const delta = amountMath . subtract ( expectedNewBalance , expectedOldBalance ) ;
136
163
t . assert (
137
164
amountMath . isEqual ( depositResult , delta ) ,
@@ -141,8 +168,10 @@ test('purse.deposit', async t => {
141
168
amountMath . isEqual ( purse . getCurrentAmount ( ) , expectedNewBalance ) ,
142
169
`the new purse balance ${ depositResult . value } is the expected amount: ${ expectedNewBalance . value } ` ,
143
170
) ;
171
+ await checkNotifier ( ) ;
144
172
} ;
145
173
174
+ await checkNotifier ( ) ;
146
175
await E ( purse )
147
176
. deposit ( payment17 , fungible17 )
148
177
. then ( checkDeposit ( fungible0 , fungible17 ) ) ;
@@ -169,14 +198,25 @@ test('purse.deposit promise', async t => {
169
198
} ) ;
170
199
171
200
test ( 'purse.getDepositFacet' , async t => {
172
- t . plan ( 2 ) ;
201
+ t . plan ( 4 ) ;
173
202
const { issuer, mint, amountMath } = makeIssuerKit ( 'fungible' ) ;
174
203
const fungible25 = amountMath . make ( 25 ) ;
175
204
176
205
const purse = issuer . makeEmptyPurse ( ) ;
177
206
const payment = mint . mintPayment ( fungible25 ) ;
207
+ const notifier = purse . getCurrentAmountNotifier ( ) ;
208
+
209
+ let nextUpdate = notifier . getUpdateSince ( ) ;
210
+ const checkNotifier = async ( ) => {
211
+ const { value : balance , updateCount } = await nextUpdate ;
212
+ nextUpdate = notifier . getUpdateSince ( updateCount ) ;
213
+ t . assert (
214
+ amountMath . isEqual ( purse . getCurrentAmount ( ) , balance ) ,
215
+ `the notifier balance is the same as the purse's` ,
216
+ ) ;
217
+ } ;
178
218
179
- const checkDeposit = newPurseBalance => {
219
+ const checkDeposit = async newPurseBalance => {
180
220
t . assert (
181
221
amountMath . isEqual ( newPurseBalance , fungible25 ) ,
182
222
`the balance returned is the purse balance` ,
@@ -185,8 +225,10 @@ test('purse.getDepositFacet', async t => {
185
225
amountMath . isEqual ( purse . getCurrentAmount ( ) , fungible25 ) ,
186
226
`the new purse balance is the payment's old balance` ,
187
227
) ;
228
+ await checkNotifier ( ) ;
188
229
} ;
189
230
231
+ await checkNotifier ( ) ;
190
232
await E ( purse )
191
233
. getDepositFacet ( )
192
234
. then ( ( { receive } ) => receive ( payment ) )
0 commit comments