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