"github.com/bytom/protocol/vm"
)
+const ruleAA = 142500
+
// validate transaction error
var (
ErrTxVersion = errors.New("invalid transaction version")
ErrWrongTransactionSize = errors.New("invalid transaction size")
ErrBadTimeRange = errors.New("invalid transaction time range")
+ ErrEmptyInputIDs = errors.New("got the empty InputIDs")
ErrNotStandardTx = errors.New("not standard transaction")
ErrWrongCoinbaseTransaction = errors.New("wrong coinbase transaction")
ErrWrongCoinbaseAsset = errors.New("wrong coinbase assetID")
return nil
}
-func checkStandardTx(tx *bc.Tx) error {
+func checkStandardTx(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 {
if err := checkTimeRange(tx, block); err != nil {
return gasStatus, err
}
- if err := checkStandardTx(tx); err != nil {
+ if err := checkStandardTx(tx, block.Height); err != nil {
return gasStatus, err
}
}
}
+func TestRuleAA(t *testing.T) {
+ testData := "070100040161015f9bc47dda88eee18c7433340c16e054cabee4318a8d638e873be19e979df81dc7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0e3f9f5c80e01011600147c7662d92bd5e77454736f94731c60a6e9cbc69f6302404a17a5995b8163ee448719b462a5694b22a35522dd9883333fd462cc3d0aabf049445c5cbb911a40e1906a5bea99b23b1a79e215eeb1a818d8b1dd27e06f3004200530c4bc9dd3cbf679fec6d824ce5c37b0c8dab88b67bcae3b000924b7dce9940160015ee334d4fe18398f0232d2aca7050388ce4ee5ae82c8148d7f0cea748438b65135ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80ace6842001011600147c7662d92bd5e77454736f94731c60a6e9cbc69f6302404a17a5995b8163ee448719b462a5694b22a35522dd9883333fd462cc3d0aabf049445c5cbb911a40e1906a5bea99b23b1a79e215eeb1a818d8b1dd27e06f3004200530c4bc9dd3cbf679fec6d824ce5c37b0c8dab88b67bcae3b000924b7dce9940161015f9bc47dda88eee18c7433340c16e054cabee4318a8d638e873be19e979df81dc7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0e3f9f5c80e01011600147c7662d92bd5e77454736f94731c60a6e9cbc69f63024062c29b20941e7f762c3afae232f61d8dac1c544825931e391408c6715c408ef69f494a1b3b61ce380ddee0c8b18ecac2b46ef96a62eebb6ec40f9f545410870a200530c4bc9dd3cbf679fec6d824ce5c37b0c8dab88b67bcae3b000924b7dce9940160015ee334d4fe18398f0232d2aca7050388ce4ee5ae82c8148d7f0cea748438b65135ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80ace6842001011600147c7662d92bd5e77454736f94731c60a6e9cbc69f630240e443d66c75b4d5fa71676d60b0b067e6941f06349f31e5f73a7d51a73f5797632b2e01e8584cd1c8730dc16df075866b0c796bd7870182e2da4b37188208fe02200530c4bc9dd3cbf679fec6d824ce5c37b0c8dab88b67bcae3b000924b7dce99402013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa08ba3fae80e01160014aac0345165045e612b3d7363f39a372bead80ce700013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08fe0fae80e01160014aac0345165045e612b3d7363f39a372bead80ce700"
+ tx := types.Tx{}
+ if err := tx.UnmarshalText([]byte(testData)); err != nil {
+ t.Errorf("fail on unmarshal txData: %s", err)
+ }
+
+ cases := []struct {
+ block *bc.Block
+ GasValid bool
+ err error
+ }{
+ {
+ block: &bc.Block{
+ BlockHeader: &bc.BlockHeader{
+ Height: ruleAA - 1,
+ },
+ },
+ GasValid: true,
+ err: ErrMismatchedPosition,
+ },
+ {
+ block: &bc.Block{
+ BlockHeader: &bc.BlockHeader{
+ Height: ruleAA,
+ },
+ },
+ GasValid: false,
+ err: ErrEmptyInputIDs,
+ },
+ }
+
+ for i, c := range cases {
+ gasStatus, err := ValidateTx(tx.Tx, c.block)
+ if rootErr(err) != c.err {
+ t.Errorf("#%d got error %s, want %s", i, err, c.err)
+ }
+ if c.GasValid != gasStatus.GasValid {
+ t.Errorf("#%d got GasValid %t, want %t", i, gasStatus.GasValid, c.GasValid)
+ }
+ }
+
+}
+
func TestTimeRange(t *testing.T) {
cases := []struct {
timeRange uint64