@@ -1200,9 +1200,10 @@ contract('DebtCache', async accounts => {
1200
1200
} ) ;
1201
1201
1202
1202
describe ( 'after the synths are exchanged into other synths' , async ( ) => {
1203
+ let tx ;
1203
1204
beforeEach ( async ( ) => {
1204
1205
// Swap some sETH into synthetic dollarydoos.
1205
- await synthetix . exchange ( sETH , '5' , sAUD , { from : account1 } ) ;
1206
+ tx = await synthetix . exchange ( sETH , '5' , sAUD , { from : account1 } ) ;
1206
1207
} ) ;
1207
1208
1208
1209
it ( 'non-SNX debt is unchanged' , async ( ) => {
@@ -1214,6 +1215,39 @@ contract('DebtCache', async accounts => {
1214
1215
it ( 'currentDebt is unchanged' , async ( ) => {
1215
1216
assert . bnEqual ( currentDebt , await debtCache . currentDebt ( ) ) ;
1216
1217
} ) ;
1218
+
1219
+ it ( 'cached debt is properly updated' , async ( ) => {
1220
+ const logs = await getDecodedLogs ( {
1221
+ hash : tx . tx ,
1222
+ contracts : [ debtCache ] ,
1223
+ } ) ;
1224
+
1225
+ const cachedDebt = ( await debtCache . cacheInfo ( ) ) [ 0 ] ;
1226
+ decodedEventEqual ( {
1227
+ event : 'DebtCacheUpdated' ,
1228
+ emittedFrom : debtCache . address ,
1229
+ args : [ cachedDebt ] ,
1230
+ log : logs . find ( ( { name } = { } ) => name === 'DebtCacheUpdated' ) ,
1231
+ } ) ;
1232
+ } ) ;
1233
+ } ) ;
1234
+
1235
+ it ( 'is properly reflected in a snapshot' , async ( ) => {
1236
+ const currentDebt = ( await debtCache . currentDebt ( ) ) [ 0 ] ;
1237
+ const cachedDebt = ( await debtCache . cacheInfo ( ) ) [ 0 ] ;
1238
+ assert . bnEqual ( currentDebt , cachedDebt ) ;
1239
+ const tx = await debtCache . takeDebtSnapshot ( ) ;
1240
+ const logs = await getDecodedLogs ( {
1241
+ hash : tx . tx ,
1242
+ contracts : [ debtCache ] ,
1243
+ } ) ;
1244
+
1245
+ decodedEventEqual ( {
1246
+ event : 'DebtCacheUpdated' ,
1247
+ emittedFrom : debtCache . address ,
1248
+ args : [ cachedDebt ] ,
1249
+ log : logs . find ( ( { name } = { } ) => name === 'DebtCacheUpdated' ) ,
1250
+ } ) ;
1217
1251
} ) ;
1218
1252
} ) ;
1219
1253
0 commit comments