X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fvalidation%2Ftx_test.go;h=484cfa2de1acb93b903ad08a60c5bdb328d937be;hp=ed0f06e83a827232703e7c06014a88b91edc934e;hb=3fd8afc8c8f3e63807d525a073f81d061cbade6d;hpb=089cb9074ed375e28850d2ff8b5e91164a04046d diff --git a/protocol/validation/tx_test.go b/protocol/validation/tx_test.go index ed0f06e8..484cfa2d 100644 --- a/protocol/validation/tx_test.go +++ b/protocol/validation/tx_test.go @@ -34,7 +34,7 @@ func TestGasStatus(t *testing.T) { BTMValue: 0, }, output: &GasState{ - GasLeft: 10000 / consensus.VMGasRate, + GasLeft: 10000/consensus.ActiveNetParams.VMGasRate + consensus.ActiveNetParams.DefaultGasCredit, GasUsed: 0, BTMValue: 10000, }, @@ -61,12 +61,12 @@ func TestGasStatus(t *testing.T) { }, { input: &GasState{ - GasLeft: consensus.DefaultGasCredit, + GasLeft: consensus.ActiveNetParams.DefaultGasCredit, GasUsed: 0, BTMValue: 0, }, output: &GasState{ - GasLeft: 200000, + GasLeft: 640000, GasUsed: 0, BTMValue: 80000000000, }, @@ -77,12 +77,12 @@ func TestGasStatus(t *testing.T) { }, { input: &GasState{ - GasLeft: consensus.DefaultGasCredit, + GasLeft: consensus.ActiveNetParams.DefaultGasCredit, GasUsed: 0, BTMValue: 0, }, output: &GasState{ - GasLeft: 200000, + GasLeft: 640000, GasUsed: 0, BTMValue: math.MaxInt64, }, @@ -231,8 +231,8 @@ func TestOverflow(t *testing.T) { txInputs := make([]*types.TxInput, 0, len(inputs)) txOutputs := make([]*types.TxOutput, 0, len(outputs)) - for _, amount := range inputs { - txInput := types.NewSpendInput(nil, *sourceID, *consensus.BTMAssetID, amount, 0, ctrlProgram) + for i, amount := range inputs { + txInput := types.NewSpendInput(nil, *sourceID, *consensus.BTMAssetID, amount, uint64(i), ctrlProgram) txInputs = append(txInputs, txInput) } @@ -500,7 +500,7 @@ func TestTxValidation(t *testing.T) { err: bc.ErrMissingEntry, }, { - desc: "no gas spend input", + desc: "normal check with no gas spend input", f: func() { spendID := mux.Sources[len(mux.Sources)-1].Ref delete(tx.Entries, *spendID) @@ -508,7 +508,7 @@ func TestTxValidation(t *testing.T) { tx.GasInputIDs = nil vs.gasStatus.GasLeft = 0 }, - err: vm.ErrRunLimitExceeded, + err: nil, }, { desc: "no gas spend input, but set gas left, so it's ok", @@ -557,7 +557,7 @@ func TestTxValidation(t *testing.T) { { desc: "coinbase arbitrary size out of limit", f: func() { - arbitrary := make([]byte, consensus.CoinbaseArbitrarySizeLimit+1) + arbitrary := make([]byte, consensus.ActiveNetParams.CoinbaseArbitrarySizeLimit+1) addCoinbase(consensus.BTMAssetID, 100000, arbitrary) }, err: ErrCoinbaseArbitraryOversize, @@ -712,8 +712,8 @@ func TestCoinbase(t *testing.T) { types.MapTx(&types.TxData{ SerializedSize: 1, Inputs: []*types.TxInput{ - types.NewSpendInput([][]byte{}, *newHash(8), *consensus.BTMAssetID, 100000000, 0, cp), types.NewCoinbaseInput(nil), + types.NewSpendInput([][]byte{}, *newHash(8), *consensus.BTMAssetID, 100000000, 0, cp), }, Outputs: []*types.TxOutput{ types.NewIntraChainOutput(*consensus.BTMAssetID, 888, cp), @@ -809,7 +809,7 @@ func TestTimeRange(t *testing.T) { block := &bc.Block{ BlockHeader: &bc.BlockHeader{ Height: 333, - Timestamp: 1521625823, + Timestamp: 1521625823000, }, } @@ -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