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