diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-13 17:30:52 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-13 17:30:52 +0800 |
commit | 4704a0a288af89795e251db98eb253de117ff031 (patch) | |
tree | d6e975352b20a3c23a6af453c45b87b1e2d976ae | |
parent | 5b561f434d888b750bb9b29726a86d664ac89660 (diff) | |
download | dexon-4704a0a288af89795e251db98eb253de117ff031.tar.gz dexon-4704a0a288af89795e251db98eb253de117ff031.tar.zst dexon-4704a0a288af89795e251db98eb253de117ff031.zip |
remove pre compiled for tests
-rw-r--r-- | tests/helper/vm.go | 5 | ||||
-rw-r--r-- | tests/vm/gh_test.go | 11 | ||||
-rw-r--r-- | vm/address.go | 57 |
3 files changed, 41 insertions, 32 deletions
diff --git a/tests/helper/vm.go b/tests/helper/vm.go index 2f3ec30f7..7c33839cf 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -116,6 +116,8 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log price = ethutil.Big(exec["gasPrice"]) value = ethutil.Big(exec["value"]) ) + // Reset the pre-compiled contracts for VM tests. + vm.Precompiled = make(map[string]*vm.PrecompiledAccount) caller := state.GetOrNewStateObject(from) @@ -138,6 +140,9 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state. caddr = FromHex(env["currentCoinbase"]) ) + // Set pre compiled contracts + vm.Precompiled = vm.PrecompiledContracts() + coinbase := statedb.GetOrNewStateObject(caddr) coinbase.SetGasPool(ethutil.Big(env["currentGasLimit"])) diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 699225e90..7b41411de 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -79,6 +79,7 @@ func RunVmTest(p string, t *testing.T) { helper.CreateFileTests(t, p, &tests) for name, test := range tests { + //helper.Log.Infoln("Running", name) db, _ := ethdb.NewMemDatabase() statedb := state.New(nil, db) 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) } - // 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) if bytes.Compare(rexp, ret) != 0 { 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 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) } else { gexp := ethutil.Big(test.Gas) 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) } } diff --git a/vm/address.go b/vm/address.go index be4284421..1c9369ab7 100644 --- a/vm/address.go +++ b/vm/address.go @@ -20,32 +20,37 @@ func (self PrecompiledAccount) Call(in []byte) []byte { return self.fn(in) } -var Precompiled = map[string]*PrecompiledAccount{ - // ECRECOVER - string(ethutil.LeftPadBytes([]byte{1}, 20)): &PrecompiledAccount{func(l int) *big.Int { - return GasEcrecover - }, ecrecoverFunc}, - - // SHA256 - string(ethutil.LeftPadBytes([]byte{2}, 20)): &PrecompiledAccount{func(l int) *big.Int { - n := big.NewInt(int64(l+31)/32 + 1) - n.Mul(n, GasSha256) - return n - }, sha256Func}, - - // RIPEMD160 - string(ethutil.LeftPadBytes([]byte{3}, 20)): &PrecompiledAccount{func(l int) *big.Int { - n := big.NewInt(int64(l+31)/32 + 1) - n.Mul(n, GasRipemd) - return n - }, ripemd160Func}, - - string(ethutil.LeftPadBytes([]byte{4}, 20)): &PrecompiledAccount{func(l int) *big.Int { - n := big.NewInt(int64(l+31)/32 + 1) - n.Mul(n, GasMemCpy) - - return n - }, memCpy}, +var Precompiled = PrecompiledContracts() + +// XXX Could set directly. Testing requires resetting and setting of pre compiled contracts. +func PrecompiledContracts() map[string]*PrecompiledAccount { + return map[string]*PrecompiledAccount{ + // ECRECOVER + string(ethutil.LeftPadBytes([]byte{1}, 20)): &PrecompiledAccount{func(l int) *big.Int { + return GasEcrecover + }, ecrecoverFunc}, + + // SHA256 + string(ethutil.LeftPadBytes([]byte{2}, 20)): &PrecompiledAccount{func(l int) *big.Int { + n := big.NewInt(int64(l+31)/32 + 1) + n.Mul(n, GasSha256) + return n + }, sha256Func}, + + // RIPEMD160 + string(ethutil.LeftPadBytes([]byte{3}, 20)): &PrecompiledAccount{func(l int) *big.Int { + n := big.NewInt(int64(l+31)/32 + 1) + n.Mul(n, GasRipemd) + return n + }, ripemd160Func}, + + string(ethutil.LeftPadBytes([]byte{4}, 20)): &PrecompiledAccount{func(l int) *big.Int { + n := big.NewInt(int64(l+31)/32 + 1) + n.Mul(n, GasMemCpy) + + return n + }, memCpy}, + } } func sha256Func(in []byte) []byte { |