Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A better abstraction is required in order to access the chain state #166

Open
ggrieco-tob opened this issue Jun 22, 2023 · 1 comment
Open
Labels
on hold This issue was marked as not desirable to complete for now very-low-priority

Comments

@ggrieco-tob
Copy link
Member

One of the objectives of medusa is to allow easy extensions of the code. I recently created a PR to optimize the gas usage instead of a call to a particular function. While it was not very complicated, the API to query the TestChain object should be improved. For instance, in order to access to the receipt of the last transaction, I had to check the pending block. If there is no transactions pending, I had to look at the last block:

		pending := worker.Chain().PendingBlock()
		var gasUsed uint64 = 0
		if pending != nil {
			messagesLen := len(pending.MessageResults)
			if messagesLen > 0 {
				gasUsed = pending.MessageResults[messagesLen-1].Receipt.GasUsed
			}
		} else {
			blocks := worker.Chain().CommittedBlocks()
			blocksLen := len(blocks)
			lastBlock := blocks[blocksLen-1]
			messagesLen := len(lastBlock.MessageResults)
			gasUsed = lastBlock.MessageResults[messagesLen-1].Receipt.GasUsed
		}

I believe this is inherited from geth and it is not clear for me how to improve it to allow a more uniform access to the latest transactions, but it could be a good idea to improve for future extensions.

@Xenomega
Copy link
Member

Good callout. We've had similar discussions with @Jaime-Iglesias . I'll drop some thoughts here stemming from those discussions.

This PR should extend past TestChain and we can provide some nice helper functions for various providers (wrapping ContractDefinitions + deployments to provide methods), features to quickly get receipts, last block, events across multiple blocks, contract deployments/destruction events. Maybe some functions to iterate over execution traces to check if some conditions occurred during execution, etc.

Until we finish the higher level testing API, maybe this should be lower priority. Once we have that, it will be more clear to us what higher level functions would be useful to have. So lets wait to add this just until then, as our testing loop, and testing framework will change and uncover what we should invest into more, and how the API should look.

So maybe we should do a post-high level testing API milestone where we focus on API design, since we should have all the bits we need at that point (easier access to arbitrary shrinking, etc).

@Xenomega Xenomega added the on hold This issue was marked as not desirable to complete for now label Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold This issue was marked as not desirable to complete for now very-low-priority
Projects
None yet
Development

No branches or pull requests

3 participants