Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4704a0a2
Commit
4704a0a2
authored
Jan 13, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove pre compiled for tests
parent
5b561f43
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
32 deletions
+41
-32
vm.go
tests/helper/vm.go
+5
-0
gh_test.go
tests/vm/gh_test.go
+5
-6
address.go
vm/address.go
+31
-26
No files found.
tests/helper/vm.go
View file @
4704a0a2
...
...
@@ -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"
]))
...
...
tests/vm/gh_test.go
View file @
4704a0a2
...
...
@@ -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
)
}
}
...
...
vm/address.go
View file @
4704a0a2
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment