diff --git a/consensus/update_test.go b/consensus/update_test.go index e93daf6c..948ca8f7 100644 --- a/consensus/update_test.go +++ b/consensus/update_test.go @@ -239,88 +239,3 @@ func TestApplyBlock(t *testing.T) { dbStore.RevertBlock(cs, ru) checkRevertElements(ru, addedSCEs, spentSCEs, addedSFEs, spentSFEs) } - -/* -func TestApplyV2Block(t *testing.T) { - n, genesisBlock := chain.TestnetZen() - n.InitialTarget = types.BlockID{0xFF} - n.HardforkDevAddr.Height = 0 - n.HardforkTax.Height = 0 - n.HardforkStorageProof.Height = 0 - n.HardforkOak.Height = 0 - n.HardforkASIC.Height = 0 - n.HardforkFoundation.Height = 0 - n.HardforkV2.AllowHeight = 1 - n.HardforkV2.RequireHeight = 1 - - cs := n.GenesisState() - bs := consensus.V1BlockSupplement{Transactions: make([]consensus.V1TransactionSupplement, len(genesisBlock.Transactions))} - cs, cau := consensus.ApplyBlock(cs, genesisBlock, bs, time.Time{}) - var sces []types.SiacoinElement - cau.ForEachSiacoinElement(func(sce types.SiacoinElement, spent bool) { sces = append(sces, sce) }) - for i := range sces { - if !cs.Elements.ContainsUnspentSiacoinElement(sces[i]) { - t.Fatal("missing siacoin element") - } - } - - b := types.Block{ - ParentID: cs.Index.ID, - Timestamp: types.CurrentTimestamp(), - MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}}, - } - cs, cau = consensus.ApplyBlock(cs, b, consensus.V1BlockSupplement{}, time.Time{}) - for i := range sces { - cau.UpdateElementProof(&sces[i].StateElement) - } - b = types.Block{ - ParentID: cs.Index.ID, - Timestamp: types.CurrentTimestamp(), - MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}}, - V2: &types.V2BlockData{ - Transactions: []types.V2Transaction{{ - SiacoinInputs: []types.V2SiacoinInput{{Parent: sces[1]}}, - MinerFee: sces[1].SiacoinOutput.Value, - }}, - }, - } - b.V2.Transactions[0].SiacoinOutputs = append(b.V2.Transactions[0].SiacoinOutputs, make([]types.SiacoinOutput, 30)...) - cs, cau = consensus.ApplyBlock(cs, b, consensus.V1BlockSupplement{}, time.Time{}) - for i := range sces { - cau.UpdateElementProof(&sces[i].StateElement) - cau.UpdateElementProof(&sces[i].StateElement) - cau.UpdateElementProof(&sces[i].StateElement) - } - if !cs.Elements.ContainsUnspentSiacoinElement(sces[0]) { - t.Error("missing siacoin element", 0) - } - if !cs.Elements.ContainsSpentSiacoinElement(sces[1]) { - t.Error("missing siacoin element", 1) - } - - b = types.Block{ - ParentID: cs.Index.ID, - Timestamp: types.CurrentTimestamp(), - MinerPayouts: []types.SiacoinOutput{{Address: types.VoidAddress, Value: cs.BlockReward()}}, - V2: &types.V2BlockData{ - Transactions: []types.V2Transaction{{ - SiacoinInputs: []types.V2SiacoinInput{{Parent: sces[0]}}, - MinerFee: sces[0].SiacoinOutput.Value, - }}, - }, - } - b.V2.Transactions[0].SiacoinOutputs = append(b.V2.Transactions[0].SiacoinOutputs, make([]types.SiacoinOutput, 30)...) - cs, cau = consensus.ApplyBlock(cs, b, consensus.V1BlockSupplement{}, time.Time{}) - for i := range sces { - cau.UpdateElementProof(&sces[i].StateElement) - cau.UpdateElementProof(&sces[i].StateElement) - cau.UpdateElementProof(&sces[i].StateElement) - } - if !cs.Elements.ContainsSpentSiacoinElement(sces[0]) { - t.Error("missing siacoin element", 0) - } - if !cs.Elements.ContainsSpentSiacoinElement(sces[1]) { - t.Error("missing siacoin element", 1) - } -} -*/ diff --git a/consensus/validation_test.go b/consensus/validation_test.go index e66108c5..464cd8b8 100644 --- a/consensus/validation_test.go +++ b/consensus/validation_test.go @@ -596,25 +596,24 @@ func TestValidateV2Block(t *testing.T) { giftAmountSC := types.Siacoins(100) giftAmountSF := uint64(100) - difference, _ := types.ParseCurrency("2080000000000000000000000") v1GiftFC := rhpv2.PrepareContractFormation(renterPublicKey, hostPublicKey, types.Siacoins(1), types.Siacoins(1), 100, rhpv2.HostSettings{}, types.VoidAddress) v2GiftFC := types.V2FileContract{ Filesize: v1GiftFC.Filesize, - ProofHeight: 20, - ExpirationHeight: 30, - // ExpirationHeight: - RenterOutput: v1GiftFC.ValidProofOutputs[0], - HostOutput: v1GiftFC.ValidProofOutputs[1], - MissedHostValue: v1GiftFC.MissedProofOutputs[1].Value, - TotalCollateral: v1GiftFC.Payout, - RenterPublicKey: renterPublicKey, - HostPublicKey: hostPublicKey, + ProofHeight: 5, + ExpirationHeight: 10, + RenterOutput: v1GiftFC.ValidProofOutputs[0], + HostOutput: v1GiftFC.ValidProofOutputs[1], + MissedHostValue: v1GiftFC.MissedProofOutputs[1].Value, + TotalCollateral: v1GiftFC.Payout, + RenterPublicKey: renterPublicKey, + HostPublicKey: hostPublicKey, } + contractCost := v2GiftFC.RenterOutput.Value.Add(v2GiftFC.HostOutput.Value).Add(n.GenesisState().V2FileContractTax(v2GiftFC)) giftTxn := types.V2Transaction{ SiacoinOutputs: []types.SiacoinOutput{ {Address: giftAddress, Value: giftAmountSC}, - {Address: giftAddress, Value: difference}, + {Address: giftAddress, Value: contractCost}, }, SiafundOutputs: []types.SiafundOutput{ {Address: giftAddress, Value: giftAmountSF}, @@ -672,7 +671,7 @@ func TestValidateV2Block(t *testing.T) { SatisfiedPolicy: types.SatisfiedPolicy{Policy: giftPolicy}, }}, SiacoinOutputs: []types.SiacoinOutput{ - {Value: giftAmountSC.Sub(minerFee).Sub(difference), Address: giftAddress}, + {Value: giftAmountSC.Sub(minerFee).Sub(contractCost), Address: giftAddress}, }, SiafundOutputs: []types.SiafundOutput{ {Value: giftAmountSF / 2, Address: giftAddress}, @@ -1039,9 +1038,9 @@ func TestValidateV2Block(t *testing.T) { }) cies = append(cies, testCau.ChainIndexElement()) - // mine 20 empty blocks + // mine empty blocks blockID := validBlock.ID() - for i := uint64(0); i < 20; i++ { + for i := uint64(0); i < v2GiftFC.ProofHeight; i++ { b := types.Block{ ParentID: blockID, Timestamp: types.CurrentTimestamp(),