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

Testing: Get rapid into the codebase #5437

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"

"pgregory.net/rapid"
)

// Note that most of the tests use makeTestProto/defaultEvalParams as evaluator version so that
Expand Down Expand Up @@ -371,6 +373,33 @@ func TestSimpleMath(t *testing.T) {
testPanics(t, "int 1; int 2; - ; int 0; ==", 1)
}

// TestRapidMath uses rapid.Check to be a bit more exhaustive
func TestRapidMath(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

rapid.Check(t, func(r *rapid.T) {
a := rapid.Uint64().Draw(r, "a").(uint64)
b := rapid.Uint64().Draw(r, "b").(uint64)
sum := a + b
test := fmt.Sprintf("int %d; int %d; +; int %d; ==", a, b, sum)
if sum < a {
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
testPanics(t, test, 1)
} else {
testAccepts(t, test, 1)
}

diff := a - b
test = fmt.Sprintf("int %d; int %d; -; int %d; ==", a, b, diff)
if a < b {
testPanics(t, test, 1)
} else {
testAccepts(t, test, 1)
}

})
}

func TestSha256EqArg(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
golang.org/x/sys v0.7.0
golang.org/x/text v0.9.0
gopkg.in/sohlich/elogrus.v3 v3.0.0-20180410122755-1fa29e2f2009
pgregory.net/rapid v0.4.8
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,5 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
pgregory.net/rapid v0.4.8 h1:d+5SGZWUbJPbl3ss6tmPFqnNeQR6VDOFly+eTjwPiEw=
pgregory.net/rapid v0.4.8/go.mod h1:Z5PbWqjvWR1I3UGjvboUuan4fe4ZYEYNLNQLExzCoUs=