mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 04:03:49 +00:00
NatSpec contracts are now not in the genesis block but added by the test
This commit is contained in:
parent
f255336c2c
commit
dba2367157
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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 + `" },
|
||||
`
|
||||
)
|
@ -63,7 +63,6 @@ const (
|
||||
|
||||
var genesisData = []byte(`{
|
||||
"` + TestAccount + `": {"balance": "` + TestBalance + `"},
|
||||
` + BuiltInContracts + `
|
||||
"0000000000000000000000000000000000000001": {"balance": "1"},
|
||||
"0000000000000000000000000000000000000002": {"balance": "1"},
|
||||
"0000000000000000000000000000000000000003": {"balance": "1"},
|
||||
|
Loading…
Reference in New Issue
Block a user