Add a custom Invoke()
function #10
No reviewers
Labels
No labels
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/contract-coverage-primer#10
Loading…
Reference in a new issue
No description provided.
Delete branch "elebedeva/contract-coverage-primer:covertest/invoke"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #4, #5, #6
Adding custom contract invoker with ability to produce coverage file from multiple testsuits.
902b9d5881
to8921d5777c
@ -0,0 +107,4 @@
}
ops, v, _ := TestInvoke(bc, tx) // ignore error to support failing transactions
tx.SystemFee = v.GasConsumed()
c.Methods[len(c.Methods)-1].Instructions = make([]InstrHash, len(ops))
Could you explain the logic here? We take the last methogs in
c.Methods
slice an replace a set of instructions here:Invoke()
(or inInvokeFail()
) we already appended current method (its name and nil forInstructions
slice) toc.Methods
. When we get a set of executed instructions from customRun()
we want to copy them toInstructions
slice in current method (last one inc.Methods
).c.Methods[len(c.Methods)-1].Instructions
there will be "tails" of allocated but unused memory. To avoid it we allocate just enough memory to copy the instructions slice there.Ok, so am I getting it right:
c.Methods
corresponds to eachInvoke
, not to each method? So 3 invocations of the same method will produce 3 results.Anyway, why do we create nil and access the last element, why not just append to
c.Methods
here?Yes, that is correct.
Moved appending method to
c.Methods
here.@ -0,0 +136,4 @@
return ops, ic.VM, err
}
type coverline struct {
Golang already has https://godocs.io/testing#CoverBlock -- we might reuse it.
Done
@ -0,0 +178,4 @@
for _, method := range di.Methods {
maxLine := method.Range.End
for _, seqPoint := range method.SeqPoints {
if isValidDocument(seqPoint.Document, docs) && seqPoint.Opcode < int(maxLine) {
What is the
seqPoint.Opcode < int(maxLine)
check here for?There is a problem with sequence points: some of them have strange opcodes which don't correspond to method opcodes. For example, in an example contract's method
putNumber
there is a SeqPoint with opcode 193 but the method don't have such opcode. This check solved the problem in theputNumber
method but clearly don't solve the problem generally.Seems like a but in the compiler.
@ -0,0 +205,4 @@
}
func countInstructions(cov []coverline, codes []InstrHash) {
for i := 0; i < len(cov); i++ {
Why no
for i := range cov
?Fixed
WIP: Add a customto Add a customInvoke()
functionInvoke()
function@ -0,0 +118,4 @@
for _, info := range cov {
covered := 0
if info.IsCovered {
covered++
I believe if we combine multiple expressions this way we will have both
0
and1
for the same file + line, right?They may interfere with each other, have you checked this is not the case?
Fixed.
Now the coverage output should be consistent.
@ -138,3 +158,4 @@
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
Do you do
go mod tidy
after dependency update?Fixed
@ -49,2 +49,4 @@
inv.InvokeFail(t, "Invalid key size", "putNumber", invalidKey, 42)
inv.InvokeFail(t, "Invalid key size", "getNumber", invalidKey)
// spew.Dump(inv.Methods)
inv.MakeCoverage(t, ctrDI, "contract.go", "c.out")
What will happen if I execute tests multiple times after changing the code?
Will I get only the new coverage?
No, actually method writes to the end of the file, so new coverage will be added to existing one.
It may not be desireable: when I modify code, I don't usually care what the old coverage was (an if I do, I can move it to a separate file).
Fixed.
Now the new coverage replaces the old one after every test execution.
fdb7293444
to8e45fee116
734468cfc9
toc51343019c