-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IND-460] Emit deleveraging events from protocol (#736)
- Loading branch information
Showing
20 changed files
with
1,144 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { logger, ParseMessageError } from '@dydxprotocol-indexer/base'; | ||
import { DeleveragingEventV1, IndexerTendermintBlock, IndexerTendermintEvent } from '@dydxprotocol-indexer/v4-protos'; | ||
import { DydxIndexerSubtypes } from '../../src/lib/types'; | ||
import { DeleveragingValidator } from '../../src/validators/deleveraging-validator'; | ||
import { | ||
defaultDeleveragingEvent, defaultHeight, defaultTime, defaultTxHash, | ||
} from '../helpers/constants'; | ||
import { createIndexerTendermintBlock, createIndexerTendermintEvent } from '../helpers/indexer-proto-helpers'; | ||
import { expectDidntLogError, expectLoggedParseMessageError } from '../helpers/validator-helpers'; | ||
|
||
describe('deleveraging-validator', () => { | ||
beforeEach(() => { | ||
jest.spyOn(logger, 'error'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('validate', () => { | ||
it('does not throw error on valid deleveraging', () => { | ||
const validator: DeleveragingValidator = new DeleveragingValidator( | ||
defaultDeleveragingEvent, | ||
createBlock(defaultDeleveragingEvent), | ||
); | ||
|
||
validator.validate(); | ||
expectDidntLogError(); | ||
}); | ||
|
||
it.each([ | ||
[ | ||
'does not contain liquidated', | ||
{ | ||
...defaultDeleveragingEvent, | ||
liquidated: undefined, | ||
}, | ||
'DeleveragingEvent must have a liquidated subaccount id', | ||
], | ||
[ | ||
'does not contain offsetting', | ||
{ | ||
...defaultDeleveragingEvent, | ||
offsetting: undefined, | ||
}, | ||
'DeleveragingEvent must have an offsetting subaccount id', | ||
], | ||
])('throws error if event %s', (_message: string, event: DeleveragingEventV1, message: string) => { | ||
const validator: DeleveragingValidator = new DeleveragingValidator( | ||
event, | ||
createBlock(event), | ||
); | ||
|
||
expect(() => validator.validate()).toThrow(new ParseMessageError(message)); | ||
expectLoggedParseMessageError( | ||
DeleveragingValidator.name, | ||
message, | ||
{ event }, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
function createBlock( | ||
deleveragingEvent: DeleveragingEventV1, | ||
): IndexerTendermintBlock { | ||
const event: IndexerTendermintEvent = createIndexerTendermintEvent( | ||
DydxIndexerSubtypes.DELEVERAGING, | ||
DeleveragingEventV1.encode(deleveragingEvent).finish(), | ||
0, | ||
0, | ||
); | ||
|
||
return createIndexerTendermintBlock( | ||
defaultHeight, | ||
defaultTime, | ||
[event], | ||
[defaultTxHash], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.