Skip to content

Commit

Permalink
[Polling tests] Validate concrete orders (#161)
Browse files Browse the repository at this point in the history
* Test validation on concrete orders

* Update jest
  • Loading branch information
anxolin authored Sep 1, 2023
1 parent c1ed797 commit bd550ee
Show file tree
Hide file tree
Showing 3 changed files with 486 additions and 329 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@openzeppelin/merkle-tree": "^1.0.5",
"cross-fetch": "^3.1.5",
"exponential-backoff": "^3.1.1",
"graphql-request": "^4.3.0",
"graphql": "^16.3.0",
"graphql-request": "^4.3.0",
"limiter": "^2.1.0"
},
"peerDependencies": {
Expand All @@ -63,7 +63,7 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unused-imports": "^3.0.0",
"ethers": "^5.7.2",
"jest": "^29.4.2",
"jest": "^29.6.4",
"jest-fetch-mock": "^3.0.3",
"microbundle": "^0.15.1",
"openapi-typescript-codegen": "^0.23.0",
Expand Down
31 changes: 27 additions & 4 deletions src/composable/ConditionalOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('Poll Single Orders', () => {
} as any)
})

test.only('[SUCCESS] Happy path', async () => {
test('[SUCCESS] Happy path', async () => {
// GIVEN: An order that is authorized
mockSingleOrders.mockReturnValue(true)

Expand All @@ -196,7 +196,7 @@ describe('Poll Single Orders', () => {
const pollResult = await SINGLE_ORDER.poll(param)

// THEN: we expect a CALL to getTradeableOrderWithSignature with the owner, params, off-chain input, and no-proof
expect(mockGetTradeableOrderWithSignature.mock.calls).toHaveLength(1)
expect(mockGetTradeableOrderWithSignature).toBeCalledTimes(1)
expect(mockGetTradeableOrderWithSignature.mock.calls[0]).toEqual([
OWNER,
SINGLE_ORDER.leaf,
Expand All @@ -212,7 +212,7 @@ describe('Poll Single Orders', () => {
})
})

test.only('[DONT_TRY_AGAIN] Not authorized', async () => {
test('[DONT_TRY_AGAIN] Not authorized', async () => {
// GIVEN: An order that is not authorized
mockSingleOrders.mockReturnValue(false)

Expand All @@ -223,11 +223,34 @@ describe('Poll Single Orders', () => {
const pollResult = await SINGLE_ORDER.poll(param)

// THEN: We expect an error. We shouldn't try again
pollResult.result === PollResultCode.UNEXPECTED_ERROR && console.error(pollResult.error)
expect(pollResult).toEqual({
result: PollResultCode.DONT_TRY_AGAIN,
reason:
'NotAuthorized: Order 0x88ca0698d8c5500b31015d84fa0166272e1812320d9af8b60e29ae00153363b3 is not authorized for 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 on chain 1',
})
})

test('[DONT_TRY_AGAIN] Invalid Conditional Order: Concrete order validation fails', async () => {
// GIVEN: The concrete order implementation is not valid
const order = createOrder()
const validationError = 'Not valid, because I say so!'
const mockIsValid = jest.fn(order.isValid).mockReturnValue({ isValid: false, reason: validationError })
order.isValid = mockIsValid

// GIVEN: Everything else is OK (auth + contract returns an order)
mockSingleOrders.mockReturnValue(true)
mockGetTradeableOrderWithSignature.mockReturnValue([DISCRETE_ORDER, signature])

// WHEN: we poll
const pollResult = await order.poll(param)

// THEN: we expect no CALLs to the
expect(mockGetTradeableOrderWithSignature).toBeCalledTimes(0)

// THEN: We expect a SUCCESS result, which returns the order and the signature
expect(pollResult).toEqual({
result: PollResultCode.DONT_TRY_AGAIN,
reason: 'InvalidConditionalOrder. Reason: ' + validationError,
})
})
})
Loading

0 comments on commit bd550ee

Please sign in to comment.