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

multi transaction support in _filetest.gno #934

Open
moul opened this issue Jun 29, 2023 · 1 comment
Open

multi transaction support in _filetest.gno #934

moul opened this issue Jun 29, 2023 · 1 comment
Labels
help wanted Extra attention is needed 📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno

Comments

@moul
Copy link
Member

moul commented Jun 29, 2023

The goal is to discover an efficient format that enables chaining tests in a single file while preserving the state between calls, mimicking real transactions in real-life scenarios.

This approach would help overcome a limitation with the banker module and std.GetOrigSend. Currently, the context sets std.GetOrigSend, and the final transfer only occurs when the VM keeper completes the transaction. By finding a suitable format, we can address this limitation and create a more realistic testing environment.

Maybe something like this:

package main

var x int

func main() {
	x++
	println("foo", x)
}

func main2() {
	x++
    println("bar", x)
}

// Output:
// foo 1

// NewTX: main2
// Output:
// bar 2
@moul moul mentioned this issue Jun 29, 2023
11 tasks
@moul
Copy link
Member Author

moul commented Jun 29, 2023

Proposal by @ajnavarro, to follow the standard ExampleXXX pattern like in go.

package main

var x int

func ExampleTX1() {
	x++
	println("foo", x)
	// Output:
	// foo 1
}

func ExampleTX2() {
	x++
	println("bar", x)
	// Output:
	// bar 2
}

In our case, we want to ensure that each _test.gno file runs from top to bottom, so the first func Example is tx1, the second is tx2, and so on.

We also need to make sure that we load all the *.gno files, including other _test.gno files, but we need to take care to reset the context of the runtime for each _test.gno file, so that we don't have to care about the order of tests based on filename.

Pseudocode could be:

for _, testFile := range pkg.TestFiles() {
	if !testFile.HasATestOrExampleFunc() { continue }
	m := machine.Load(pkg) // including the other test files

	// run test files without simulating various transactions.
	m.RunTestFuncs()
	// now, simulate one transaction per example
	m.Reset()
	for _, exampleFunc := range testFile.ExampleFuncs() {
		m.ResetContext()
		m.TXSequenceTimeHeight++
		m.Call(exampleFunc)
		m.SaveState()
	}
}

@ajnavarro ajnavarro added 🌱 feature New update to Gno 📦 🤖 gnovm Issues or PRs gnovm related labels Jul 3, 2023
@moul moul added the help wanted Extra attention is needed label Jul 5, 2023
@moul moul added this to the 🌟 main.gno.land (wanted) milestone Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed 📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno
Projects
Status: 🌟 Wanted for Launch
Development

No branches or pull requests

2 participants