From 221f7b1231d7f505501fdb1200ccff14f9bac104 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Sat, 21 Oct 2023 02:14:12 +0800 Subject: [PATCH 1/3] test: protect tests from bad random height --- util/testsuite/testsuite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/testsuite/testsuite.go b/util/testsuite/testsuite.go index e26537d57..6ad937752 100644 --- a/util/testsuite/testsuite.go +++ b/util/testsuite/testsuite.go @@ -133,9 +133,9 @@ func (ts *TestSuite) RandIntNonZero(max int) int { return ts.RandInt(max) + 1 } -// RandHeight returns a random number between [1, 1,000,000] for block height. +// RandHeight returns a random number between [1,000, 1,000,000] for block height. func (ts *TestSuite) RandHeight() uint32 { - return ts.RandUint32NonZero(1e6) + return ts.RandUint32NonZero(1e6-1000) + 1000 } // RandRound returns a random number between [0, 10) for block round. From a68fbeb743357999c86673afdf52a72a72eef84b Mon Sep 17 00:00:00 2001 From: Mostafa Date: Sat, 21 Oct 2023 02:19:46 +0800 Subject: [PATCH 2/3] chore: updating a comment --- util/testsuite/testsuite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/testsuite/testsuite.go b/util/testsuite/testsuite.go index 6ad937752..8b84986a6 100644 --- a/util/testsuite/testsuite.go +++ b/util/testsuite/testsuite.go @@ -133,7 +133,7 @@ func (ts *TestSuite) RandIntNonZero(max int) int { return ts.RandInt(max) + 1 } -// RandHeight returns a random number between [1,000, 1,000,000] for block height. +// RandHeight returns a random number between [1000, 1000000] for block height. func (ts *TestSuite) RandHeight() uint32 { return ts.RandUint32NonZero(1e6-1000) + 1000 } From 4b1e76ba534ce2bb4bf16a1b6bbe88bd05f209d8 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Sat, 21 Oct 2023 03:06:42 +0800 Subject: [PATCH 3/3] test: fixing random amount issue --- execution/executor/transfer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution/executor/transfer_test.go b/execution/executor/transfer_test.go index f1ec53220..3fda04f03 100644 --- a/execution/executor/transfer_test.go +++ b/execution/executor/transfer_test.go @@ -48,7 +48,7 @@ func (td *testData) checkTotalCoin(t *testing.T, fee int64) { } func (td *testData) randomAmountAndFee(min int64, max int64) (int64, int64) { - amt := td.RandInt64NonZero(max) + amt := td.RandInt64NonZero(max - 1) // To make sure amt+fee is less than max for amt < min { amt = td.RandInt64NonZero(max) }