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
94489b22
Commit
94489b22
authored
Apr 06, 2015
by
zsfelfoldi
Committed by
zelig
Apr 19, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
s
parent
e2d333d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
52 deletions
+81
-52
docserver.go
common/docserver/docserver.go
+5
-1
natspec_e2e_test.go
common/natspec/natspec_e2e_test.go
+68
-45
resolver.go
common/resolver/resolver.go
+6
-5
contracts.go
core/contracts.go
+2
-1
No files found.
common/docserver/docserver.go
View file @
94489b22
...
...
@@ -55,7 +55,11 @@ func (self *DocServer) RegisterProtocols(schemes map[string]func(*DocServer) htt
func
(
self
*
DocServer
)
GetAuthContent
(
uri
string
,
hash
common
.
Hash
)
(
content
[]
byte
,
err
error
)
{
// retrieve content
resp
,
err
:=
self
.
Client
()
.
Get
(
uri
)
defer
resp
.
Body
.
Close
()
defer
func
()
{
if
resp
!=
nil
{
resp
.
Body
.
Close
()
}
}()
if
err
!=
nil
{
return
}
...
...
common/natspec/natspec_e2e_test.go
View file @
94489b22
...
...
@@ -9,8 +9,10 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/docserver"
"github.com/ethereum/go-ethereum/common/resolver"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
//"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
...
...
@@ -18,9 +20,12 @@ import (
)
type
testFrontend
struct
{
t
*
testing
.
T
ethereum
*
eth
.
Ethereum
xeth
*
xe
.
XEth
t
*
testing
.
T
ethereum
*
eth
.
Ethereum
xeth
*
xe
.
XEth
stateDb
*
state
.
StateDB
coinbase
string
lastConfirm
string
}
func
(
f
*
testFrontend
)
UnlockAccount
(
acc
[]
byte
)
bool
{
...
...
@@ -29,11 +34,14 @@ func (f *testFrontend) UnlockAccount(acc []byte) bool {
return
true
}
func
(
testFrontend
)
ConfirmTransaction
(
message
string
)
bool
{
return
true
}
func
(
f
*
testFrontend
)
ConfirmTransaction
(
message
string
)
bool
{
f
.
lastConfirm
=
message
return
true
}
var
port
=
30300
func
test
JEthRE
(
t
*
testing
.
T
)
(
ethereum
*
eth
.
Ethereum
,
err
error
)
{
func
test
Eth
(
t
*
testing
.
T
)
(
ethereum
*
eth
.
Ethereum
,
err
error
)
{
os
.
RemoveAll
(
"/tmp/eth/"
)
err
=
os
.
MkdirAll
(
"/tmp/eth/keys/e273f01c99144c438695e10f24926dc1f9fbf62d/"
,
os
.
ModePerm
)
if
err
!=
nil
{
...
...
@@ -66,6 +74,41 @@ func testJEthRE(t *testing.T) (ethereum *eth.Ethereum, err error) {
return
}
func
testInit
(
t
*
testing
.
T
)
(
self
*
testFrontend
)
{
ethereum
,
err
:=
testEth
(
t
)
if
err
!=
nil
{
t
.
Errorf
(
"error creating jsre, got %v"
,
err
)
return
}
err
=
ethereum
.
Start
()
if
err
!=
nil
{
t
.
Errorf
(
"error starting ethereum: %v"
,
err
)
return
}
self
=
&
testFrontend
{
t
:
t
,
ethereum
:
ethereum
}
self
.
xeth
=
xe
.
New
(
ethereum
,
self
)
addr
:=
self
.
xeth
.
Coinbase
()
self
.
coinbase
=
addr
if
addr
!=
"0x"
+
core
.
TestAccount
{
t
.
Errorf
(
"CoinBase %v does not match TestAccount 0x%v"
,
addr
,
core
.
TestAccount
)
}
t
.
Logf
(
"CoinBase is %v"
,
addr
)
balance
:=
self
.
xeth
.
BalanceAt
(
core
.
TestAccount
)
if
balance
!=
core
.
TestBalance
{
t
.
Errorf
(
"Balance %v does not match TestBalance %v"
,
balance
,
core
.
TestBalance
)
}
t
.
Logf
(
"Balance is %v"
,
balance
)
self
.
stateDb
=
self
.
ethereum
.
ChainManager
()
.
State
()
.
Copy
()
return
}
func
(
self
*
testFrontend
)
insertTx
(
addr
,
contract
,
fnsig
string
,
args
[]
string
)
{
hash
:=
common
.
Bytes2Hex
(
crypto
.
Sha3
([]
byte
(
fnsig
)))
...
...
@@ -77,67 +120,47 @@ func (self *testFrontend) insertTx(addr, contract, fnsig string, args []string)
self
.
xeth
.
Transact
(
addr
,
contract
,
"100000000000"
,
"100000"
,
"100000"
,
data
)
cb
:=
common
.
HexToAddress
(
addr
)
stateDb
:=
self
.
ethereum
.
ChainManager
()
.
State
()
.
Copy
()
coinbase
:=
stateDb
.
GetStateObject
(
cb
)
coinbase
:=
s
elf
.
s
tateDb
.
GetStateObject
(
cb
)
coinbase
.
SetGasPool
(
big
.
NewInt
(
100000
))
block
:=
self
.
ethereum
.
ChainManager
()
.
NewBlock
(
cb
)
txs
:=
self
.
ethereum
.
TxPool
()
.
GetTransactions
()
tx
:=
txs
[
0
]
_
,
gas
,
err
:=
core
.
ApplyMessage
(
core
.
NewEnv
(
stateDb
,
self
.
ethereum
.
ChainManager
(),
tx
,
block
),
tx
,
coinbase
)
_
,
gas
,
err
:=
core
.
ApplyMessage
(
core
.
NewEnv
(
s
elf
.
s
tateDb
,
self
.
ethereum
.
ChainManager
(),
tx
,
block
),
tx
,
coinbase
)
self
.
t
.
Logf
(
"ApplyMessage: gas %v err %v"
,
gas
,
err
)
self
.
ethereum
.
TxPool
()
.
RemoveSet
(
txs
)
self
.
xeth
=
self
.
xeth
.
WithState
(
stateDb
)
self
.
xeth
=
self
.
xeth
.
WithState
(
s
elf
.
s
tateDb
)
}
func
TestNatspecE2E
(
t
*
testing
.
T
)
{
ethereum
,
err
:=
testJEthRE
(
t
)
if
err
!=
nil
{
t
.
Errorf
(
"error creating jsre, got %v"
,
err
)
return
}
err
=
ethereum
.
Start
()
if
err
!=
nil
{
t
.
Errorf
(
"error starting ethereum: %v"
,
err
)
return
}
defer
ethereum
.
Stop
()
frontend
:=
&
testFrontend
{
t
:
t
,
ethereum
:
ethereum
}
frontend
.
xeth
=
xe
.
New
(
ethereum
,
frontend
)
func
(
self
*
testFrontend
)
registerURL
(
hash
common
.
Hash
,
url
string
)
{
hashHex
:=
common
.
Bytes2Hex
(
hash
[
:
])
urlHex
:=
common
.
Bytes2Hex
([]
byte
(
url
))
self
.
insertTx
(
self
.
coinbase
,
core
.
ContractAddrURLhint
,
"register(bytes32,bytes32)"
,
[]
string
{
hashHex
,
urlHex
})
}
addr
:=
frontend
.
xeth
.
Coinbase
()
if
addr
!=
"0x"
+
core
.
TestAccount
{
t
.
Errorf
(
"CoinBase %v does not match TestAccount 0x%v"
,
addr
,
core
.
TestAccount
)
}
t
.
Logf
(
"CoinBase is %v"
,
addr
)
func
(
self
*
testFrontend
)
testResolver
()
*
resolver
.
Resolver
{
return
resolver
.
New
(
self
.
xeth
,
resolver
.
URLHintContractAddress
,
resolver
.
NameRegContractAddress
)
}
balance
:=
frontend
.
xeth
.
BalanceAt
(
core
.
TestAccount
)
if
balance
!=
core
.
TestBalance
{
t
.
Errorf
(
"Balance %v does not match TestBalance %v"
,
balance
,
core
.
TestBalance
)
}
t
.
Logf
(
"Balance is %v"
,
balance
)
func
TestNatspecE2E
(
t
*
testing
.
T
)
{
frontend
.
insertTx
(
addr
,
core
.
ContractAddrURLhint
,
"register(bytes32,bytes32)"
,
[]
string
{
"1234"
,
"5678"
})
tf
:=
testInit
(
t
)
defer
tf
.
ethereum
.
Stop
()
t
.
Logf
(
"testcnt: %v"
,
frontend
.
xeth
.
StorageAt
(
core
.
ContractAddrURLhint
,
"00"
)
)
ds
,
_
:=
docserver
.
New
(
"/tmp/"
)
for
i
:=
0
;
i
<
10
;
i
++
{
t
.
Logf
(
"storage[%v] = %v"
,
i
,
frontend
.
xeth
.
StorageAt
(
"0x"
+
core
.
ContractAddrURLhint
,
fmt
.
Sprintf
(
"%v"
,
i
))
)
}
chash
:=
common
.
BytesToHash
(
crypto
.
Sha3
([]
byte
(
"kutyafasza"
)))
tf
.
registerURL
(
chash
,
"file:///test.content"
)
tf
.
registerURL
(
chash
,
"kf"
)
rsv
:=
resolver
.
New
(
frontend
.
xeth
,
resolver
.
URLHintContractAddress
,
resolver
.
NameRegContractAddress
)
url
,
err2
:=
rsv
.
ContentHashToUrl
(
common
.
BytesToHash
(
common
.
Hex2BytesFixed
(
"1234"
,
32
)))
url
,
err2
:=
tf
.
testResolver
()
.
ContentHashToUrl
(
chash
)
t
.
Logf
(
"URL: %v err: %v"
,
url
,
err2
)
/*
This test is unfinished; first we need to see the result of a
transaction in the contract storage (testcnt should be 1).
*/
ds
.
GetAuthContent
(
url
,
chash
)
}
common/resolver/resolver.go
View file @
94489b22
...
...
@@ -39,7 +39,7 @@ func New(eth Backend, uhca, nrca string) *Resolver {
func
(
self
*
Resolver
)
NameToContentHash
(
name
string
)
(
chash
common
.
Hash
,
err
error
)
{
// look up in nameReg
key
:=
storageAddress
(
1
,
common
.
Hex2BytesFixed
(
name
,
32
))
hash
:=
self
.
backend
.
StorageAt
(
self
.
nameRegContractAddress
,
key
)
hash
:=
self
.
backend
.
StorageAt
(
"0x"
+
self
.
nameRegContractAddress
,
key
)
copy
(
chash
[
:
],
common
.
Hex2Bytes
(
hash
))
return
}
...
...
@@ -47,7 +47,8 @@ func (self *Resolver) NameToContentHash(name string) (chash common.Hash, err err
func
(
self
*
Resolver
)
ContentHashToUrl
(
chash
common
.
Hash
)
(
uri
string
,
err
error
)
{
// look up in nameReg
key
:=
storageAddress
(
2
,
chash
[
:
])
uri
=
string
(
common
.
Hex2Bytes
(
self
.
backend
.
StorageAt
(
self
.
urlHintContractAddress
,
key
)))
hex
:=
self
.
backend
.
StorageAt
(
"0x"
+
self
.
urlHintContractAddress
,
key
)
uri
=
string
(
common
.
Hex2Bytes
(
hex
[
2
:
]))
l
:=
len
(
uri
)
for
(
l
>
0
)
&&
(
uri
[
l
-
1
]
==
0
)
{
l
--
...
...
@@ -72,7 +73,7 @@ func (self *Resolver) NameToUrl(name string) (uri string, hash common.Hash, err
func
storageAddress
(
varidx
uint32
,
key
[]
byte
)
string
{
data
:=
make
([]
byte
,
64
)
binary
.
BigEndian
.
PutUint32
(
data
[
28
:
32
],
varidx
)
copy
(
data
[
32
:
64
],
key
[
0
:
32
])
return
common
.
Bytes2Hex
(
crypto
.
Sha3
(
data
))
binary
.
BigEndian
.
PutUint32
(
data
[
60
:
64
],
varidx
)
copy
(
data
[
0
:
32
],
key
[
0
:
32
])
return
"0x"
+
common
.
Bytes2Hex
(
crypto
.
Sha3
(
data
))
}
core/contracts.go
View file @
94489b22
...
...
@@ -2,7 +2,8 @@ package core
const
(
// built-in contracts address and code
ContractAddrURLhint
=
"0000000000000000000000000000000000000008"
ContractCodeURLhint
=
"0x60bd80600c6000396000f30060003560e060020a900480632f92673214601557005b60216004356024356027565b60006000f35b6000805490816001019055506001600083815260200190815260200160002054600160a060020a0316600014806081575033600160a060020a03166001600084815260200190815260200160002054600160a060020a0316145b60885760b9565b3360016000848152602001908152602001600020819055508060026000848152602001908152602001600020819055505b505056"
//ContractCodeURLhint = "0x60bd80600c6000396000f30060003560e060020a900480632f92673214601557005b60216004356024356027565b60006000f35b6000805490816001019055506001600083815260200190815260200160002054600160a060020a0316600014806081575033600160a060020a03166001600084815260200190815260200160002054600160a060020a0316145b60885760b9565b3360016000848152602001908152602001600020819055508060026000848152602001908152602001600020819055505b505056"
ContractCodeURLhint
=
"0x60003560e060020a900480632f92673214601557005b60216004356024356027565b60006000f35b6000805490816001019055506001600083815260200190815260200160002054600160a060020a0316600014806081575033600160a060020a03166001600084815260200190815260200160002054600160a060020a0316145b60885760b9565b3360016000848152602001908152602001600020819055508060026000848152602001908152602001600020819055505b505056"
//"0x60b180600c6000396000f30060003560e060020a900480632f92673214601557005b60216004356024356027565b60006000f35b6000600083815260200190815260200160002054600160a060020a0316600014806075575033600160a060020a03166000600084815260200190815260200160002054600160a060020a0316145b607c5760ad565b3360006000848152602001908152602001600020819055508060016000848152602001908152602001600020819055505b505056"
/*
contract URLhint {
...
...
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