Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
166 lines
4.5 KiB
Go
166 lines
4.5 KiB
Go
package orm
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
storetypes "cosmossdk.io/store/types"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/codec"
|
|
"git.cw.tr/mukan-network/mukan-sdk/codec/types"
|
|
"git.cw.tr/mukan-network/mukan-sdk/testutil/testdata"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/group/errors"
|
|
)
|
|
|
|
func TestAutoUInt64PrefixScan(t *testing.T) {
|
|
interfaceRegistry := types.NewInterfaceRegistry()
|
|
cdc := codec.NewProtoCodec(interfaceRegistry)
|
|
|
|
tb, err := NewAutoUInt64Table(AutoUInt64TablePrefix, AutoUInt64TableSeqPrefix, &testdata.TableModel{}, cdc)
|
|
require.NoError(t, err)
|
|
|
|
ctx := NewMockContext()
|
|
store := ctx.KVStore(storetypes.NewKVStoreKey("test"))
|
|
|
|
metadata := []byte("metadata")
|
|
t1 := testdata.TableModel{
|
|
Id: 1,
|
|
Name: "my test 1",
|
|
Metadata: metadata,
|
|
}
|
|
t2 := testdata.TableModel{
|
|
Id: 2,
|
|
Name: "my test 2",
|
|
Metadata: metadata,
|
|
}
|
|
t3 := testdata.TableModel{
|
|
Id: 3,
|
|
Name: "my test 3",
|
|
Metadata: metadata,
|
|
}
|
|
for _, g := range []testdata.TableModel{t1, t2, t3} {
|
|
_, err := tb.Create(store, &g)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
specs := map[string]struct {
|
|
start, end uint64
|
|
expResult []testdata.TableModel
|
|
expRowIDs []RowID
|
|
expError *errorsmod.Error
|
|
method func(store storetypes.KVStore, start, end uint64) (Iterator, error)
|
|
}{
|
|
"first element": {
|
|
start: 1,
|
|
end: 2,
|
|
method: tb.PrefixScan,
|
|
expResult: []testdata.TableModel{t1},
|
|
expRowIDs: []RowID{EncodeSequence(1)},
|
|
},
|
|
"first 2 elements": {
|
|
start: 1,
|
|
end: 3,
|
|
method: tb.PrefixScan,
|
|
expResult: []testdata.TableModel{t1, t2},
|
|
expRowIDs: []RowID{EncodeSequence(1), EncodeSequence(2)},
|
|
},
|
|
"first 3 elements": {
|
|
start: 1,
|
|
end: 4,
|
|
method: tb.PrefixScan,
|
|
expResult: []testdata.TableModel{t1, t2, t3},
|
|
expRowIDs: []RowID{EncodeSequence(1), EncodeSequence(2), EncodeSequence(3)},
|
|
},
|
|
"search with max end": {
|
|
start: 1,
|
|
end: math.MaxUint64,
|
|
method: tb.PrefixScan,
|
|
expResult: []testdata.TableModel{t1, t2, t3},
|
|
expRowIDs: []RowID{EncodeSequence(1), EncodeSequence(2), EncodeSequence(3)},
|
|
},
|
|
"2 to end": {
|
|
start: 2,
|
|
end: 5,
|
|
method: tb.PrefixScan,
|
|
expResult: []testdata.TableModel{t2, t3},
|
|
expRowIDs: []RowID{EncodeSequence(2), EncodeSequence(3)},
|
|
},
|
|
"start after end should fail": {
|
|
start: 2,
|
|
end: 1,
|
|
method: tb.PrefixScan,
|
|
expError: errors.ErrORMInvalidArgument,
|
|
},
|
|
"start equals end should fail": {
|
|
start: 1,
|
|
end: 1,
|
|
method: tb.PrefixScan,
|
|
expError: errors.ErrORMInvalidArgument,
|
|
},
|
|
"reverse first element": {
|
|
start: 1,
|
|
end: 2,
|
|
method: tb.ReversePrefixScan,
|
|
expResult: []testdata.TableModel{t1},
|
|
expRowIDs: []RowID{EncodeSequence(1)},
|
|
},
|
|
"reverse first 2 elements": {
|
|
start: 1,
|
|
end: 3,
|
|
method: tb.ReversePrefixScan,
|
|
expResult: []testdata.TableModel{t2, t1},
|
|
expRowIDs: []RowID{EncodeSequence(2), EncodeSequence(1)},
|
|
},
|
|
"reverse first 3 elements": {
|
|
start: 1,
|
|
end: 4,
|
|
method: tb.ReversePrefixScan,
|
|
expResult: []testdata.TableModel{t3, t2, t1},
|
|
expRowIDs: []RowID{EncodeSequence(3), EncodeSequence(2), EncodeSequence(1)},
|
|
},
|
|
"reverse search with max end": {
|
|
start: 1,
|
|
end: math.MaxUint64,
|
|
method: tb.ReversePrefixScan,
|
|
expResult: []testdata.TableModel{t3, t2, t1},
|
|
expRowIDs: []RowID{EncodeSequence(3), EncodeSequence(2), EncodeSequence(1)},
|
|
},
|
|
"reverse 2 to end": {
|
|
start: 2,
|
|
end: 5,
|
|
method: tb.ReversePrefixScan,
|
|
expResult: []testdata.TableModel{t3, t2},
|
|
expRowIDs: []RowID{EncodeSequence(3), EncodeSequence(2)},
|
|
},
|
|
"reverse start after end should fail": {
|
|
start: 2,
|
|
end: 1,
|
|
method: tb.ReversePrefixScan,
|
|
expError: errors.ErrORMInvalidArgument,
|
|
},
|
|
"reverse start equals end should fail": {
|
|
start: 1,
|
|
end: 1,
|
|
method: tb.ReversePrefixScan,
|
|
expError: errors.ErrORMInvalidArgument,
|
|
},
|
|
}
|
|
for msg, spec := range specs {
|
|
t.Run(msg, func(t *testing.T) {
|
|
it, err := spec.method(store, spec.start, spec.end)
|
|
require.True(t, spec.expError.Is(err), "expected #+v but got #+v", spec.expError, err)
|
|
if spec.expError != nil {
|
|
return
|
|
}
|
|
var loaded []testdata.TableModel
|
|
rowIDs, err := ReadAll(it, &loaded)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, spec.expResult, loaded)
|
|
assert.Equal(t, spec.expRowIDs, rowIDs)
|
|
})
|
|
}
|
|
}
|