fix transaction tests
This commit is contained in:
parent
cb3dddcbed
commit
f7c61f95d4
|
@ -18,6 +18,7 @@ package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
@ -68,7 +69,7 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
|
||||||
if err := tt.validate(); err != nil {
|
if err := tt.validate(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead, isIstanbul, isShanghai bool) (sender common.Address, hash common.Hash, requiredGas uint64, err error) {
|
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, rules *params.Rules) (sender common.Address, hash common.Hash, requiredGas uint64, err error) {
|
||||||
tx := new(types.Transaction)
|
tx := new(types.Transaction)
|
||||||
if err = tx.UnmarshalBinary(rlpData); err != nil {
|
if err = tx.UnmarshalBinary(rlpData); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -77,9 +78,8 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rules := config.Rules(common.Big0, true, 0)
|
|
||||||
// Intrinsic gas
|
// Intrinsic gas
|
||||||
requiredGas, err = tx.IntrinsicGas(&rules)
|
requiredGas, err = tx.IntrinsicGas(rules)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -90,31 +90,32 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
|
||||||
return sender, hash, requiredGas, nil
|
return sender, hash, requiredGas, nil
|
||||||
}
|
}
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name string
|
name string
|
||||||
signer types.Signer
|
signer types.Signer
|
||||||
fork *ttFork
|
fork *ttFork
|
||||||
isHomestead bool
|
|
||||||
isIstanbul bool
|
|
||||||
isShanghai bool
|
|
||||||
}{
|
}{
|
||||||
{"Frontier", types.FrontierSigner{}, tt.Result["Frontier"], false, false, false},
|
{"Frontier", types.FrontierSigner{}, tt.Result["Frontier"]},
|
||||||
{"Homestead", types.HomesteadSigner{}, tt.Result["Homestead"], true, false, false},
|
{"Homestead", types.HomesteadSigner{}, tt.Result["Homestead"]},
|
||||||
{"EIP150", types.HomesteadSigner{}, tt.Result["EIP150"], true, false, false},
|
{"EIP150", types.HomesteadSigner{}, tt.Result["EIP150"]},
|
||||||
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result["EIP158"], true, false, false},
|
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.Result["EIP158"]},
|
||||||
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result["Byzantium"], true, false, false},
|
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Result["Byzantium"]},
|
||||||
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result["Constantinople"], true, false, false},
|
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Result["Constantinople"]},
|
||||||
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result["Istanbul"], true, true, false},
|
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Result["Istanbul"]},
|
||||||
{"Berlin", types.NewEIP2930Signer(config.ChainID), tt.Result["Berlin"], true, true, false},
|
{"Berlin", types.NewEIP2930Signer(config.ChainID), tt.Result["Berlin"]},
|
||||||
{"London", types.NewLondonSigner(config.ChainID), tt.Result["London"], true, true, false},
|
{"London", types.NewLondonSigner(config.ChainID), tt.Result["London"]},
|
||||||
{"Paris", types.NewLondonSigner(config.ChainID), tt.Result["Paris"], true, true, false},
|
{"Paris", types.NewLondonSigner(config.ChainID), tt.Result["Paris"]},
|
||||||
{"Shanghai", types.NewLondonSigner(config.ChainID), tt.Result["Shanghai"], true, true, true},
|
{"Shanghai", types.NewLondonSigner(config.ChainID), tt.Result["Shanghai"]},
|
||||||
{"Cancun", types.NewCancunSigner(config.ChainID), tt.Result["Cancun"], true, true, true},
|
{"Cancun", types.NewCancunSigner(config.ChainID), tt.Result["Cancun"]},
|
||||||
{"Prague", types.NewPragueSigner(config.ChainID), tt.Result["Prague"], true, true, true},
|
{"Prague", types.NewPragueSigner(config.ChainID), tt.Result["Prague"]},
|
||||||
} {
|
} {
|
||||||
if testcase.fork == nil {
|
if testcase.fork == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sender, hash, gas, err := validateTx(tt.Txbytes, testcase.signer, testcase.isHomestead, testcase.isIstanbul, testcase.isShanghai)
|
rules, err := getRules(config, testcase.name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sender, hash, gas, err := validateTx(tt.Txbytes, testcase.signer, &rules)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if testcase.fork.Hash != nil {
|
if testcase.fork.Hash != nil {
|
||||||
return fmt.Errorf("unexpected error: %v", err)
|
return fmt.Errorf("unexpected error: %v", err)
|
||||||
|
@ -139,3 +140,35 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRules(config *params.ChainConfig, fork string) (params.Rules, error) {
|
||||||
|
switch fork {
|
||||||
|
case "Frontier":
|
||||||
|
return config.Rules(new(big.Int), false, 0), nil
|
||||||
|
case "Homestead":
|
||||||
|
return config.Rules(config.HomesteadBlock, false, 0), nil
|
||||||
|
case "EIP150":
|
||||||
|
return config.Rules(config.EIP150Block, false, 0), nil
|
||||||
|
case "EIP158":
|
||||||
|
return config.Rules(config.EIP158Block, false, 0), nil
|
||||||
|
case "Byzantium":
|
||||||
|
return config.Rules(config.ByzantiumBlock, false, 0), nil
|
||||||
|
case "Constantinople":
|
||||||
|
return config.Rules(config.ConstantinopleBlock, false, 0), nil
|
||||||
|
case "Istanbul":
|
||||||
|
return config.Rules(config.IstanbulBlock, false, 0), nil
|
||||||
|
case "Berlin":
|
||||||
|
return config.Rules(config.BerlinBlock, false, 0), nil
|
||||||
|
case "London":
|
||||||
|
return config.Rules(config.LondonBlock, false, 0), nil
|
||||||
|
case "Paris":
|
||||||
|
return config.Rules(config.LondonBlock, true, 0), nil
|
||||||
|
case "Shanghai":
|
||||||
|
return config.Rules(config.LondonBlock, true, *config.ShanghaiTime), nil
|
||||||
|
case "Cancun":
|
||||||
|
return config.Rules(config.LondonBlock, true, *config.CancunTime), nil
|
||||||
|
case "Prague":
|
||||||
|
return config.Rules(config.LondonBlock, true, *config.PragueTime), nil
|
||||||
|
}
|
||||||
|
return params.Rules{}, UnsupportedForkError{Name: fork}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue