remove pre compiled for tests
This commit is contained in:
parent
5b561f434d
commit
4704a0a288
@ -116,6 +116,8 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
|
|||||||
price = ethutil.Big(exec["gasPrice"])
|
price = ethutil.Big(exec["gasPrice"])
|
||||||
value = ethutil.Big(exec["value"])
|
value = ethutil.Big(exec["value"])
|
||||||
)
|
)
|
||||||
|
// Reset the pre-compiled contracts for VM tests.
|
||||||
|
vm.Precompiled = make(map[string]*vm.PrecompiledAccount)
|
||||||
|
|
||||||
caller := state.GetOrNewStateObject(from)
|
caller := state.GetOrNewStateObject(from)
|
||||||
|
|
||||||
@ -138,6 +140,9 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
|
|||||||
caddr = FromHex(env["currentCoinbase"])
|
caddr = FromHex(env["currentCoinbase"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Set pre compiled contracts
|
||||||
|
vm.Precompiled = vm.PrecompiledContracts()
|
||||||
|
|
||||||
coinbase := statedb.GetOrNewStateObject(caddr)
|
coinbase := statedb.GetOrNewStateObject(caddr)
|
||||||
coinbase.SetGasPool(ethutil.Big(env["currentGasLimit"]))
|
coinbase.SetGasPool(ethutil.Big(env["currentGasLimit"]))
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
helper.CreateFileTests(t, p, &tests)
|
helper.CreateFileTests(t, p, &tests)
|
||||||
|
|
||||||
for name, test := range tests {
|
for name, test := range tests {
|
||||||
|
//helper.Log.Infoln("Running", name)
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
statedb := state.New(nil, db)
|
statedb := state.New(nil, db)
|
||||||
for addr, account := range test.Pre {
|
for addr, account := range test.Pre {
|
||||||
@ -116,12 +117,6 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
ret, logs, gas, err = helper.RunState(statedb, env, test.Transaction)
|
ret, logs, gas, err = helper.RunState(statedb, env, test.Transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the error if there is one. Error does not mean failing test.
|
|
||||||
// A test fails if err != nil and post params are specified in the test.
|
|
||||||
if err != nil {
|
|
||||||
helper.Log.Infof("%s's: %v\n", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rexp := helper.FromHex(test.Out)
|
rexp := helper.FromHex(test.Out)
|
||||||
if bytes.Compare(rexp, ret) != 0 {
|
if bytes.Compare(rexp, ret) != 0 {
|
||||||
t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
|
t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
|
||||||
@ -129,10 +124,14 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
|
|
||||||
if isVmTest {
|
if isVmTest {
|
||||||
if len(test.Gas) == 0 && err == nil {
|
if len(test.Gas) == 0 && err == nil {
|
||||||
|
// Log VM err
|
||||||
|
helper.Log.Infof("%s's: %v\n", name, err)
|
||||||
t.Errorf("%s's gas unspecified, indicating an error. VM returned (incorrectly) successfull", name)
|
t.Errorf("%s's gas unspecified, indicating an error. VM returned (incorrectly) successfull", name)
|
||||||
} else {
|
} else {
|
||||||
gexp := ethutil.Big(test.Gas)
|
gexp := ethutil.Big(test.Gas)
|
||||||
if gexp.Cmp(gas) != 0 {
|
if gexp.Cmp(gas) != 0 {
|
||||||
|
// Log VM err
|
||||||
|
helper.Log.Infof("%s's: %v\n", name, err)
|
||||||
t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
|
t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,32 +20,37 @@ func (self PrecompiledAccount) Call(in []byte) []byte {
|
|||||||
return self.fn(in)
|
return self.fn(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
var Precompiled = map[string]*PrecompiledAccount{
|
var Precompiled = PrecompiledContracts()
|
||||||
// ECRECOVER
|
|
||||||
string(ethutil.LeftPadBytes([]byte{1}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
|
||||||
return GasEcrecover
|
|
||||||
}, ecrecoverFunc},
|
|
||||||
|
|
||||||
// SHA256
|
// XXX Could set directly. Testing requires resetting and setting of pre compiled contracts.
|
||||||
string(ethutil.LeftPadBytes([]byte{2}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
func PrecompiledContracts() map[string]*PrecompiledAccount {
|
||||||
n := big.NewInt(int64(l+31)/32 + 1)
|
return map[string]*PrecompiledAccount{
|
||||||
n.Mul(n, GasSha256)
|
// ECRECOVER
|
||||||
return n
|
string(ethutil.LeftPadBytes([]byte{1}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
||||||
}, sha256Func},
|
return GasEcrecover
|
||||||
|
}, ecrecoverFunc},
|
||||||
|
|
||||||
// RIPEMD160
|
// SHA256
|
||||||
string(ethutil.LeftPadBytes([]byte{3}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
string(ethutil.LeftPadBytes([]byte{2}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
||||||
n := big.NewInt(int64(l+31)/32 + 1)
|
n := big.NewInt(int64(l+31)/32 + 1)
|
||||||
n.Mul(n, GasRipemd)
|
n.Mul(n, GasSha256)
|
||||||
return n
|
return n
|
||||||
}, ripemd160Func},
|
}, sha256Func},
|
||||||
|
|
||||||
string(ethutil.LeftPadBytes([]byte{4}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
// RIPEMD160
|
||||||
n := big.NewInt(int64(l+31)/32 + 1)
|
string(ethutil.LeftPadBytes([]byte{3}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
||||||
n.Mul(n, GasMemCpy)
|
n := big.NewInt(int64(l+31)/32 + 1)
|
||||||
|
n.Mul(n, GasRipemd)
|
||||||
|
return n
|
||||||
|
}, ripemd160Func},
|
||||||
|
|
||||||
return n
|
string(ethutil.LeftPadBytes([]byte{4}, 20)): &PrecompiledAccount{func(l int) *big.Int {
|
||||||
}, memCpy},
|
n := big.NewInt(int64(l+31)/32 + 1)
|
||||||
|
n.Mul(n, GasMemCpy)
|
||||||
|
|
||||||
|
return n
|
||||||
|
}, memCpy},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sha256Func(in []byte) []byte {
|
func sha256Func(in []byte) []byte {
|
||||||
|
Loading…
Reference in New Issue
Block a user