@@ -2036,7 +2036,7 @@ func TestBaseApp_EndBlock(t *testing.T) {
20362036 require .Equal (t , cp .Block .MaxGas , res .ConsensusParamUpdates .Block .MaxGas )
20372037}
20382038
2039- func TestBaseApp_Init (t * testing.T ) {
2039+ func TestBaseApp_Init_PruningAndSnapshot (t * testing.T ) {
20402040 db := memdb .NewDB ()
20412041 name := t .Name ()
20422042 logger := defaultLogger ()
@@ -2045,10 +2045,11 @@ func TestBaseApp_Init(t *testing.T) {
20452045 require .NoError (t , err )
20462046
20472047 testCases := map [string ]struct {
2048- bapp * BaseApp
2049- expectedPruning pruningtypes.PruningOptions
2050- expectedSnapshot snapshottypes.SnapshotOptions
2051- expectedErr error
2048+ bapp * BaseApp
2049+ expectedPruning pruningtypes.PruningOptions
2050+ expectedSnapshot snapshottypes.SnapshotOptions
2051+ expectedErr error
2052+ isSnapshotManagerNil bool
20522053 }{
20532054 "snapshot but no pruning" : {
20542055 NewBaseApp (name , logger , db , nil ,
@@ -2058,14 +2059,26 @@ func TestBaseApp_Init(t *testing.T) {
20582059 snapshottypes .NewSnapshotOptions (1500 , 2 ),
20592060 // if no pruning is set, the default is PruneNothing
20602061 nil ,
2062+ false ,
2063+ },
2064+ "nil snapshot store" : {
2065+ NewBaseApp (name , logger , db , nil ,
2066+ SetPruning (pruningtypes .NewPruningOptions (pruningtypes .PruningNothing )),
2067+ SetSnapshot (nil , snapshottypes .NewSnapshotOptions (1500 , 2 )),
2068+ ),
2069+ pruningtypes .NewPruningOptions (pruningtypes .PruningNothing ),
2070+ snapshottypes.SnapshotOptions {},
2071+ nil ,
2072+ true ,
20612073 },
20622074 "pruning everything only" : {
20632075 NewBaseApp (name , logger , db , nil ,
20642076 SetPruning (pruningtypes .NewPruningOptions (pruningtypes .PruningEverything )),
20652077 ),
20662078 pruningtypes .NewPruningOptions (pruningtypes .PruningEverything ),
2067- snapshottypes .NewSnapshotOptions ( snapshottypes . SnapshotIntervalOff , 0 ) ,
2079+ snapshottypes.SnapshotOptions {} ,
20682080 nil ,
2081+ true ,
20692082 },
20702083 "pruning nothing only" : {
20712084 NewBaseApp (name , logger , db , nil ,
@@ -2074,6 +2087,7 @@ func TestBaseApp_Init(t *testing.T) {
20742087 pruningtypes .NewPruningOptions (pruningtypes .PruningNothing ),
20752088 snapshottypes .NewSnapshotOptions (snapshottypes .SnapshotIntervalOff , 0 ),
20762089 nil ,
2090+ true ,
20772091 },
20782092 "pruning default only" : {
20792093 NewBaseApp (name , logger , db , nil ,
@@ -2082,6 +2096,7 @@ func TestBaseApp_Init(t *testing.T) {
20822096 pruningtypes .NewPruningOptions (pruningtypes .PruningDefault ),
20832097 snapshottypes .NewSnapshotOptions (snapshottypes .SnapshotIntervalOff , 0 ),
20842098 nil ,
2099+ true ,
20852100 },
20862101 "pruning custom only" : {
20872102 NewBaseApp (name , logger , db , nil ,
@@ -2090,6 +2105,7 @@ func TestBaseApp_Init(t *testing.T) {
20902105 pruningtypes .NewCustomPruningOptions (10 , 10 ),
20912106 snapshottypes .NewSnapshotOptions (snapshottypes .SnapshotIntervalOff , 0 ),
20922107 nil ,
2108+ true ,
20932109 },
20942110 "pruning everything and snapshots" : {
20952111 NewBaseApp (name , logger , db , nil ,
@@ -2099,6 +2115,7 @@ func TestBaseApp_Init(t *testing.T) {
20992115 pruningtypes .NewPruningOptions (pruningtypes .PruningEverything ),
21002116 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21012117 nil ,
2118+ false ,
21022119 },
21032120 "pruning nothing and snapshots" : {
21042121 NewBaseApp (name , logger , db , nil ,
@@ -2108,6 +2125,7 @@ func TestBaseApp_Init(t *testing.T) {
21082125 pruningtypes .NewPruningOptions (pruningtypes .PruningNothing ),
21092126 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21102127 nil ,
2128+ false ,
21112129 },
21122130 "pruning default and snapshots" : {
21132131 NewBaseApp (name , logger , db , nil ,
@@ -2117,6 +2135,7 @@ func TestBaseApp_Init(t *testing.T) {
21172135 pruningtypes .NewPruningOptions (pruningtypes .PruningDefault ),
21182136 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21192137 nil ,
2138+ false ,
21202139 },
21212140 "pruning custom and snapshots" : {
21222141 NewBaseApp (name , logger , db , nil ,
@@ -2126,6 +2145,7 @@ func TestBaseApp_Init(t *testing.T) {
21262145 pruningtypes .NewCustomPruningOptions (10 , 10 ),
21272146 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21282147 nil ,
2148+ false ,
21292149 },
21302150 "error custom pruning 0 interval" : {
21312151 NewBaseApp (name , logger , db , nil ,
@@ -2135,6 +2155,7 @@ func TestBaseApp_Init(t *testing.T) {
21352155 pruningtypes .NewCustomPruningOptions (10 , 0 ),
21362156 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21372157 pruningtypes .ErrPruningIntervalZero ,
2158+ false ,
21382159 },
21392160 "error custom pruning too small interval" : {
21402161 NewBaseApp (name , logger , db , nil ,
@@ -2144,24 +2165,27 @@ func TestBaseApp_Init(t *testing.T) {
21442165 pruningtypes .NewCustomPruningOptions (10 , 9 ),
21452166 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21462167 pruningtypes .ErrPruningIntervalTooSmall ,
2168+ false ,
21472169 },
21482170 "error custom pruning too small keep recent" : {
21492171 NewBaseApp (name , logger , db , nil ,
2150- SetPruning (pruningtypes .NewCustomPruningOptions (9 , 10 )),
2172+ SetPruning (pruningtypes .NewCustomPruningOptions (1 , 10 )),
21512173 SetSnapshot (snapshotStore , snapshottypes .NewSnapshotOptions (1500 , 2 )),
21522174 ),
2153- pruningtypes .NewCustomPruningOptions (9 , 10 ),
2175+ pruningtypes .NewCustomPruningOptions (1 , 10 ),
21542176 snapshottypes .NewSnapshotOptions (1500 , 2 ),
21552177 pruningtypes .ErrPruningKeepRecentTooSmall ,
2178+ false ,
21562179 },
2157- "snapshot zero interval - manager not set" : {
2180+ "snapshot zero interval - manager is set" : {
21582181 NewBaseApp (name , logger , db , nil ,
21592182 SetPruning (pruningtypes .NewCustomPruningOptions (10 , 10 )),
21602183 SetSnapshot (snapshotStore , snapshottypes .NewSnapshotOptions (0 , 2 )),
21612184 ),
21622185 pruningtypes .NewCustomPruningOptions (10 , 10 ),
2163- snapshottypes .NewSnapshotOptions (snapshottypes .SnapshotIntervalOff , 0 ),
2186+ snapshottypes .NewSnapshotOptions (snapshottypes .SnapshotIntervalOff , 2 ),
21642187 nil ,
2188+ false ,
21652189 },
21662190 "snapshot zero keep recent - allowed" : {
21672191 NewBaseApp (name , logger , db , nil ,
@@ -2171,26 +2195,27 @@ func TestBaseApp_Init(t *testing.T) {
21712195 pruningtypes .NewCustomPruningOptions (10 , 10 ),
21722196 snapshottypes .NewSnapshotOptions (1500 , 0 ), // 0 snapshot-keep-recent means keep all
21732197 nil ,
2198+ false ,
21742199 },
21752200 }
21762201
2177- for _ , tc := range testCases {
2202+ for k , tc := range testCases {
21782203 // Init and validate
2179- require .Equal (t , tc .expectedErr , tc .bapp .Init ())
2204+ require .Equal (t , tc .expectedErr , tc .bapp .Init (), k )
21802205 if tc .expectedErr != nil {
21812206 continue
21822207 }
21832208
21842209 // Check that settings were set correctly
21852210 actualPruning := tc .bapp .store .GetPruning ()
2186- require .Equal (t , tc .expectedPruning , actualPruning )
2211+ require .Equal (t , tc .expectedPruning , actualPruning , k )
21872212
2188- if tc .expectedSnapshot . Interval == snapshottypes . SnapshotIntervalOff {
2189- require .Nil (t , tc .bapp .snapshotManager )
2213+ if tc .isSnapshotManagerNil {
2214+ require .Nil (t , tc .bapp .snapshotManager , k )
21902215 continue
21912216 }
21922217
2193- require .Equal (t , tc .expectedSnapshot .Interval , tc .bapp .snapshotManager .GetInterval ())
2194- require .Equal (t , tc .expectedSnapshot .KeepRecent , tc .bapp .snapshotManager .GetKeepRecent ())
2218+ require .Equal (t , tc .expectedSnapshot .Interval , tc .bapp .snapshotManager .GetInterval (), k )
2219+ require .Equal (t , tc .expectedSnapshot .KeepRecent , tc .bapp .snapshotManager .GetKeepRecent (), k )
21952220 }
21962221}
0 commit comments