Make neotest coverage properly handle contract update #1354

Open
opened 2025-12-28 17:16:09 +00:00 by sami · 0 comments
Owner

Originally created by @AnnaShaleva on GitHub (Aug 19, 2024).

Contract update often implies new source file and new instructions offsets. Currently neotest internally treats an updated contract as a new one (since it has a new sourcepath), and it's correct:
nspcc-dev/neo-go@7766168c19/pkg/neotest/compile.go (L24-L25)

However, coverage tool identifies contracts by hash:
nspcc-dev/neo-go@3e31b118c5/pkg/neotest/coverage.go (L29-L30)
Hence, coverage tool can't really distinguish old executable from the new one since both of them have the same hash. It leads to the fact that coverage results of updated and old contracts are mixed (and even may be invalid due to instructions offset update).

Describe the solution you'd like

I thought about making coverage tool distinguish contracts coverage by source path, exactly like neotest does. The trick is VM execution hook doesn't have access to the executable contract source, VM can only access executable script hash. This problem my be solved by accessing contract's path via Executor state provided to VM execution hook.

Describe alternatives you've considered

No other alternatives yet, but there should be any.

Originally created by @AnnaShaleva on GitHub (Aug 19, 2024). ## Is your feature request related to a problem? Please describe. Contract update often implies new source file and new instructions offsets. Currently neotest internally treats an updated contract as a new one (since it has a new sourcepath), and it's correct: https://github.com/nspcc-dev/neo-go/blob/7766168c19ac885da64696f0de41afd28f3c53fe/pkg/neotest/compile.go#L24-L25 However, coverage tool identifies contracts by hash: https://github.com/nspcc-dev/neo-go/blob/3e31b118c5159a91634795bb7fad4b5eb9f45652/pkg/neotest/coverage.go#L29-L30 Hence, coverage tool can't really distinguish old executable from the new one since both of them have the same hash. It leads to the fact that coverage results of updated and old contracts are mixed (and even may be invalid due to instructions offset update). ## Describe the solution you'd like I thought about making coverage tool distinguish contracts coverage by source path, exactly like neotest does. The trick is VM execution hook doesn't have access to the executable contract source, VM can only access executable script hash. This problem my be solved by accessing contract's path via Executor state provided to VM execution hook. ## Describe alternatives you've considered No other alternatives yet, but there should be any.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nspcc-dev/neo-go#1354
No description provided.