// TestApplyMissedStorageProof probes the applyMissedStorageProof method of the // consensus set. func TestApplyMissedStorageProof(t *testing.T) { if testing.Short() { t.SkipNow() } cst, err := createConsensusSetTester("TestApplyMissedStorageProof") if err != nil { t.Fatal(err) } defer cst.closeCst() // Create a block node. pb := new(processedBlock) pb.Height = cst.cs.height() // Create a file contract that's expiring and has 1 missed proof output. expiringFC := types.FileContract{ Payout: types.NewCurrency64(300e3), WindowEnd: pb.Height, MissedProofOutputs: []types.SiacoinOutput{{Value: types.NewCurrency64(290e3)}}, } // Assign the contract a 0-id. cst.cs.db.addFileContracts(types.FileContractID{}, expiringFC) cst.cs.db.addFCExpirations(pb.Height) cst.cs.db.addFCExpirationsHeight(pb.Height, types.FileContractID{}) cst.cs.applyMissedStorageProof(pb, types.FileContractID{}) exists := cst.cs.db.inFileContracts(types.FileContractID{}) if exists { t.Error("file contract was not consumed in missed storage proof") } spoid := types.FileContractID{}.StorageProofOutputID(types.ProofMissed, 0) exists = cst.cs.db.inDelayedSiacoinOutputsHeight(pb.Height+types.MaturityDelay, spoid) if !exists { t.Error("missed proof output was never created") } exists = cst.cs.db.inSiacoinOutputs(spoid) if exists { t.Error("storage proof output made it into the siacoin output set") } exists = cst.cs.db.inFileContracts(types.FileContractID{}) if exists { t.Error("file contract remains after expiration") } // Trigger the debug panics. // not exist. defer func() { r := recover() if r != errNilItem { t.Error(r) } }() defer func() { r := recover() if r != errNilItem { t.Error(r) } // Trigger errMissingFileContract cst.cs.applyMissedStorageProof(pb, types.FileContractID(spoid)) }() defer func() { r := recover() if r != errNilItem { t.Error(r) } // Trigger errStorageProofTiming expiringFC.WindowEnd = 0 cst.cs.applyMissedStorageProof(pb, types.FileContractID{}) }() defer func() { r := recover() if r != errNilItem { t.Error(r) } // Trigger errPayoutsAlreadyPaid from siacoin outputs. cst.cs.db.rmDelayedSiacoinOutputsHeight(pb.Height+types.MaturityDelay, spoid) cst.cs.db.addSiacoinOutputs(spoid, types.SiacoinOutput{}) cst.cs.applyMissedStorageProof(pb, types.FileContractID{}) }() // Trigger errPayoutsAlreadyPaid from delayed outputs. cst.cs.db.rmFileContracts(types.FileContractID{}) cst.cs.db.addFileContracts(types.FileContractID{}, expiringFC) cst.cs.db.addDelayedSiacoinOutputsHeight(pb.Height+types.MaturityDelay, spoid, types.SiacoinOutput{}) cst.cs.applyMissedStorageProof(pb, types.FileContractID{}) }