Unverified Commit d855a5e9 authored by David's avatar David Committed by GitHub
Browse files

Fix mocking multiple http calls in the same function call (#6510)



* Fix mocking multiple http calls in the same function call

Fixes an issue where a function call would perform more than one http request and wait for each to complete before proceeding. The `RequestId` comes from the length of the `requests` collection in the `OffchainState` and if a request is completed before the next one starts it will be removed and the "next expected" will be off by one. This PR tries to fix that by using a request counter that tracks how many requests have been performed so that we can `remove()` items from the `expected_requests` at the right index.

I suspect that this is a sub-optimal soluton and perhaps requests and their mocks should live side by side in the same collection, e.g. in a tuple of `(PendingRequest, Option<ExpectedRequest>)`.

* Update primitives/core/src/offchain/testing.rs

Co-authored-by: default avatarBernhard Schuster <[email protected]>

* Update primitives/core/src/offchain/testing.rs

Co-authored-by: default avatarBernhard Schuster <[email protected]>

* Panic on overflow

* Update primitives/core/src/offchain/testing.rs

Co-authored-by: default avatarBastian Köcher <[email protected]>

* Use a Deque and push/pop expected requests

* fix test

Co-authored-by: default avatarBernhard Schuster <[email protected]>
Co-authored-by: default avatarBastian Köcher <[email protected]>
parent 23055a9e
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment