OSDN Git Service

Cancel contract of btm inspection (#198)
authorwz <mars@bytom.io>
Thu, 20 Jun 2019 02:28:31 +0000 (10:28 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 20 Jun 2019 02:28:31 +0000 (10:28 +0800)
* Cancel  contract of btm inspection

* fix test

protocol/validation/tx.go
protocol/validation/tx_test.go

index 0768d88..65f4815 100644 (file)
@@ -6,7 +6,6 @@ import (
 
        "github.com/vapor/config"
        "github.com/vapor/consensus"
-       "github.com/vapor/consensus/segwit"
        "github.com/vapor/errors"
        "github.com/vapor/math/checked"
        "github.com/vapor/protocol/bc"
@@ -524,37 +523,12 @@ func checkValidDest(vs *validationState, vd *bc.ValueDestination) error {
        return nil
 }
 
-func checkStandardTx(tx *bc.Tx, blockHeight uint64) error {
+func checkInputID(tx *bc.Tx, blockHeight uint64) error {
        for _, id := range tx.InputIDs {
                if blockHeight >= ruleAA && id.IsZero() {
                        return ErrEmptyInputIDs
                }
        }
-
-       for _, id := range tx.GasInputIDs {
-               spend, err := tx.Spend(id)
-               if err != nil {
-                       continue
-               }
-
-               code := []byte{}
-               outputEntry, err := tx.Entry(*spend.SpentOutputId)
-               if err != nil {
-                       return err
-               }
-               switch output := outputEntry.(type) {
-               case *bc.IntraChainOutput:
-                       code = output.ControlProgram.Code
-               case *bc.VoteOutput:
-                       code = output.ControlProgram.Code
-               default:
-                       return errors.Wrapf(bc.ErrEntryType, "entry %x has unexpected type %T", id.Bytes(), outputEntry)
-               }
-
-               if !segwit.IsP2WScript(code) {
-                       return ErrNotStandardTx
-               }
-       }
        return nil
 }
 
@@ -582,7 +556,7 @@ func ValidateTx(tx *bc.Tx, block *bc.Block) (*GasState, error) {
        if err := checkTimeRange(tx, block); err != nil {
                return gasStatus, err
        }
-       if err := checkStandardTx(tx, block.Height); err != nil {
+       if err := checkInputID(tx, block.Height); err != nil {
                return gasStatus, err
        }
 
index a9a2f3d..4fd3a66 100644 (file)
@@ -832,53 +832,6 @@ func TestTimeRange(t *testing.T) {
        }
 }
 
-func TestStandardTx(t *testing.T) {
-       fixture := sample(t, nil)
-       tx := types.NewTx(*fixture.tx).Tx
-
-       cases := []struct {
-               desc string
-               f    func()
-               err  error
-       }{
-               {
-                       desc: "normal standard tx",
-                       err:  nil,
-               },
-               {
-                       desc: "not standard tx in spend input",
-                       f: func() {
-                               inputID := tx.GasInputIDs[0]
-                               spend := tx.Entries[inputID].(*bc.Spend)
-                               spentOutput, err := tx.IntraChainOutput(*spend.SpentOutputId)
-                               if err != nil {
-                                       t.Fatal(err)
-                               }
-                               spentOutput.ControlProgram = &bc.Program{Code: []byte{0}}
-                       },
-                       err: ErrNotStandardTx,
-               },
-               {
-                       desc: "not standard tx in output",
-                       f: func() {
-                               outputID := tx.ResultIds[0]
-                               output := tx.Entries[*outputID].(*bc.IntraChainOutput)
-                               output.ControlProgram = &bc.Program{Code: []byte{0}}
-                       },
-                       err: ErrNotStandardTx,
-               },
-       }
-
-       for i, c := range cases {
-               if c.f != nil {
-                       c.f()
-               }
-               if err := checkStandardTx(tx, 0); err != c.err {
-                       t.Errorf("case #%d (%s) got error %t, want %t", i, c.desc, err, c.err)
-               }
-       }
-}
-
 func TestValidateTxVersion(t *testing.T) {
        cases := []struct {
                desc  string