Skip to content

[GnoVM] Panics in tests do not revert state #2043

@leohhhn

Description

@leohhhn

Description

Check this out:

package panic

var count int

func Increment(shouldRevert bool) {
	count++

	if shouldRevert {
		count++
		panic("i was instructed to revert!")
	}
}
package panic

import "testing"

func TestIncrement(t *testing.T) {
	println(count)
	Increment(true)
}

func TestIncrement2(t *testing.T) {
	println(count)
}

Running gno test will output the following:

❯ gno test . -v
--- WARNING: unable to read package path from gno.mod or gno root directory; try creating a gno.mod file
=== RUN   TestIncrement
0
panic: i was instructed to revert!
--- FAIL: TestIncrement (0.00s)
=== RUN   TestIncrement2
2
--- PASS: TestIncrement2 (0.00s)
.: test pkg: failed: "TestIncrement"
FAIL
FAIL    .       0.69s
FAIL
FAIL
FAIL: 0 build errors, 1 test errors

Issue number one is this, where the machine state & context is not reset between tests, and the second problem is, as demonstrated with this issue, the fact that a panic statement does not revert the state.

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Other dev assigned

Status

Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions