github.com/cosmos/cosmos-sdk@v0.50.10/x/group/internal/orm/sequence_property_test.go (about) 1 package orm 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "pgregory.net/rapid" 8 9 storetypes "cosmossdk.io/store/types" 10 ) 11 12 func TestSequence(t *testing.T) { 13 rapid.Check(t, testSequenceMachine) 14 } 15 16 func testSequenceMachine(t *rapid.T) { 17 // Init sets up the real Sequence, including choosing a random initial value, 18 // and intialises the model state 19 ctx := NewMockContext() 20 store := ctx.KVStore(storetypes.NewKVStoreKey("test")) 21 22 // Create primary key table 23 seq := NewSequence(0x1) 24 25 // Choose initial sequence value 26 initSeqVal := rapid.Uint64().Draw(t, "initSeqVal") 27 err := seq.InitVal(store, initSeqVal) 28 require.NoError(t, err) 29 30 // Create model state 31 state := initSeqVal 32 33 t.Repeat(map[string]func(*rapid.T){ 34 // NextVal is one of the model commands. It checks that the next value of the 35 // sequence matches the model and increments the model state. 36 "NextVal": func(t *rapid.T) { 37 // Check that the next value in the sequence matches the model 38 require.Equal(t, state+1, seq.NextVal(store)) 39 // Increment the model state 40 state++ 41 }, 42 // CurVal is one of the model commands. It checks that the current value of the 43 // sequence matches the model. 44 "CurVal": func(t *rapid.T) { 45 // Check the current value matches the model 46 require.Equal(t, state, seq.CurVal(store)) 47 }, 48 // PeekNextVal is one of the model commands. It checks that the next value of 49 // the sequence matches the model without modifying the state. 50 "PeekNextVal": func(t *rapid.T) { 51 // Check that the next value in the sequence matches the model 52 require.Equal(t, state+1, seq.PeekNextVal(store)) 53 }, 54 }) 55 }