diff --git a/depinject/go.mod b/depinject/go.mod index 35a5ea3a77..829d99f6e0 100644 --- a/depinject/go.mod +++ b/depinject/go.mod @@ -24,5 +24,5 @@ require ( github.com/rogpeppe/go-internal v1.8.1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - pgregory.net/rapid v0.4.8 // indirect + pgregory.net/rapid v0.5.2 // indirect ) diff --git a/go.mod b/go.mod index 2470cd9d48..a6e00ade6c 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b google.golang.org/grpc v1.49.0 google.golang.org/protobuf v1.28.1 - pgregory.net/rapid v0.4.8 + pgregory.net/rapid v0.5.2 sigs.k8s.io/yaml v1.3.0 ) diff --git a/go.sum b/go.sum index 5b302c078f..491b51ec6a 100644 --- a/go.sum +++ b/go.sum @@ -1742,8 +1742,8 @@ mvdan.cc/unparam v0.0.0-20220706161116-678bad134442/go.mod h1:F/Cxw/6mVrNKqrR2Yj nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= -pgregory.net/rapid v0.4.8 h1:d+5SGZWUbJPbl3ss6tmPFqnNeQR6VDOFly+eTjwPiEw= -pgregory.net/rapid v0.4.8/go.mod h1:Z5PbWqjvWR1I3UGjvboUuan4fe4ZYEYNLNQLExzCoUs= +pgregory.net/rapid v0.5.2 h1:zC+jmuzcz5yJvG/igG06aLx8kcGmZY435NcuyhblKjY= +pgregory.net/rapid v0.5.2/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/orm/encoding/ormfield/codec_test.go b/orm/encoding/ormfield/codec_test.go index 898433b4bd..98e67bb8a2 100644 --- a/orm/encoding/ormfield/codec_test.go +++ b/orm/encoding/ormfield/codec_test.go @@ -31,7 +31,7 @@ func testCodec(t *testing.T, spec testutil.TestFieldSpec) { }) } -func testCodecNT(t *testing.T, fname protoreflect.Name, generator *rapid.Generator, nonTerminal bool) { +func testCodecNT(t *testing.T, fname protoreflect.Name, generator *rapid.Generator[any], nonTerminal bool) { cdc, err := testutil.MakeTestCodec(fname, nonTerminal) assert.NilError(t, err) rapid.Check(t, func(t *rapid.T) { @@ -98,8 +98,8 @@ func TestCompactUInt32(t *testing.T) { // randomized tests rapid.Check(t, func(t *rapid.T) { - x := rapid.Uint32().Draw(t, "x").(uint32) - y := rapid.Uint32().Draw(t, "y").(uint32) + x := rapid.Uint32().Draw(t, "x") + y := rapid.Uint32().Draw(t, "y") bx := ormfield.EncodeCompactUint32(x) by := ormfield.EncodeCompactUint32(y) @@ -146,8 +146,8 @@ func TestCompactUInt64(t *testing.T) { // randomized tests rapid.Check(t, func(t *rapid.T) { - x := rapid.Uint64().Draw(t, "x").(uint64) - y := rapid.Uint64().Draw(t, "y").(uint64) + x := rapid.Uint64().Draw(t, "x") + y := rapid.Uint64().Draw(t, "y") bx := ormfield.EncodeCompactUint64(x) by := ormfield.EncodeCompactUint64(y) diff --git a/orm/encoding/ormkv/index_key_test.go b/orm/encoding/ormkv/index_key_test.go index 322f24c172..9625641bf1 100644 --- a/orm/encoding/ormkv/index_key_test.go +++ b/orm/encoding/ormkv/index_key_test.go @@ -15,9 +15,9 @@ import ( func TestIndexKeyCodec(t *testing.T) { rapid.Check(t, func(t *rapid.T) { - idxPartCdc := testutil.TestKeyCodecGen(1, 5).Draw(t, "idxPartCdc").(testutil.TestKeyCodec) - pkCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "pkCdc").(testutil.TestKeyCodec) - prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix").([]byte) + idxPartCdc := testutil.TestKeyCodecGen(1, 5).Draw(t, "idxPartCdc") + pkCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "pkCdc") + prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix") messageType := (&testpb.ExampleTable{}).ProtoReflect().Type() indexKeyCdc, err := ormkv.NewIndexKeyCodec( prefix, @@ -27,7 +27,7 @@ func TestIndexKeyCodec(t *testing.T) { ) assert.NilError(t, err) for i := 0; i < 100; i++ { - a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i)).(*testpb.ExampleTable) + a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i)) key := indexKeyCdc.GetKeyValues(a.ProtoReflect()) pk := pkCodec.Codec.GetKeyValues(a.ProtoReflect()) idx1 := &ormkv.IndexKeyEntry{ diff --git a/orm/encoding/ormkv/key_codec_test.go b/orm/encoding/ormkv/key_codec_test.go index 4aa8ac5c5f..2b5ae8e7d7 100644 --- a/orm/encoding/ormkv/key_codec_test.go +++ b/orm/encoding/ormkv/key_codec_test.go @@ -17,7 +17,7 @@ import ( func TestKeyCodec(t *testing.T) { rapid.Check(t, func(t *rapid.T) { - key := testutil.TestKeyCodecGen(0, 5).Draw(t, "key").(testutil.TestKeyCodec) + key := testutil.TestKeyCodecGen(0, 5).Draw(t, "key") for i := 0; i < 100; i++ { keyValues := key.Draw(t, "values") diff --git a/orm/encoding/ormkv/primary_key_test.go b/orm/encoding/ormkv/primary_key_test.go index dba11a1be6..ece72754a7 100644 --- a/orm/encoding/ormkv/primary_key_test.go +++ b/orm/encoding/ormkv/primary_key_test.go @@ -17,7 +17,7 @@ import ( func TestPrimaryKeyCodec(t *testing.T) { rapid.Check(t, func(t *rapid.T) { - keyCodec := testutil.TestKeyCodecGen(0, 5).Draw(t, "keyCodec").(testutil.TestKeyCodec) + keyCodec := testutil.TestKeyCodecGen(0, 5).Draw(t, "keyCodec") pkCodec, err := ormkv.NewPrimaryKeyCodec( keyCodec.Codec.Prefix(), (&testpb.ExampleTable{}).ProtoReflect().Type(), @@ -26,7 +26,7 @@ func TestPrimaryKeyCodec(t *testing.T) { ) assert.NilError(t, err) for i := 0; i < 100; i++ { - a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i)).(*testpb.ExampleTable) + a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i)) key := keyCodec.Codec.GetKeyValues(a.ProtoReflect()) pk1 := &ormkv.PrimaryKeyEntry{ TableName: aFullName, diff --git a/orm/encoding/ormkv/seq_test.go b/orm/encoding/ormkv/seq_test.go index 29ecf2ed0a..90a3c2b8c2 100644 --- a/orm/encoding/ormkv/seq_test.go +++ b/orm/encoding/ormkv/seq_test.go @@ -14,7 +14,7 @@ import ( func TestSeqCodec(t *testing.T) { rapid.Check(t, func(t *rapid.T) { - prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix").([]byte) + prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix") typ := (&testpb.ExampleTable{}).ProtoReflect().Type() tableName := typ.Descriptor().FullName() cdc := ormkv.NewSeqCodec(typ, prefix) @@ -27,7 +27,7 @@ func TestSeqCodec(t *testing.T) { assert.NilError(t, err) assert.Equal(t, uint64(0), seq) - seq = rapid.Uint64().Draw(t, "seq").(uint64) + seq = rapid.Uint64().Draw(t, "seq") v := cdc.EncodeValue(seq) seq2, err := cdc.DecodeValue(v) diff --git a/orm/encoding/ormkv/unique_key_test.go b/orm/encoding/ormkv/unique_key_test.go index a41c1b90e5..c015e671e3 100644 --- a/orm/encoding/ormkv/unique_key_test.go +++ b/orm/encoding/ormkv/unique_key_test.go @@ -17,8 +17,8 @@ import ( func TestUniqueKeyCodec(t *testing.T) { rapid.Check(t, func(t *rapid.T) { - keyCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "keyCodec").(testutil.TestKeyCodec) - pkCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "primaryKeyCodec").(testutil.TestKeyCodec) + keyCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "keyCodec") + pkCodec := testutil.TestKeyCodecGen(1, 5).Draw(t, "primaryKeyCodec") // check if we have a trivial unique index where all of the fields // in the primary key are in the unique key, we should expect an @@ -51,7 +51,7 @@ func TestUniqueKeyCodec(t *testing.T) { } for i := 0; i < 100; i++ { - a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i)).(*testpb.ExampleTable) + a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i)) key := keyCodec.Codec.GetKeyValues(a.ProtoReflect()) pk := pkCodec.Codec.GetKeyValues(a.ProtoReflect()) uniq1 := &ormkv.IndexKeyEntry{ diff --git a/orm/go.mod b/orm/go.mod index 865c2f97e9..09fe6ef49d 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -15,7 +15,7 @@ require ( google.golang.org/grpc v1.49.0 google.golang.org/protobuf v1.28.1 gotest.tools/v3 v3.3.0 - pgregory.net/rapid v0.5.1 + pgregory.net/rapid v0.5.2 ) require ( diff --git a/orm/go.sum b/orm/go.sum index 5c41e186dc..71a2f98a1d 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -259,3 +259,5 @@ gotest.tools/v3 v3.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A= pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= pgregory.net/rapid v0.5.1 h1:U7LVKOJavGH81G5buGiyztKCmpQLfepzitHEKDLQ8ug= pgregory.net/rapid v0.5.1/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v0.5.2 h1:zC+jmuzcz5yJvG/igG06aLx8kcGmZY435NcuyhblKjY= +pgregory.net/rapid v0.5.2/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= diff --git a/orm/internal/testutil/testutil.go b/orm/internal/testutil/testutil.go index f220cc8979..a4856eb1a0 100644 --- a/orm/internal/testutil/testutil.go +++ b/orm/internal/testutil/testutil.go @@ -18,92 +18,92 @@ import ( // TestFieldSpec defines a test field against the testpb.ExampleTable message. type TestFieldSpec struct { FieldName protoreflect.Name - Gen *rapid.Generator + Gen *rapid.Generator[any] } var TestFieldSpecs = []TestFieldSpec{ { "u32", - rapid.Uint32(), + rapid.Uint32().AsAny(), }, { "u64", - rapid.Uint64(), + rapid.Uint64().AsAny(), }, { "str", rapid.String().Filter(func(x string) bool { // filter out null terminators return strings.IndexByte(x, 0) < 0 - }), + }).AsAny(), }, { "bz", - rapid.SliceOfN(rapid.Byte(), 0, math.MaxUint32), + rapid.SliceOfN(rapid.Byte(), 0, math.MaxUint32).AsAny(), }, { "i32", - rapid.Int32(), + rapid.Int32().AsAny(), }, { "f32", - rapid.Uint32(), + rapid.Uint32().AsAny(), }, { "s32", - rapid.Int32(), + rapid.Int32().AsAny(), }, { "sf32", - rapid.Int32(), + rapid.Int32().AsAny(), }, { "i64", - rapid.Int64(), + rapid.Int64().AsAny(), }, { "f64", - rapid.Uint64(), + rapid.Uint64().AsAny(), }, { "s64", - rapid.Int64(), + rapid.Int64().AsAny(), }, { "sf64", - rapid.Int64(), + rapid.Int64().AsAny(), }, { "b", - rapid.Bool(), + rapid.Bool().AsAny(), }, { "ts", rapid.Custom(func(t *rapid.T) protoreflect.Message { - seconds := rapid.Int64Range(-9999999999, 9999999999).Draw(t, "seconds").(int64) - nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos").(int32) + seconds := rapid.Int64Range(-9999999999, 9999999999).Draw(t, "seconds") + nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos") return (×tamppb.Timestamp{ Seconds: seconds, Nanos: nanos, }).ProtoReflect() - }), + }).AsAny(), }, { "dur", rapid.Custom(func(t *rapid.T) protoreflect.Message { - seconds := rapid.Int64Range(0, 315576000000).Draw(t, "seconds").(int64) - nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos").(int32) + seconds := rapid.Int64Range(0, 315576000000).Draw(t, "seconds") + nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos") return (&durationpb.Duration{ Seconds: seconds, Nanos: nanos, }).ProtoReflect() - }), + }).AsAny(), }, { "e", - rapid.Int32().Map(func(x int32) protoreflect.EnumNumber { + rapid.Transform(rapid.Int32(), func(x int32) protoreflect.EnumNumber { return protoreflect.EnumNumber(x) - }), + }).AsAny(), }, } @@ -125,10 +125,10 @@ type TestKeyCodec struct { Codec *ormkv.KeyCodec } -func TestFieldSpecsGen(minLen, maxLen int) *rapid.Generator { +func TestFieldSpecsGen(minLen, maxLen int) *rapid.Generator[[]TestFieldSpec] { return rapid.Custom(func(t *rapid.T) []TestFieldSpec { xs := rapid.SliceOfNDistinct(rapid.IntRange(0, len(TestFieldSpecs)-1), minLen, maxLen, func(i int) int { return i }). - Draw(t, "fieldSpecIndexes").([]int) + Draw(t, "fieldSpecIndexes") var specs []TestFieldSpec @@ -141,16 +141,16 @@ func TestFieldSpecsGen(minLen, maxLen int) *rapid.Generator { }) } -func TestKeyCodecGen(minLen, maxLen int) *rapid.Generator { +func TestKeyCodecGen(minLen, maxLen int) *rapid.Generator[TestKeyCodec] { return rapid.Custom(func(t *rapid.T) TestKeyCodec { - specs := TestFieldSpecsGen(minLen, maxLen).Draw(t, "fieldSpecs").([]TestFieldSpec) + specs := TestFieldSpecsGen(minLen, maxLen).Draw(t, "fieldSpecs") var fields []protoreflect.Name for _, spec := range specs { fields = append(fields, spec.FieldName) } - prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix").([]byte) + prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix") msgType := (&testpb.ExampleTable{}).ProtoReflect().Type() cdc, err := ormkv.NewKeyCodec(prefix, msgType, fields) @@ -169,6 +169,7 @@ func (k TestKeyCodec) Draw(t *rapid.T, id string) []protoreflect.Value { n := len(k.KeySpecs) keyValues := make([]protoreflect.Value, n) for i, k := range k.KeySpecs { + keyValues[i] = protoreflect.ValueOf(k.Gen.Draw(t, fmt.Sprintf("%s[%d]", id, i))) } return keyValues diff --git a/orm/model/ormtable/table_test.go b/orm/model/ormtable/table_test.go index 088ec8be2d..c5bf1ee396 100644 --- a/orm/model/ormtable/table_test.go +++ b/orm/model/ormtable/table_test.go @@ -500,7 +500,7 @@ func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backen } func TestRandomTableData(t *testing.T) { - testTable(t, TableDataGen(testutil.GenA, 100).Example().(*TableData)) + testTable(t, TableDataGen(testutil.GenA, 100).Example()) } func testTable(t *testing.T, tableData *TableData) { @@ -553,8 +553,8 @@ func testIndex(t *testing.T, model *IndexModel) { checkIteratorAgainstSlice(t, it, reverseData(model.data)) rapid.Check(t, func(t *rapid.T) { - i := rapid.IntRange(0, len(model.data)-2).Draw(t, "i").(int) - j := rapid.IntRange(i+1, len(model.data)-1).Draw(t, "j").(int) + i := rapid.IntRange(0, len(model.data)-2).Draw(t, "i") + j := rapid.IntRange(i+1, len(model.data)-1).Draw(t, "j") start, _, err := model.index.(ormkv.IndexCodec).EncodeKeyFromMessage(model.data[i].ProtoReflect()) assert.NilError(t, err) @@ -630,10 +630,10 @@ func checkIteratorAgainstSlice(t assert.TestingT, iterator ormtable.Iterator, da } } -func TableDataGen(elemGen *rapid.Generator, n int) *rapid.Generator { +func TableDataGen[T proto.Message](elemGen *rapid.Generator[T], n int) *rapid.Generator[*TableData] { return rapid.Custom(func(t *rapid.T) *TableData { - prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix").([]byte) - message := elemGen.Draw(t, "message").(proto.Message) + prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix") + message := elemGen.Draw(t, "message") table, err := ormtable.Build(ormtable.Options{ Prefix: prefix, MessageType: message.ProtoReflect().Type(), @@ -646,7 +646,7 @@ func TableDataGen(elemGen *rapid.Generator, n int) *rapid.Generator { store := ormtable.WrapContextDefault(testkv.NewSplitMemBackend()) for i := 0; i < n; { - message = elemGen.Draw(t, fmt.Sprintf("message[%d]", i)).(proto.Message) + message = elemGen.Draw(t, fmt.Sprintf("message[%d]", i)) err := table.Insert(store, message) if sdkerrors.IsOf(err, ormerrors.PrimaryKeyConstraintViolation, ormerrors.UniqueKeyViolation) { continue @@ -723,7 +723,7 @@ func TestJSONExportImport(t *testing.T) { store := ormtable.WrapContextDefault(testkv.NewSplitMemBackend()) for i := 0; i < 100; { - x := testutil.GenA.Example().(proto.Message) + x := testutil.GenA.Example() err = table.Insert(store, x) if sdkerrors.IsOf(err, ormerrors.PrimaryKeyConstraintViolation, ormerrors.UniqueKeyViolation) { continue diff --git a/x/group/internal/math/dec_test.go b/x/group/internal/math/dec_test.go index 6bf0edb5af..4c9fcc6cc6 100644 --- a/x/group/internal/math/dec_test.go +++ b/x/group/internal/math/dec_test.go @@ -87,8 +87,8 @@ func TestDec(t *testing.T) { require.True(t, minusOne.IsNegative()) } -var genDec *rapid.Generator = rapid.Custom(func(t *rapid.T) Dec { - f := rapid.Float64().Draw(t, "f").(float64) +var genDec *rapid.Generator[Dec] = rapid.Custom(func(t *rapid.T) Dec { + f := rapid.Float64().Draw(t, "f") dec, err := NewDecFromString(fmt.Sprintf("%g", f)) require.NoError(t, err) return dec @@ -101,8 +101,8 @@ type floatAndDec struct { } // Generate a Dec value along with the float used to create it -var genFloatAndDec *rapid.Generator = rapid.Custom(func(t *rapid.T) floatAndDec { - f := rapid.Float64().Draw(t, "f").(float64) +var genFloatAndDec *rapid.Generator[floatAndDec] = rapid.Custom(func(t *rapid.T) floatAndDec { + f := rapid.Float64().Draw(t, "f") dec, err := NewDecFromString(fmt.Sprintf("%g", f)) require.NoError(t, err) return floatAndDec{f, dec} @@ -110,7 +110,7 @@ var genFloatAndDec *rapid.Generator = rapid.Custom(func(t *rapid.T) floatAndDec // Property: n == NewDecFromInt64(n).Int64() func testDecInt64(t *rapid.T) { - nIn := rapid.Int64().Draw(t, "n").(int64) + nIn := rapid.Int64().Draw(t, "n") nOut, err := NewDecFromInt64(nIn).Int64() require.NoError(t, err) @@ -119,7 +119,7 @@ func testDecInt64(t *rapid.T) { // Property: 0 + a == a func testAddLeftIdentity(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) + a := genDec.Draw(t, "a") zero := NewDecFromInt64(0) b, err := zero.Add(a) @@ -130,7 +130,7 @@ func testAddLeftIdentity(t *rapid.T) { // Property: a + 0 == a func testAddRightIdentity(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) + a := genDec.Draw(t, "a") zero := NewDecFromInt64(0) b, err := a.Add(zero) @@ -141,8 +141,8 @@ func testAddRightIdentity(t *rapid.T) { // Property: a + b == b + a func testAddCommutative(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) - b := genDec.Draw(t, "b").(Dec) + a := genDec.Draw(t, "a") + b := genDec.Draw(t, "b") c, err := a.Add(b) require.NoError(t, err) @@ -155,9 +155,9 @@ func testAddCommutative(t *rapid.T) { // Property: (a + b) + c == a + (b + c) func testAddAssociative(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) - b := genDec.Draw(t, "b").(Dec) - c := genDec.Draw(t, "c").(Dec) + a := genDec.Draw(t, "a") + b := genDec.Draw(t, "b") + c := genDec.Draw(t, "c") // (a + b) + c d, err := a.Add(b) @@ -178,7 +178,7 @@ func testAddAssociative(t *rapid.T) { // Property: a - 0 == a func testSubRightIdentity(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) + a := genDec.Draw(t, "a") zero := NewDecFromInt64(0) b, err := a.Sub(zero) @@ -189,7 +189,7 @@ func testSubRightIdentity(t *rapid.T) { // Property: a - a == 0 func testSubZero(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) + a := genDec.Draw(t, "a") zero := NewDecFromInt64(0) b, err := a.Sub(a) @@ -200,8 +200,8 @@ func testSubZero(t *rapid.T) { // Property: (a - b) + b == a func testSubAdd(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) - b := genDec.Draw(t, "b").(Dec) + a := genDec.Draw(t, "a") + b := genDec.Draw(t, "b") c, err := a.Sub(b) require.NoError(t, err) @@ -214,8 +214,8 @@ func testSubAdd(t *rapid.T) { // Property: (a + b) - b == a func testAddSub(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) - b := genDec.Draw(t, "b").(Dec) + a := genDec.Draw(t, "a") + b := genDec.Draw(t, "b") c, err := a.Add(b) require.NoError(t, err) @@ -228,23 +228,23 @@ func testAddSub(t *rapid.T) { // Property: Cmp(a, b) == -Cmp(b, a) func testCmpInverse(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) - b := genDec.Draw(t, "b").(Dec) + a := genDec.Draw(t, "a") + b := genDec.Draw(t, "b") require.Equal(t, a.Cmp(b), -b.Cmp(a)) } // Property: IsEqual(a, b) == IsEqual(b, a) func testEqualCommutative(t *rapid.T) { - a := genDec.Draw(t, "a").(Dec) - b := genDec.Draw(t, "b").(Dec) + a := genDec.Draw(t, "a") + b := genDec.Draw(t, "b") require.Equal(t, a.IsEqual(b), b.IsEqual(a)) } // Property: isNegative(f) == isNegative(NewDecFromString(f.String())) func testIsNegative(t *rapid.T) { - floatAndDec := genFloatAndDec.Draw(t, "floatAndDec").(floatAndDec) + floatAndDec := genFloatAndDec.Draw(t, "floatAndDec") f, dec := floatAndDec.float, floatAndDec.dec require.Equal(t, f < 0, dec.IsNegative()) diff --git a/x/group/internal/orm/generators_test.go b/x/group/internal/orm/generators_test.go index 0cc95eedaa..3ad52df15d 100644 --- a/x/group/internal/orm/generators_test.go +++ b/x/group/internal/orm/generators_test.go @@ -10,9 +10,9 @@ import ( // generate empty strings for Name. var genTableModel = rapid.Custom(func(t *rapid.T) *testdata.TableModel { return &testdata.TableModel{ - Id: rapid.Uint64().Draw(t, "id").(uint64), - Name: rapid.StringN(1, 100, 150).Draw(t, "name").(string), - Number: rapid.Uint64().Draw(t, "number ").(uint64), - Metadata: []byte(rapid.StringN(1, 100, 150).Draw(t, "metadata").(string)), + Id: rapid.Uint64().Draw(t, "id"), + Name: rapid.StringN(1, 100, 150).Draw(t, "name"), + Number: rapid.Uint64().Draw(t, "number "), + Metadata: []byte(rapid.StringN(1, 100, 150).Draw(t, "metadata")), } }) diff --git a/x/group/internal/orm/index_property_test.go b/x/group/internal/orm/index_property_test.go index 48b2cc02ef..e48de3c122 100644 --- a/x/group/internal/orm/index_property_test.go +++ b/x/group/internal/orm/index_property_test.go @@ -10,7 +10,7 @@ import ( func TestPrefixRangeProperty(t *testing.T) { t.Run("TestPrefixRange", rapid.MakeCheck(func(t *rapid.T) { - prefix := rapid.SliceOf(rapid.Byte()).Draw(t, "prefix").([]byte) + prefix := rapid.SliceOf(rapid.Byte()).Draw(t, "prefix") start, end := PrefixRange(prefix) diff --git a/x/group/internal/orm/iterator_property_test.go b/x/group/internal/orm/iterator_property_test.go index 1f30fcb227..c1e5eaec8b 100644 --- a/x/group/internal/orm/iterator_property_test.go +++ b/x/group/internal/orm/iterator_property_test.go @@ -15,14 +15,14 @@ import ( func TestPaginationProperty(t *testing.T) { t.Run("TestPagination", rapid.MakeCheck(func(t *rapid.T) { // Create a slice of group members - tableModels := rapid.SliceOf(genTableModel).Draw(t, "tableModels").([]*testdata.TableModel) + tableModels := rapid.SliceOf(genTableModel).Draw(t, "tableModels") // Choose a random limit for paging upperLimit := uint64(len(tableModels)) if upperLimit == 0 { upperLimit = 1 } - limit := rapid.Uint64Range(1, upperLimit).Draw(t, "limit").(uint64) + limit := rapid.Uint64Range(1, upperLimit).Draw(t, "limit") // Reconstruct the slice from offset pages reconstructedTableModels := make([]*testdata.TableModel, 0, len(tableModels)) diff --git a/x/group/internal/orm/primary_key_property_test.go b/x/group/internal/orm/primary_key_property_test.go index 083fd2c294..3b7f371053 100644 --- a/x/group/internal/orm/primary_key_property_test.go +++ b/x/group/internal/orm/primary_key_property_test.go @@ -13,7 +13,7 @@ import ( ) func TestPrimaryKeyTable(t *testing.T) { - rapid.Check(t, rapid.Run(&primaryKeyMachine{})) + rapid.Check(t, rapid.Run[*primaryKeyMachine]()) } // primaryKeyMachine is a state machine model of the PrimaryKeyTable. The state @@ -39,9 +39,9 @@ func (m *primaryKeyMachine) stateKeys() []string { // Generate a TableModel that has a 50% chance of being a part of the existing // state -func (m *primaryKeyMachine) genTableModel() *rapid.Generator { +func (m *primaryKeyMachine) genTableModel() *rapid.Generator[*testdata.TableModel] { genStateTableModel := rapid.Custom(func(t *rapid.T) *testdata.TableModel { - pk := rapid.SampledFrom(m.stateKeys()).Draw(t, "key").(string) + pk := rapid.SampledFrom(m.stateKeys()).Draw(t, "key") return m.state[pk] }) @@ -86,7 +86,7 @@ func (m *primaryKeyMachine) Check(t *rapid.T) { // Create is one of the model commands. It adds an object to the table, creating // an error if it already exists. func (m *primaryKeyMachine) Create(t *rapid.T) { - g := genTableModel.Draw(t, "g").(*testdata.TableModel) + g := genTableModel.Draw(t, "g") pk := string(PrimaryKey(g)) t.Logf("pk: %v", pk) @@ -105,9 +105,9 @@ func (m *primaryKeyMachine) Create(t *rapid.T) { // Update is one of the model commands. It updates the value at a given primary // key and fails if that primary key doesn't already exist in the table. func (m *primaryKeyMachine) Update(t *rapid.T) { - tm := m.genTableModel().Draw(t, "tm").(*testdata.TableModel) + tm := m.genTableModel().Draw(t, "tm") - newName := rapid.StringN(1, 100, 150).Draw(t, "newName").(string) + newName := rapid.StringN(1, 100, 150).Draw(t, "newName") tm.Name = newName // Perform the real Update @@ -128,7 +128,7 @@ func (m *primaryKeyMachine) Update(t *rapid.T) { // Set is one of the model commands. It sets the value at a key in the table // whether it exists or not. func (m *primaryKeyMachine) Set(t *rapid.T) { - g := genTableModel.Draw(t, "g").(*testdata.TableModel) + g := genTableModel.Draw(t, "g") pk := string(PrimaryKey(g)) err := m.table.Set(m.store, g) @@ -141,7 +141,7 @@ func (m *primaryKeyMachine) Set(t *rapid.T) { // primary key from the table and returns an error if that primary key doesn't // already exist in the table. func (m *primaryKeyMachine) Delete(t *rapid.T) { - tm := m.genTableModel().Draw(t, "tm").(*testdata.TableModel) + tm := m.genTableModel().Draw(t, "tm") // Perform the real Delete err := m.table.Delete(m.store, tm) @@ -161,7 +161,7 @@ func (m *primaryKeyMachine) Delete(t *rapid.T) { // Has is one of the model commands. It checks whether a key already exists in // the table. func (m *primaryKeyMachine) Has(t *rapid.T) { - pk := PrimaryKey(m.genTableModel().Draw(t, "g").(*testdata.TableModel)) + pk := PrimaryKey(m.genTableModel().Draw(t, "g")) realHas := m.table.Has(m.store, pk) modelHas := m.state[string(pk)] != nil @@ -172,7 +172,7 @@ func (m *primaryKeyMachine) Has(t *rapid.T) { // GetOne is one of the model commands. It fetches an object from the table by // its primary key and returns an error if that primary key isn't in the table. func (m *primaryKeyMachine) GetOne(t *rapid.T) { - pk := PrimaryKey(m.genTableModel().Draw(t, "tm").(*testdata.TableModel)) + pk := PrimaryKey(m.genTableModel().Draw(t, "tm")) var tm testdata.TableModel diff --git a/x/group/internal/orm/sequence_property_test.go b/x/group/internal/orm/sequence_property_test.go index 2d3d9c10a2..0872e429a0 100644 --- a/x/group/internal/orm/sequence_property_test.go +++ b/x/group/internal/orm/sequence_property_test.go @@ -9,7 +9,7 @@ import ( ) func TestSequence(t *testing.T) { - rapid.Check(t, rapid.Run(&sequenceMachine{})) + rapid.Check(t, rapid.Run[*sequenceMachine]()) } // sequenceMachine is a state machine model of Sequence. It simply uses a uint64 @@ -32,7 +32,7 @@ func (m *sequenceMachine) Init(t *rapid.T) { m.seq = &seq // Choose initial sequence value - initSeqVal := rapid.Uint64().Draw(t, "initSeqVal").(uint64) + initSeqVal := rapid.Uint64().Draw(t, "initSeqVal") err := m.seq.InitVal(m.store, initSeqVal) require.NoError(t, err)