Skip to content

Commit eb53788

Browse files
committed
tests: add State deserialization test
1 parent 05d6e67 commit eb53788

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

types/serialization_test.go

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package types
33
import (
44
"crypto/rand"
55
"testing"
6+
"time"
67

78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910

1011
"github.com/tendermint/tendermint/crypto/ed25519"
12+
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
1113
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
14+
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
1215
tmtypes "github.com/tendermint/tendermint/types"
1316

1417
pb "github.com/celestiaorg/optimint/types/pb/optimint"
@@ -91,17 +94,70 @@ func TestStateRoundTrip(t *testing.T) {
9194
name string
9295
state State
9396
}{
94-
{"with max bytes", State{
95-
LastValidators: valSet,
96-
Validators: valSet,
97-
NextValidators: valSet,
98-
ConsensusParams: tmproto.ConsensusParams{
99-
Block: tmproto.BlockParams{
100-
MaxBytes: 123,
101-
MaxGas: 456,
102-
TimeIotaMs: 789,
97+
{
98+
"with max bytes",
99+
State{
100+
LastValidators: valSet,
101+
Validators: valSet,
102+
NextValidators: valSet,
103+
ConsensusParams: tmproto.ConsensusParams{
104+
Block: tmproto.BlockParams{
105+
MaxBytes: 123,
106+
MaxGas: 456,
107+
TimeIotaMs: 789,
108+
},
103109
},
104-
}}},
110+
},
111+
},
112+
{
113+
name: "with all fields set",
114+
state: State{
115+
Version: tmstate.Version{
116+
Consensus: tmversion.Consensus{
117+
Block: 123,
118+
App: 456,
119+
},
120+
Software: "optimint",
121+
},
122+
ChainID: "testchain",
123+
InitialHeight: 987,
124+
LastBlockHeight: 987654321,
125+
LastBlockID: tmtypes.BlockID{
126+
Hash: nil,
127+
PartSetHeader: tmtypes.PartSetHeader{
128+
Total: 0,
129+
Hash: nil,
130+
},
131+
},
132+
LastBlockTime: time.Date(2022, 6, 6, 12, 12, 33, 44, time.UTC),
133+
DAHeight: 3344,
134+
NextValidators: valSet,
135+
Validators: valSet,
136+
LastValidators: valSet,
137+
LastHeightValidatorsChanged: 8272,
138+
ConsensusParams: tmproto.ConsensusParams{
139+
Block: tmproto.BlockParams{
140+
MaxBytes: 12345,
141+
MaxGas: 6543234,
142+
TimeIotaMs: 235,
143+
},
144+
Evidence: tmproto.EvidenceParams{
145+
MaxAgeNumBlocks: 100,
146+
MaxAgeDuration: 200,
147+
MaxBytes: 300,
148+
},
149+
Validator: tmproto.ValidatorParams{
150+
PubKeyTypes: []string{"secure", "more secure"},
151+
},
152+
Version: tmproto.VersionParams{
153+
AppVersion: 42,
154+
},
155+
},
156+
LastHeightConsensusParamsChanged: 12345,
157+
LastResultsHash: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2},
158+
AppHash: [32]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1},
159+
},
160+
},
105161
}
106162

107163
for _, c := range cases {

0 commit comments

Comments
 (0)