aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzsfelfoldi <zsfelfoldi@gmail.com>2015-04-14 21:20:52 +0800
committerzelig <viktor.tron@gmail.com>2015-04-20 03:57:49 +0800
commitdba2367157fc4ad7947ee1632dbe76d6a110f49f (patch)
tree5d50f5f68a0ccc689ff8adf606359c949a3eab16
parentf255336c2cf989be52502f0f384da7c2d44d2109 (diff)
downloadgo-tangerine-dba2367157fc4ad7947ee1632dbe76d6a110f49f.tar.gz
go-tangerine-dba2367157fc4ad7947ee1632dbe76d6a110f49f.tar.zst
go-tangerine-dba2367157fc4ad7947ee1632dbe76d6a110f49f.zip
NatSpec contracts are now not in the genesis block but added by the test
-rw-r--r--common/natspec/natspec_e2e_test.go41
-rw-r--r--common/resolver/resolver.go24
-rw-r--r--core/contracts.go44
-rw-r--r--core/genesis.go1
4 files changed, 45 insertions, 65 deletions
diff --git a/common/natspec/natspec_e2e_test.go b/common/natspec/natspec_e2e_test.go
index 4a0b82a43..204da7899 100644
--- a/common/natspec/natspec_e2e_test.go
+++ b/common/natspec/natspec_e2e_test.go
@@ -13,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/common/natspec"
"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/state"
//"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
@@ -27,14 +27,16 @@ type testFrontend struct {
xeth *xe.XEth
api *rpc.EthereumApi
coinbase string
+ stateDb *state.StateDB
+ txc uint64
lastConfirm string
makeNatSpec bool
}
const testNotice = "Register key `utils.toHex(_key)` <- content `utils.toHex(_content)`"
const testExpNotice = "Register key 0xadd1a7d961cff0242089674ec2ef6fca671ab15e1fe80e38859fc815b98d88ab <- content 0xc00d5bcc872e17813df6ec5c646bb281a6e2d3b454c2c400c78192adf3344af9"
-const testExpNotice2 = `About to submit transaction (NatSpec notice error "abi key %!x(MISSING) does not match any method %!v(MISSING)"): {"id":6,"jsonrpc":"2.0","method":"eth_transact","params":[{"from":"0xe273f01c99144c438695e10f24926dc1f9fbf62d","to":"0x0000000000000000000000000000000000000009","value":"100000000000","gas":"100000","gasPrice":"100000","data":"0x31e12c20"}]}`
-const testExpNotice3 = `About to submit transaction (no NatSpec info found for contract): {"id":6,"jsonrpc":"2.0","method":"eth_transact","params":[{"from":"0xe273f01c99144c438695e10f24926dc1f9fbf62d","to":"0x0000000000000000000000000000000000000008","value":"100000000000","gas":"100000","gasPrice":"100000","data":"0xd66d6c10c00d5bcc872e17813df6ec5c646bb281a6e2d3b454c2c400c78192adf3344af900000000000000000000000066696c653a2f2f2f746573742e636f6e74656e74"}]}`
+const testExpNotice2 = `About to submit transaction (NatSpec notice error "abi key %!x(MISSING) does not match any method %!v(MISSING)"): {"id":6,"jsonrpc":"2.0","method":"eth_transact","params":[{"from":"0xe273f01c99144c438695e10f24926dc1f9fbf62d","to":"0xb737b91f8e95cf756766fc7c62c9a8ff58470381","value":"100000000000","gas":"100000","gasPrice":"100000","data":"0x31e12c20"}]}`
+const testExpNotice3 = `About to submit transaction (no NatSpec info found for contract): {"id":6,"jsonrpc":"2.0","method":"eth_transact","params":[{"from":"0xe273f01c99144c438695e10f24926dc1f9fbf62d","to":"0x8b839ad85686967a4f418eccc81962eaee314ac3","value":"100000000000","gas":"100000","gasPrice":"100000","data":"0xd66d6c10c00d5bcc872e17813df6ec5c646bb281a6e2d3b454c2c400c78192adf3344af900000000000000000000000066696c653a2f2f2f746573742e636f6e74656e74"}]}`
const testUserDoc = `
{
@@ -161,6 +163,8 @@ func testInit(t *testing.T) (self *testFrontend) {
}*/
t.Logf("Balance is %v", balance)
+ self.stateDb = self.ethereum.ChainManager().State().Copy()
+
return
}
@@ -201,43 +205,45 @@ func (self *testFrontend) insertTx(addr, contract, fnsig string, args []string)
}
//self.xeth.Transact(addr, contract, "100000000000", "100000", "100000", data)
+
}
func (self *testFrontend) applyTxs() {
cb := common.HexToAddress(self.coinbase)
- stateDb := self.ethereum.ChainManager().State().Copy()
block := self.ethereum.ChainManager().NewBlock(cb)
- coinbase := stateDb.GetStateObject(cb)
- coinbase.SetGasPool(big.NewInt(1000000))
+ coinbase := self.stateDb.GetStateObject(cb)
+ coinbase.SetGasPool(big.NewInt(10000000))
txs := self.ethereum.TxPool().GetTransactions()
for i := 0; i < len(txs); i++ {
for _, tx := range txs {
- if tx.Nonce() == uint64(i) {
- _, gas, err := core.ApplyMessage(core.NewEnv(stateDb, self.ethereum.ChainManager(), tx, block), tx, coinbase)
+ //self.t.Logf("%v %v %v", i, tx.Nonce(), self.txc)
+ if tx.Nonce() == self.txc {
+ _, gas, err := core.ApplyMessage(core.NewEnv(self.stateDb, self.ethereum.ChainManager(), tx, block), tx, coinbase)
//self.ethereum.TxPool().RemoveSet([]*types.Transaction{tx})
self.t.Logf("ApplyMessage: gas %v err %v", gas, err)
+ self.txc++
}
}
}
- self.ethereum.TxPool().RemoveSet(txs)
- self.xeth = self.xeth.WithState(stateDb)
+ //self.ethereum.TxPool().RemoveSet(txs)
+ self.xeth = self.xeth.WithState(self.stateDb)
}
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(uint256,uint256)", []string{hashHex, urlHex})
+ self.insertTx(self.coinbase, resolver.URLHintContractAddress, "register(uint256,uint256)", []string{hashHex, urlHex})
}
func (self *testFrontend) setOwner() {
- self.insertTx(self.coinbase, core.ContractAddrHashReg, "setowner()", []string{})
+ self.insertTx(self.coinbase, resolver.HashRegContractAddress, "setowner()", []string{})
- /*owner := self.xeth.StorageAt("0x"+core.ContractAddrHashReg, "0x0000000000000000000000000000000000000000000000000000000000000000")
+ /*owner := self.xeth.StorageAt("0x"+resolver.HashRegContractAddress, "0x0000000000000000000000000000000000000000000000000000000000000000")
self.t.Logf("owner = %v", owner)
if owner != self.coinbase {
self.t.Errorf("setowner() unsuccessful, owner != coinbase")
@@ -248,7 +254,7 @@ func (self *testFrontend) registerNatSpec(codehash, dochash common.Hash) {
codeHex := common.Bytes2Hex(codehash[:])
docHex := common.Bytes2Hex(dochash[:])
- self.insertTx(self.coinbase, core.ContractAddrHashReg, "register(uint256,uint256)", []string{codeHex, docHex})
+ self.insertTx(self.coinbase, resolver.HashRegContractAddress, "register(uint256,uint256)", []string{codeHex, docHex})
}
func (self *testFrontend) testResolver() *resolver.Resolver {
@@ -260,10 +266,15 @@ func TestNatspecE2E(t *testing.T) {
tf := testInit(t)
defer tf.ethereum.Stop()
+ resolver.CreateContracts(tf.xeth, core.TestAccount)
+ t.Logf("URLHint contract registered at %v", resolver.URLHintContractAddress)
+ t.Logf("HashReg contract registered at %v", resolver.HashRegContractAddress)
+ tf.applyTxs()
+
ioutil.WriteFile("/tmp/test.content", []byte(testDocs), os.ModePerm)
dochash := common.BytesToHash(crypto.Sha3([]byte(testDocs)))
- codehex := tf.xeth.CodeAt(core.ContractAddrHashReg)
+ codehex := tf.xeth.CodeAt(resolver.HashRegContractAddress)
codehash := common.BytesToHash(crypto.Sha3(common.Hex2Bytes(codehex[2:])))
tf.setOwner()
diff --git a/common/resolver/resolver.go b/common/resolver/resolver.go
index 2858a049d..45afb2971 100644
--- a/common/resolver/resolver.go
+++ b/common/resolver/resolver.go
@@ -5,8 +5,8 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
+ xe "github.com/ethereum/go-ethereum/xeth"
)
/*
@@ -17,10 +17,24 @@ UrlHint : Content Hash -> Url Hint
The resolver is meant to be called by the roundtripper transport implementation
of a url scheme
*/
-const (
- URLHintContractAddress = core.ContractAddrURLhint
- HashRegContractAddress = core.ContractAddrHashReg
-)
+
+// contract addresses will be hardcoded after they're created
+var URLHintContractAddress string = "0000000000000000000000000000000000000000000000000000000000001234"
+var HashRegContractAddress string = "0000000000000000000000000000000000000000000000000000000000005678"
+
+func CreateContracts(xeth *xe.XEth, addr string) {
+ var err error
+ URLHintContractAddress, err = xeth.Transact(addr, "", "100000000000", "1000000", "100000", ContractCodeURLhint)
+ if err != nil {
+ panic(err)
+ }
+ HashRegContractAddress, err = xeth.Transact(addr, "", "100000000000", "1000000", "100000", ContractCodeHashReg)
+ if err != nil {
+ panic(err)
+ }
+ URLHintContractAddress = URLHintContractAddress[2:]
+ HashRegContractAddress = HashRegContractAddress[2:]
+}
type Resolver struct {
backend Backend
diff --git a/core/contracts.go b/core/contracts.go
deleted file mode 100644
index 9d63e4043..000000000
--- a/core/contracts.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package core
-
-const ( // built-in contracts address and code
- ContractAddrURLhint = "0000000000000000000000000000000000000008"
- //ContractCodeURLhint = "0x60b180600c6000396000f30060003560e060020a90048063d66d6c1014601557005b60216004356024356027565b60006000f35b6000600083815260200190815260200160002054600160a060020a0316600014806075575033600160a060020a03166000600084815260200190815260200160002054600160a060020a0316145b607c5760ad565b3360006000848152602001908152602001600020819055508060016000848152602001908152602001600020819055505b505056"
- ContractCodeURLhint = "0x60003560e060020a90048063d66d6c1014601557005b60216004356024356027565b60006000f35b6000600083815260200190815260200160002054600160a060020a0316600014806075575033600160a060020a03166000600084815260200190815260200160002054600160a060020a0316145b607c5760ad565b3360006000848152602001908152602001600020819055508060016000848152602001908152602001600020819055505b505056"
- /*
- contract URLhint {
- function register(uint256 _hash, uint256 _url) {
- if (owner[_hash] == 0 || owner[_hash] == msg.sender) {
- owner[_hash] = msg.sender;
- url[_hash] = _url;
- }
- }
- mapping (uint256 => address) owner;
- mapping (uint256 => uint256) url;
- }
- */
-
- ContractAddrHashReg = "0000000000000000000000000000000000000009"
- ContractCodeHashReg = "0x60003560e060020a9004806331e12c2014601f578063d66d6c1014602b57005b6025603d565b60006000f35b6037600435602435605d565b60006000f35b600054600160a060020a0316600014605357605b565b336000819055505b565b600054600160a060020a031633600160a060020a031614607b576094565b8060016000848152602001908152602001600020819055505b505056"
- //ContractCodeHashReg = "0x609880600c6000396000f30060003560e060020a9004806331e12c2014601f578063d66d6c1014602b57005b6025603d565b60006000f35b6037600435602435605d565b60006000f35b600054600160a060020a0316600014605357605b565b336000819055505b565b600054600160a060020a031633600160a060020a031614607b576094565b8060016000848152602001908152602001600020819055505b505056"
- /*
- contract HashReg {
- function setowner() {
- if (owner == 0) {
- owner = msg.sender;
- }
- }
- function register(uint256 _key, uint256 _content) {
- if (msg.sender == owner) {
- content[_key] = _content;
- }
- }
- address owner;
- mapping (uint256 => uint256) content;
- }
- */
-
- BuiltInContracts = `
- "` + ContractAddrURLhint + `": {"balance": "0", "code": "` + ContractCodeURLhint + `" },
- "` + ContractAddrHashReg + `": {"balance": "0", "code": "` + ContractCodeHashReg + `" },
- `
-)
diff --git a/core/genesis.go b/core/genesis.go
index c475ca637..1159a5cec 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -63,7 +63,6 @@ const (
var genesisData = []byte(`{
"` + TestAccount + `": {"balance": "` + TestBalance + `"},
- ` + BuiltInContracts + `
"0000000000000000000000000000000000000001": {"balance": "1"},
"0000000000000000000000000000000000000002": {"balance": "1"},
"0000000000000000000000000000000000000003": {"balance": "1"},