accounts: update test to use quick check
package wavelet
import (
+ "bytes"
"github.com/perlin-network/wavelet/store"
"github.com/stretchr/testify/assert"
- "math/rand"
"testing"
+ "testing/quick"
)
func TestSmartContract(t *testing.T) {
+ fn := func(id [TransactionIDSize]byte, code [2 * 1024]byte) bool {
db := store.NewInmem()
defer func() {
_ = db.Close()
@@ -15,23 +17,21 @@ func TestSmartContract(t *testing.T) {
accounts := newAccounts(db)
- var id [TransactionIDSize]byte
- var code [2 * 1024 * 1024]byte
-
- _, err := rand.Read(id[:])
- assert.NoError(t, err)
-
- _, err = rand.Read(code[:])
- assert.NoError(t, err)
-
- // Not exist.
returned, available := accounts.ReadAccountContractCode(id)
- assert.Nil(t, returned)
- assert.False(t, available)
+ if returned != nil || available == true {
+ return false
+ }
accounts.WriteAccountContractCode(id, code[:])
returned, available = accounts.ReadAccountContractCode(id)
- assert.Equal(t, code[:], returned)
- assert.True(t, available)
+ if !bytes.Equal(code[:], returned) || available == false {
+ return false
+ }
+
+ return true
+ }
+
+ assert.NoError(t, quick.Check(fn, nil))
+
}
