refactor(schema)!: move view interfaces from testing to schema (#21204)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"cosmossdk.io/schema"
|
||||
"cosmossdk.io/schema/appdata"
|
||||
"cosmossdk.io/schema/testing/statesim"
|
||||
"cosmossdk.io/schema/view"
|
||||
)
|
||||
|
||||
// Options are the options for creating an app data simulator.
|
||||
@@ -151,11 +152,11 @@ func (a *Simulator) ProcessPacket(packet appdata.Packet) error {
|
||||
}
|
||||
|
||||
// AppState returns the current app state backing the simulator.
|
||||
func (a *Simulator) AppState() statesim.AppState {
|
||||
func (a *Simulator) AppState() view.AppState {
|
||||
return a.state
|
||||
}
|
||||
|
||||
// BlockNum returns the current block number of the simulator.
|
||||
func (a *Simulator) BlockNum() uint64 {
|
||||
return a.blockNum
|
||||
func (a *Simulator) BlockNum() (uint64, error) {
|
||||
return a.blockNum, nil
|
||||
}
|
||||
|
||||
@@ -4,25 +4,15 @@ import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/schema/testing/statesim"
|
||||
"cosmossdk.io/schema/view"
|
||||
)
|
||||
|
||||
// HasAppData defines an interface for things that hold app data include app state.
|
||||
// If an indexer implements this then DiffAppData can be used to compare it with
|
||||
// the Simulator state which also implements this.
|
||||
type HasAppData interface {
|
||||
// AppState returns the app state.
|
||||
AppState() statesim.AppState
|
||||
|
||||
// BlockNum returns the latest block number.
|
||||
BlockNum() uint64
|
||||
}
|
||||
|
||||
// DiffAppData compares the app data of two objects that implement HasAppData.
|
||||
// This can be used by indexer to compare their state with the Simulator state
|
||||
// if the indexer implements HasAppData.
|
||||
// It returns a human-readable diff if the app data differs and the empty string
|
||||
// if they are the same.
|
||||
func DiffAppData(expected, actual HasAppData) string {
|
||||
func DiffAppData(expected, actual view.AppData) string {
|
||||
res := ""
|
||||
|
||||
if stateDiff := statesim.DiffAppStates(expected.AppState(), actual.AppState()); stateDiff != "" {
|
||||
@@ -30,8 +20,20 @@ func DiffAppData(expected, actual HasAppData) string {
|
||||
res += stateDiff
|
||||
}
|
||||
|
||||
if expected.BlockNum() != actual.BlockNum() {
|
||||
res += fmt.Sprintf("BlockNum: expected %d, got %d\n", expected.BlockNum(), actual.BlockNum())
|
||||
expectedBlock, err := expected.BlockNum()
|
||||
if err != nil {
|
||||
res += fmt.Sprintf("ERROR getting expected block num: %s\n", err)
|
||||
return res
|
||||
}
|
||||
|
||||
actualBlock, err := actual.BlockNum()
|
||||
if err != nil {
|
||||
res += fmt.Sprintf("ERROR getting actual block num: %s\n", err)
|
||||
return res
|
||||
}
|
||||
|
||||
if expectedBlock != actualBlock {
|
||||
res += fmt.Sprintf("BlockNum: expected %d, got %d\n", expectedBlock, actualBlock)
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
@@ -78,7 +78,7 @@ StartBlock: {6 <nil> <nil>}
|
||||
OnObjectUpdate: {"ModuleName":"test_cases","Updates":[{"TypeName":"TwoKeys","Key":["A𞥟",981],"Value":null,"Delete":false},{"TypeName":"ManyValues","Key":"ᵕ؏A","Value":{"Value1":-317,"Value2":"AA==","Value3":-37.62890625,"Value4":232},"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"all_kinds","Updates":[{"TypeName":"test_address","Key":"AACHBAjyAgFHOQAABo+PGAK3Bj7TwwBb/wAB3gE=","Value":{"valNotNull":"HBwBHAY6AAKO+UwDKRICAT0lgRRvCRvHFFoNAigBAUEDHoQUfB2qApRB/z41AAubARsBATQg3gCppQMAAQwHAQ=="},"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"all_kinds","Updates":[{"TypeName":"test_decimal","Key":"9.5E+8","Value":["-2","88111430.0122412446"],"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"all_kinds","Updates":[{"TypeName":"test_uint8","Key":7,"Value":null,"Delete":true},{"TypeName":"test_time","Key":"1970-01-01T00:59:59.999999999+01:00","Value":["1970-01-01T01:00:00.000000001+01:00",null],"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"all_kinds","Updates":[{"TypeName":"test_uint8","Key":7,"Value":null,"Delete":true},{"TypeName":"test_time","Key":"1969-12-31T18:59:59.999999999-05:00","Value":["1969-12-31T19:00:00.000000001-05:00",null],"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"test_cases","Updates":[{"TypeName":"RetainDeletions","Key":"൴~𝔶ٞ蹯a_ ᛮ!؋aض©-?","Value":{"Value2":""},"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"all_kinds","Updates":[{"TypeName":"test_uint8","Key":14,"Value":{"valNotNull":116},"Delete":false},{"TypeName":"test_duration","Key":100403021838,"Value":[1547,null],"Delete":false}]}
|
||||
OnObjectUpdate: {"ModuleName":"all_kinds","Updates":[{"TypeName":"test_int64","Key":-34196421,"Value":[56,224549431],"Delete":false},{"TypeName":"test_bool","Key":true,"Value":{"valNotNull":true,"valNullable":null},"Delete":false}]}
|
||||
|
||||
+5
-5
@@ -60,10 +60,10 @@ Module all_kinds
|
||||
Object key=℠¼々¢~;-Ⱥ!˃a[ʰᾌ?{ᪧ৵%ᾯ¦〈: NOT FOUND
|
||||
Object Collection test_time
|
||||
OBJECT COUNT ERROR: expected 4, got 3
|
||||
Object key=1970-01-01 01:00:00.000000005 +0100 CET: NOT FOUND
|
||||
Object key=1970-01-01 01:00:00.001598687 +0100 CET
|
||||
valNotNull: expected 1970-01-01 01:00:00.007727197 +0100 CET, got 1970-01-01 01:00:00.034531678 +0100 CET
|
||||
valNullable: expected 1970-01-01 01:00:00.000000484 +0100 CET, got 1970-01-01 01:00:00.000000033 +0100 CET
|
||||
Object key=1969-12-31 19:00:00.000000005 -0500 EST: NOT FOUND
|
||||
Object key=1969-12-31 19:00:00.001598687 -0500 EST
|
||||
valNotNull: expected 1969-12-31 19:00:00.007727197 -0500 EST, got 1969-12-31 19:00:00.034531678 -0500 EST
|
||||
valNullable: expected 1969-12-31 19:00:00.000000484 -0500 EST, got 1969-12-31 19:00:00.000000033 -0500 EST
|
||||
Object Collection test_uint16
|
||||
OBJECT COUNT ERROR: expected 4, got 3
|
||||
Object key=23712: NOT FOUND
|
||||
@@ -75,5 +75,5 @@ Module all_kinds
|
||||
Object Collection test_uint8
|
||||
OBJECT COUNT ERROR: expected 3, got 2
|
||||
Object key=1: NOT FOUND
|
||||
Module test_cases: NOT FOUND
|
||||
Module test_cases: actual module NOT FOUND
|
||||
BlockNum: expected 2, got 1
|
||||
|
||||
Reference in New Issue
Block a user