BTMValue: 0,
},
output: &GasState{
- GasLeft: 10000 / consensus.VMGasRate,
+ GasLeft: 10000/consensus.ActiveNetParams.VMGasRate + consensus.ActiveNetParams.DefaultGasCredit,
GasUsed: 0,
BTMValue: 10000,
},
},
{
input: &GasState{
- GasLeft: consensus.DefaultGasCredit,
+ GasLeft: consensus.ActiveNetParams.DefaultGasCredit,
GasUsed: 0,
BTMValue: 0,
},
output: &GasState{
- GasLeft: 200000,
+ GasLeft: 640000,
GasUsed: 0,
BTMValue: 80000000000,
},
},
{
input: &GasState{
- GasLeft: consensus.DefaultGasCredit,
+ GasLeft: consensus.ActiveNetParams.DefaultGasCredit,
GasUsed: 0,
BTMValue: 0,
},
output: &GasState{
- GasLeft: 200000,
+ GasLeft: 640000,
GasUsed: 0,
BTMValue: math.MaxInt64,
},
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)
}
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)
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",
{
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,
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),
block := &bc.Block{
BlockHeader: &bc.BlockHeader{
Height: 333,
- Timestamp: 1521625823,
+ Timestamp: 1521625823000,
},
}
}
}
-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