Add commitment support to MockSubtensor #1635
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was intended to mock recently-added functions:
In order to "fairly" mock
MockSubtensor.commit()
andMockSubtensor.get_commitment()
, we should mockMockSubtensor.substrate = MockSubstrate()
. This wayMockSubtensor.commit()
will under the hood callbittensor.extrinsics.serving.publish_metadata()
which will use our newMockSubstrate
- so the behavior will be exactly the same as in production, except that substrate won't make an external call.However, I see that
MockSubtensor
does not use any mocked substrate, thus it doesn't use "fair" low-level logic. This leads to following consequences:bittensor.extrinsics.serving.publish_metadata
andbittensor.extrinsics.serving.get_metadata
since there is only "production" substrate class and they use it.MockSubtensor
does not really use low-level functions, thus if some low-level function is created/modified/deleted,MockSubtensor
will automatically diverge from originalSubtensor
.MockSubtensor
inherits fromsubtensor
, so if any new method is added tosubtensor
, then new non-mocked method appears inMockSubtensor
.Being said that, I would recommend to mock only real low-level network requests (the
SubstrateInterface
), so that everything else is mocked automatically now and in the future.Anyway, taking into account existing codebase and approach, I added
MockSubtensor.commit()
andMockSubtensor.get_commitment()
mocked methods.Usage: