"github.com/davecgh/go-spew/spew"
- "github.com/bytom/consensus"
- "github.com/bytom/crypto/sha3pool"
- "github.com/bytom/errors"
- "github.com/bytom/protocol/bc"
- "github.com/bytom/protocol/bc/types"
- "github.com/bytom/protocol/vm"
- "github.com/bytom/protocol/vm/vmutil"
- "github.com/bytom/testutil"
+ "github.com/bytom/bytom/consensus"
+ "github.com/bytom/bytom/crypto/sha3pool"
+ "github.com/bytom/bytom/errors"
+ "github.com/bytom/bytom/protocol/bc"
+ "github.com/bytom/bytom/protocol/bc/types"
+ "github.com/bytom/bytom/protocol/vm"
+ "github.com/bytom/bytom/protocol/vm/vmutil"
+ "github.com/bytom/bytom/testutil"
)
func init() {
},
{
input: &GasState{
+ GasLeft: consensus.DefaultGasCredit,
+ GasUsed: 0,
+ BTMValue: 0,
+ },
+ output: &GasState{
+ GasLeft: 200000,
+ GasUsed: 0,
+ BTMValue: math.MaxInt64,
+ },
+ f: func(input *GasState) error {
+ return input.setGas(math.MaxInt64, 0)
+ },
+ err: nil,
+ },
+ {
+ input: &GasState{
GasLeft: 10000,
GasUsed: 0,
BTMValue: 0,
},
{
input: &GasState{
+ GasLeft: -10000,
+ GasUsed: 0,
+ BTMValue: 0,
+ },
+ output: &GasState{
+ GasLeft: -10000,
+ GasUsed: 0,
+ BTMValue: 0,
+ },
+ f: func(input *GasState) error {
+ return input.updateUsage(math.MaxInt64)
+ },
+ err: ErrGasCalculate,
+ },
+ {
+ input: &GasState{
GasLeft: 1000,
GasUsed: 10,
StorageGas: 1000,
}
}
+// TestCoinbase test the coinbase transaction is valid (txtest#1016)
func TestCoinbase(t *testing.T) {
cp, _ := vmutil.DefaultCoinbaseProgram()
retire, _ := vmutil.RetireProgram([]byte{})
}
+// TestTimeRange test the checkTimeRange function (txtest#1004)
func TestTimeRange(t *testing.T) {
cases := []struct {
timeRange uint64
func TestStandardTx(t *testing.T) {
fixture := sample(t, nil)
tx := types.NewTx(*fixture.tx).Tx
-
+
cases := []struct {
desc string
f func()
}
}
+func TestValidateTxVersion(t *testing.T) {
+ cases := []struct {
+ desc string
+ block *bc.Block
+ err error
+ }{
+ {
+ desc: "tx version greater than 1 (txtest#1001)",
+ block: &bc.Block{
+ BlockHeader: &bc.BlockHeader{Version: 1},
+ Transactions: []*bc.Tx{
+ {TxHeader: &bc.TxHeader{Version: 2}},
+ },
+ },
+ err: ErrTxVersion,
+ },
+ {
+ desc: "tx version equals 0 (txtest#1002)",
+ block: &bc.Block{
+ BlockHeader: &bc.BlockHeader{Version: 1},
+ Transactions: []*bc.Tx{
+ {TxHeader: &bc.TxHeader{Version: 0}},
+ },
+ },
+ err: ErrTxVersion,
+ },
+ {
+ desc: "tx version equals max uint64 (txtest#1003)",
+ block: &bc.Block{
+ BlockHeader: &bc.BlockHeader{Version: 1},
+ Transactions: []*bc.Tx{
+ {TxHeader: &bc.TxHeader{Version: math.MaxUint64}},
+ },
+ },
+ err: ErrTxVersion,
+ },
+ }
+
+ for i, c := range cases {
+ if _, err := ValidateTx(c.block.Transactions[0], c.block); rootErr(err) != c.err {
+ t.Errorf("case #%d (%s) got error %t, want %t", i, c.desc, err, c.err)
+ }
+ }
+}
+
// A txFixture is returned by sample (below) to produce a sample
// transaction, which takes a separate, optional _input_ txFixture to
// affect the transaction that's built. The components of the
result.issuanceProg = bc.Program{VmVersion: 1, Code: prog}
}
if len(result.issuanceArgs) == 0 {
- result.issuanceArgs = [][]byte{[]byte{2}, []byte{3}}
+ result.issuanceArgs = [][]byte{{2}, {3}}
}
if len(result.assetDef) == 0 {
result.assetDef = []byte{2}
if err != nil {
tb.Fatal(err)
}
- args1 := [][]byte{[]byte{4}, []byte{5}}
+ args1 := [][]byte{{4}, {5}}
cp2, err := vm.Assemble("ADD 13 NUMEQUAL")
if err != nil {
tb.Fatal(err)
}
- args2 := [][]byte{[]byte{6}, []byte{7}}
+ args2 := [][]byte{{6}, {7}}
result.txInputs = []*types.TxInput{
types.NewIssuanceInput([]byte{3}, 10, result.issuanceProg.Code, result.issuanceArgs, result.assetDef),