gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/consensus/diffs_test.go (about) 1 package consensus 2 3 import ( 4 "testing" 5 6 bolt "github.com/coreos/bbolt" 7 "gitlab.com/SiaPrime/SiaPrime/modules" 8 "gitlab.com/SiaPrime/SiaPrime/types" 9 ) 10 11 // TestCommitDelayedSiacoinOutputDiffBadMaturity commits a delayed siacoin 12 // output that has a bad maturity height and triggers a panic. 13 func TestCommitDelayedSiacoinOutputDiffBadMaturity(t *testing.T) { 14 if testing.Short() { 15 t.SkipNow() 16 } 17 t.Parallel() 18 cst, err := createConsensusSetTester(t.Name()) 19 if err != nil { 20 t.Fatal(err) 21 } 22 defer cst.Close() 23 24 // Trigger an inconsistency check. 25 defer func() { 26 r := recover() 27 if r == nil { 28 t.Error("expecting error after corrupting database") 29 } 30 }() 31 32 // Commit a delayed siacoin output with maturity height = cs.height()+1 33 maturityHeight := cst.cs.dbBlockHeight() - 1 34 id := types.SiacoinOutputID{'1'} 35 dsco := types.SiacoinOutput{Value: types.NewCurrency64(1)} 36 dscod := modules.DelayedSiacoinOutputDiff{ 37 Direction: modules.DiffApply, 38 ID: id, 39 SiacoinOutput: dsco, 40 MaturityHeight: maturityHeight, 41 } 42 _ = cst.cs.db.Update(func(tx *bolt.Tx) error { 43 commitDelayedSiacoinOutputDiff(tx, dscod, modules.DiffApply) 44 return nil 45 }) 46 } 47 48 // TestCommitNodeDiffs probes the commitNodeDiffs method of the consensus set. 49 /* 50 func TestCommitNodeDiffs(t *testing.T) { 51 if testing.Short() { 52 t.SkipNow() 53 } 54 cst, err := createConsensusSetTester(t.Name()) 55 if err != nil { 56 t.Fatal(err) 57 } 58 defer cst.Close() 59 pb := cst.cs.dbCurrentProcessedBlock() 60 _ = cst.cs.db.Update(func(tx *bolt.Tx) error { 61 commitDiffSet(tx, pb, modules.DiffRevert) // pull the block node out of the consensus set. 62 return nil 63 }) 64 65 // For diffs that can be destroyed in the same block they are created, 66 // create diffs that do just that. This has in the past caused issues upon 67 // rewinding. 68 scoid := types.SiacoinOutputID{'1'} 69 scod0 := modules.SiacoinOutputDiff{ 70 Direction: modules.DiffApply, 71 ID: scoid, 72 } 73 scod1 := modules.SiacoinOutputDiff{ 74 Direction: modules.DiffRevert, 75 ID: scoid, 76 } 77 fcid := types.FileContractID{'2'} 78 fcd0 := modules.FileContractDiff{ 79 Direction: modules.DiffApply, 80 ID: fcid, 81 } 82 fcd1 := modules.FileContractDiff{ 83 Direction: modules.DiffRevert, 84 ID: fcid, 85 } 86 sfoid := types.SiafundOutputID{'3'} 87 sfod0 := modules.SiafundOutputDiff{ 88 Direction: modules.DiffApply, 89 ID: sfoid, 90 } 91 sfod1 := modules.SiafundOutputDiff{ 92 Direction: modules.DiffRevert, 93 ID: sfoid, 94 } 95 dscoid := types.SiacoinOutputID{'4'} 96 dscod := modules.DelayedSiacoinOutputDiff{ 97 Direction: modules.DiffApply, 98 ID: dscoid, 99 MaturityHeight: cst.cs.dbBlockHeight() + types.MaturityDelay, 100 } 101 var siafundPool types.Currency 102 err = cst.cs.db.Update(func(tx *bolt.Tx) error { 103 siafundPool = getSiafundPool(tx) 104 return nil 105 }) 106 if err != nil { 107 panic(err) 108 } 109 sfpd := modules.SiafundPoolDiff{ 110 Direction: modules.DiffApply, 111 Previous: siafundPool, 112 Adjusted: siafundPool.Add(types.NewCurrency64(1)), 113 } 114 pb.SiacoinOutputDiffs = append(pb.SiacoinOutputDiffs, scod0) 115 pb.SiacoinOutputDiffs = append(pb.SiacoinOutputDiffs, scod1) 116 pb.FileContractDiffs = append(pb.FileContractDiffs, fcd0) 117 pb.FileContractDiffs = append(pb.FileContractDiffs, fcd1) 118 pb.SiafundOutputDiffs = append(pb.SiafundOutputDiffs, sfod0) 119 pb.SiafundOutputDiffs = append(pb.SiafundOutputDiffs, sfod1) 120 pb.DelayedSiacoinOutputDiffs = append(pb.DelayedSiacoinOutputDiffs, dscod) 121 pb.SiafundPoolDiffs = append(pb.SiafundPoolDiffs, sfpd) 122 _ = cst.cs.db.Update(func(tx *bolt.Tx) error { 123 createUpcomingDelayedOutputMaps(tx, pb, modules.DiffApply) 124 return nil 125 }) 126 _ = cst.cs.db.Update(func(tx *bolt.Tx) error { 127 commitNodeDiffs(tx, pb, modules.DiffApply) 128 return nil 129 }) 130 exists := cst.cs.db.inSiacoinOutputs(scoid) 131 if exists { 132 t.Error("intradependent outputs not treated correctly") 133 } 134 exists = cst.cs.db.inFileContracts(fcid) 135 if exists { 136 t.Error("intradependent outputs not treated correctly") 137 } 138 exists = cst.cs.db.inSiafundOutputs(sfoid) 139 if exists { 140 t.Error("intradependent outputs not treated correctly") 141 } 142 _ = cst.cs.db.Update(func(tx *bolt.Tx) error { 143 commitNodeDiffs(tx, pb, modules.DiffRevert) 144 return nil 145 }) 146 exists = cst.cs.db.inSiacoinOutputs(scoid) 147 if exists { 148 t.Error("intradependent outputs not treated correctly") 149 } 150 exists = cst.cs.db.inFileContracts(fcid) 151 if exists { 152 t.Error("intradependent outputs not treated correctly") 153 } 154 exists = cst.cs.db.inSiafundOutputs(sfoid) 155 if exists { 156 t.Error("intradependent outputs not treated correctly") 157 } 158 } 159 */ 160 161 /* 162 // TestSiacoinOutputDiff applies and reverts a siacoin output diff, then 163 // triggers an inconsistency panic. 164 func TestCommitSiacoinOutputDiff(t *testing.T) { 165 if testing.Short() { 166 t.SkipNow() 167 } 168 cst, err := createConsensusSetTester(t.Name()) 169 if err != nil { 170 t.Fatal(err) 171 } 172 defer cst.Close() 173 174 // Commit a siacoin output diff. 175 initialScosLen := cst.cs.db.lenSiacoinOutputs() 176 id := types.SiacoinOutputID{'1'} 177 sco := types.SiacoinOutput{Value: types.NewCurrency64(1)} 178 scod := modules.SiacoinOutputDiff{ 179 Direction: modules.DiffApply, 180 ID: id, 181 SiacoinOutput: sco, 182 } 183 cst.cs.commitSiacoinOutputDiff(scod, modules.DiffApply) 184 if cst.cs.db.lenSiacoinOutputs() != initialScosLen+1 { 185 t.Error("siacoin output diff set did not increase in size") 186 } 187 if cst.cs.db.getSiacoinOutputs(id).Value.Cmp(sco.Value) != 0 { 188 t.Error("wrong siacoin output value after committing a diff") 189 } 190 191 // Rewind the diff. 192 cst.cs.commitSiacoinOutputDiff(scod, modules.DiffRevert) 193 if cst.cs.db.lenSiacoinOutputs() != initialScosLen { 194 t.Error("siacoin output diff set did not increase in size") 195 } 196 exists := cst.cs.db.inSiacoinOutputs(id) 197 if exists { 198 t.Error("siacoin output was not reverted") 199 } 200 201 // Restore the diff and then apply the inverse diff. 202 cst.cs.commitSiacoinOutputDiff(scod, modules.DiffApply) 203 scod.Direction = modules.DiffRevert 204 cst.cs.commitSiacoinOutputDiff(scod, modules.DiffApply) 205 if cst.cs.db.lenSiacoinOutputs() != initialScosLen { 206 t.Error("siacoin output diff set did not increase in size") 207 } 208 exists = cst.cs.db.inSiacoinOutputs(id) 209 if exists { 210 t.Error("siacoin output was not reverted") 211 } 212 213 // Revert the inverse diff. 214 cst.cs.commitSiacoinOutputDiff(scod, modules.DiffRevert) 215 if cst.cs.db.lenSiacoinOutputs() != initialScosLen+1 { 216 t.Error("siacoin output diff set did not increase in size") 217 } 218 if cst.cs.db.getSiacoinOutputs(id).Value.Cmp(sco.Value) != 0 { 219 t.Error("wrong siacoin output value after committing a diff") 220 } 221 222 // Trigger an inconsistency check. 223 defer func() { 224 r := recover() 225 if r != errBadCommitSiacoinOutputDiff { 226 t.Error("expecting errBadCommitSiacoinOutputDiff, got", r) 227 } 228 }() 229 // Try reverting a revert diff that was already reverted. (add an object 230 // that already exists) 231 cst.cs.commitSiacoinOutputDiff(scod, modules.DiffRevert) 232 } 233 */ 234 235 /* 236 // TestCommitFileContracttDiff applies and reverts a file contract diff, then 237 // triggers an inconsistency panic. 238 func TestCommitFileContractDiff(t *testing.T) { 239 if testing.Short() { 240 t.SkipNow() 241 } 242 cst, err := createConsensusSetTester(t.Name()) 243 if err != nil { 244 t.Fatal(err) 245 } 246 247 // Commit a file contract diff. 248 initialFcsLen := cst.cs.db.lenFileContracts() 249 id := types.FileContractID{'1'} 250 fc := types.FileContract{Payout: types.NewCurrency64(1)} 251 fcd := modules.FileContractDiff{ 252 Direction: modules.DiffApply, 253 ID: id, 254 FileContract: fc, 255 } 256 cst.cs.commitFileContractDiff(fcd, modules.DiffApply) 257 if cst.cs.db.lenFileContracts() != initialFcsLen+1 { 258 t.Error("siacoin output diff set did not increase in size") 259 } 260 if cst.cs.db.getFileContracts(id).Payout.Cmp(fc.Payout) != 0 { 261 t.Error("wrong siacoin output value after committing a diff") 262 } 263 264 // Rewind the diff. 265 cst.cs.commitFileContractDiff(fcd, modules.DiffRevert) 266 if cst.cs.db.lenFileContracts() != initialFcsLen { 267 t.Error("siacoin output diff set did not increase in size") 268 } 269 exists := cst.cs.db.inFileContracts(id) 270 if exists { 271 t.Error("siacoin output was not reverted") 272 } 273 274 // Restore the diff and then apply the inverse diff. 275 cst.cs.commitFileContractDiff(fcd, modules.DiffApply) 276 fcd.Direction = modules.DiffRevert 277 cst.cs.commitFileContractDiff(fcd, modules.DiffApply) 278 if cst.cs.db.lenFileContracts() != initialFcsLen { 279 t.Error("siacoin output diff set did not increase in size") 280 } 281 exists = cst.cs.db.inFileContracts(id) 282 if exists { 283 t.Error("siacoin output was not reverted") 284 } 285 286 // Revert the inverse diff. 287 cst.cs.commitFileContractDiff(fcd, modules.DiffRevert) 288 if cst.cs.db.lenFileContracts() != initialFcsLen+1 { 289 t.Error("siacoin output diff set did not increase in size") 290 } 291 if cst.cs.db.getFileContracts(id).Payout.Cmp(fc.Payout) != 0 { 292 t.Error("wrong siacoin output value after committing a diff") 293 } 294 295 // Trigger an inconsistency check. 296 defer func() { 297 r := recover() 298 if r != errBadCommitFileContractDiff { 299 t.Error("expecting errBadCommitFileContractDiff, got", r) 300 } 301 }() 302 // Try reverting an apply diff that was already reverted. (remove an object 303 // that was already removed) 304 fcd.Direction = modules.DiffApply // Object currently exists, but make the direction 'apply'. 305 cst.cs.commitFileContractDiff(fcd, modules.DiffRevert) // revert the application. 306 cst.cs.commitFileContractDiff(fcd, modules.DiffRevert) // revert the application again, in error. 307 } 308 */ 309 310 // TestSiafundOutputDiff applies and reverts a siafund output diff, then 311 // triggers an inconsistency panic. 312 /* 313 func TestCommitSiafundOutputDiff(t *testing.T) { 314 if testing.Short() { 315 t.SkipNow() 316 } 317 cst, err := createConsensusSetTester(t.Name()) 318 if err != nil { 319 t.Fatal(err) 320 } 321 322 // Commit a siafund output diff. 323 initialScosLen := cst.cs.db.lenSiafundOutputs() 324 id := types.SiafundOutputID{'1'} 325 sfo := types.SiafundOutput{Value: types.NewCurrency64(1)} 326 sfod := modules.SiafundOutputDiff{ 327 Direction: modules.DiffApply, 328 ID: id, 329 SiafundOutput: sfo, 330 } 331 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffApply) 332 if cst.cs.db.lenSiafundOutputs() != initialScosLen+1 { 333 t.Error("siafund output diff set did not increase in size") 334 } 335 sfo1 := cst.cs.db.getSiafundOutputs(id) 336 if sfo1.Value.Cmp(sfo.Value) != 0 { 337 t.Error("wrong siafund output value after committing a diff") 338 } 339 340 // Rewind the diff. 341 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffRevert) 342 if cst.cs.db.lenSiafundOutputs() != initialScosLen { 343 t.Error("siafund output diff set did not increase in size") 344 } 345 exists := cst.cs.db.inSiafundOutputs(id) 346 if exists { 347 t.Error("siafund output was not reverted") 348 } 349 350 // Restore the diff and then apply the inverse diff. 351 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffApply) 352 sfod.Direction = modules.DiffRevert 353 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffApply) 354 if cst.cs.db.lenSiafundOutputs() != initialScosLen { 355 t.Error("siafund output diff set did not increase in size") 356 } 357 exists = cst.cs.db.inSiafundOutputs(id) 358 if exists { 359 t.Error("siafund output was not reverted") 360 } 361 362 // Revert the inverse diff. 363 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffRevert) 364 if cst.cs.db.lenSiafundOutputs() != initialScosLen+1 { 365 t.Error("siafund output diff set did not increase in size") 366 } 367 sfo2 := cst.cs.db.getSiafundOutputs(id) 368 if sfo2.Value.Cmp(sfo.Value) != 0 { 369 t.Error("wrong siafund output value after committing a diff") 370 } 371 372 // Trigger an inconsistency check. 373 defer func() { 374 r := recover() 375 if r != errBadCommitSiafundOutputDiff { 376 t.Error("expecting errBadCommitSiafundOutputDiff, got", r) 377 } 378 }() 379 // Try applying a revert diff that was already applied. (remove an object 380 // that was already removed) 381 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffApply) // Remove the object. 382 cst.cs.commitSiafundOutputDiff(sfod, modules.DiffApply) // Remove the object again. 383 } 384 */ 385 386 // TestCommitDelayedSiacoinOutputDiff probes the commitDelayedSiacoinOutputDiff 387 // method of the consensus set. 388 /* 389 func TestCommitDelayedSiacoinOutputDiff(t *testing.T) { 390 t.Skip("test isn't working, but checks the wrong code anyway") 391 if testing.Short() { 392 t.Skip() 393 } 394 cst, err := createConsensusSetTester(t.Name()) 395 if err != nil { 396 t.Fatal(err) 397 } 398 399 // Commit a delayed siacoin output with maturity height = cs.height()+1 400 maturityHeight := cst.cs.height() + 1 401 initialDscosLen := cst.cs.db.lenDelayedSiacoinOutputsHeight(maturityHeight) 402 id := types.SiacoinOutputID{'1'} 403 dsco := types.SiacoinOutput{Value: types.NewCurrency64(1)} 404 dscod := modules.DelayedSiacoinOutputDiff{ 405 Direction: modules.DiffApply, 406 ID: id, 407 SiacoinOutput: dsco, 408 MaturityHeight: maturityHeight, 409 } 410 cst.cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffApply) 411 if cst.cs.db.lenDelayedSiacoinOutputsHeight(maturityHeight) != initialDscosLen+1 { 412 t.Fatal("delayed output diff set did not increase in size") 413 } 414 if cst.cs.db.getDelayedSiacoinOutputs(maturityHeight, id).Value.Cmp(dsco.Value) != 0 { 415 t.Error("wrong delayed siacoin output value after committing a diff") 416 } 417 418 // Rewind the diff. 419 cst.cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffRevert) 420 if cst.cs.db.lenDelayedSiacoinOutputsHeight(maturityHeight) != initialDscosLen { 421 t.Error("siacoin output diff set did not increase in size") 422 } 423 exists := cst.cs.db.inDelayedSiacoinOutputsHeight(maturityHeight, id) 424 if exists { 425 t.Error("siacoin output was not reverted") 426 } 427 428 // Restore the diff and then apply the inverse diff. 429 cst.cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffApply) 430 dscod.Direction = modules.DiffRevert 431 cst.cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffApply) 432 if cst.cs.db.lenDelayedSiacoinOutputsHeight(maturityHeight) != initialDscosLen { 433 t.Error("siacoin output diff set did not increase in size") 434 } 435 exists = cst.cs.db.inDelayedSiacoinOutputsHeight(maturityHeight, id) 436 if exists { 437 t.Error("siacoin output was not reverted") 438 } 439 440 // Revert the inverse diff. 441 cst.cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffRevert) 442 if cst.cs.db.lenDelayedSiacoinOutputsHeight(maturityHeight) != initialDscosLen+1 { 443 t.Error("siacoin output diff set did not increase in size") 444 } 445 if cst.cs.db.getDelayedSiacoinOutputs(maturityHeight, id).Value.Cmp(dsco.Value) != 0 { 446 t.Error("wrong siacoin output value after committing a diff") 447 } 448 449 // Trigger an inconsistency check. 450 defer func() { 451 r := recover() 452 if r != errBadCommitDelayedSiacoinOutputDiff { 453 t.Error("expecting errBadCommitDelayedSiacoinOutputDiff, got", r) 454 } 455 }() 456 // Try applying an apply diff that was already applied. (add an object 457 // that already exists) 458 dscod.Direction = modules.DiffApply // set the direction to apply 459 cst.cs.commitDelayedSiacoinOutputDiff(dscod, modules.DiffApply) // apply an already existing delayed output. 460 } 461 */ 462 463 /* 464 // TestCommitSiafundPoolDiff probes the commitSiafundPoolDiff method of the 465 // consensus set. 466 func TestCommitSiafundPoolDiff(t *testing.T) { 467 if testing.Short() { 468 t.SkipNow() 469 } 470 cst, err := createConsensusSetTester(t.Name()) 471 if err != nil { 472 t.Fatal(err) 473 } 474 475 // Apply two siafund pool diffs, and then a diff with 0 change. Then revert 476 // them all. 477 initial := cst.cs.siafundPool 478 adjusted1 := initial.Add(types.NewCurrency64(200)) 479 adjusted2 := adjusted1.Add(types.NewCurrency64(500)) 480 adjusted3 := adjusted2.Add(types.NewCurrency64(0)) 481 sfpd1 := modules.SiafundPoolDiff{ 482 Direction: modules.DiffApply, 483 Previous: initial, 484 Adjusted: adjusted1, 485 } 486 sfpd2 := modules.SiafundPoolDiff{ 487 Direction: modules.DiffApply, 488 Previous: adjusted1, 489 Adjusted: adjusted2, 490 } 491 sfpd3 := modules.SiafundPoolDiff{ 492 Direction: modules.DiffApply, 493 Previous: adjusted2, 494 Adjusted: adjusted3, 495 } 496 cst.cs.commitSiafundPoolDiff(sfpd1, modules.DiffApply) 497 if cst.cs.siafundPool.Cmp(adjusted1) != 0 { 498 t.Error("siafund pool was not adjusted correctly") 499 } 500 cst.cs.commitSiafundPoolDiff(sfpd2, modules.DiffApply) 501 if cst.cs.siafundPool.Cmp(adjusted2) != 0 { 502 t.Error("second siafund pool adjustment was flawed") 503 } 504 cst.cs.commitSiafundPoolDiff(sfpd3, modules.DiffApply) 505 if cst.cs.siafundPool.Cmp(adjusted3) != 0 { 506 t.Error("second siafund pool adjustment was flawed") 507 } 508 cst.cs.commitSiafundPoolDiff(sfpd3, modules.DiffRevert) 509 if cst.cs.siafundPool.Cmp(adjusted2) != 0 { 510 t.Error("reverting second adjustment was flawed") 511 } 512 cst.cs.commitSiafundPoolDiff(sfpd2, modules.DiffRevert) 513 if cst.cs.siafundPool.Cmp(adjusted1) != 0 { 514 t.Error("reverting second adjustment was flawed") 515 } 516 cst.cs.commitSiafundPoolDiff(sfpd1, modules.DiffRevert) 517 if cst.cs.siafundPool.Cmp(initial) != 0 { 518 t.Error("reverting first adjustment was flawed") 519 } 520 521 // Do a chaining set of panics. First apply a negative pool adjustment, 522 // then revert the pool diffs in the wrong order, than apply the pool diffs 523 // in the wrong order. 524 defer func() { 525 r := recover() 526 if r != errApplySiafundPoolDiffMismatch { 527 t.Error("expecting errApplySiafundPoolDiffMismatch, got", r) 528 } 529 }() 530 defer func() { 531 r := recover() 532 if r != errRevertSiafundPoolDiffMismatch { 533 t.Error("expecting errRevertSiafundPoolDiffMismatch, got", r) 534 } 535 cst.cs.commitSiafundPoolDiff(sfpd1, modules.DiffApply) 536 }() 537 defer func() { 538 r := recover() 539 if r != errNonApplySiafundPoolDiff { 540 t.Error(r) 541 } 542 cst.cs.commitSiafundPoolDiff(sfpd1, modules.DiffRevert) 543 }() 544 defer func() { 545 r := recover() 546 if r != errNegativePoolAdjustment { 547 t.Error("expecting errNegativePoolAdjustment, got", r) 548 } 549 sfpd2.Direction = modules.DiffRevert 550 cst.cs.commitSiafundPoolDiff(sfpd2, modules.DiffApply) 551 }() 552 cst.cs.commitSiafundPoolDiff(sfpd1, modules.DiffApply) 553 cst.cs.commitSiafundPoolDiff(sfpd2, modules.DiffApply) 554 negativeAdjustment := adjusted2.Sub(types.NewCurrency64(100)) 555 negativeSfpd := modules.SiafundPoolDiff{ 556 Previous: adjusted3, 557 Adjusted: negativeAdjustment, 558 } 559 cst.cs.commitSiafundPoolDiff(negativeSfpd, modules.DiffApply) 560 } 561 */ 562 563 /* 564 // TestDeleteObsoleteDelayedOutputMapsSanity probes the sanity checks of the 565 // deleteObsoleteDelayedOutputMaps method of the consensus set. 566 func TestDeleteObsoleteDelayedOutputMapsSanity(t *testing.T) { 567 if testing.Short() { 568 t.SkipNow() 569 } 570 cst, err := createConsensusSetTester(t.Name()) 571 if err != nil { 572 t.Fatal(err) 573 } 574 pb := cst.cs.currentProcessedBlock() 575 err = cst.cs.db.Update(func(tx *bolt.Tx) error { 576 return commitDiffSet(tx, pb, modules.DiffRevert) 577 }) 578 if err != nil { 579 t.Fatal(err) 580 } 581 582 defer func() { 583 r := recover() 584 if r == nil { 585 t.Error("expecting an error after corrupting the database") 586 } 587 }() 588 defer func() { 589 r := recover() 590 if r == nil { 591 t.Error("expecting an error after corrupting the database") 592 } 593 594 // Trigger a panic by deleting a map with outputs in it during revert. 595 err = cst.cs.db.Update(func(tx *bolt.Tx) error { 596 return createUpcomingDelayedOutputMaps(tx, pb, modules.DiffApply) 597 }) 598 if err != nil { 599 t.Fatal(err) 600 } 601 err = cst.cs.db.Update(func(tx *bolt.Tx) error { 602 return commitNodeDiffs(tx, pb, modules.DiffApply) 603 }) 604 if err != nil { 605 t.Fatal(err) 606 } 607 err = cst.cs.db.Update(func(tx *bolt.Tx) error { 608 return deleteObsoleteDelayedOutputMaps(tx, pb, modules.DiffRevert) 609 }) 610 if err != nil { 611 t.Fatal(err) 612 } 613 }() 614 615 // Trigger a panic by deleting a map with outputs in it during apply. 616 err = cst.cs.db.Update(func(tx *bolt.Tx) error { 617 return deleteObsoleteDelayedOutputMaps(tx, pb, modules.DiffApply) 618 }) 619 if err != nil { 620 t.Fatal(err) 621 } 622 } 623 */ 624 625 /* 626 // TestGenerateAndApplyDiffSanity triggers the sanity checks in the 627 // generateAndApplyDiff method of the consensus set. 628 func TestGenerateAndApplyDiffSanity(t *testing.T) { 629 if testing.Short() { 630 t.SkipNow() 631 } 632 cst, err := createConsensusSetTester(t.Name()) 633 if err != nil { 634 t.Fatal(err) 635 } 636 pb := cst.cs.currentProcessedBlock() 637 cst.cs.commitDiffSet(pb, modules.DiffRevert) 638 639 defer func() { 640 r := recover() 641 if r != errRegenerateDiffs { 642 t.Error("expected errRegenerateDiffs, got", r) 643 } 644 }() 645 defer func() { 646 r := recover() 647 if r != errInvalidSuccessor { 648 t.Error("expected errInvalidSuccessor, got", r) 649 } 650 651 // Trigger errRegenerteDiffs 652 _ = cst.cs.generateAndApplyDiff(pb) 653 }() 654 655 // Trigger errInvalidSuccessor 656 parent := cst.cs.db.getBlockMap(pb.Parent) 657 parent.DiffsGenerated = false 658 _ = cst.cs.generateAndApplyDiff(parent) 659 } 660 */