Commit 64f35ba8 authored by obscuren's avatar obscuren

merge errors fixed

parents 616066a5 99481a24
......@@ -9,11 +9,9 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
)
......@@ -312,11 +310,10 @@ out:
}
if len(blocks) > 0 {
chainManager := self.eth.ChainManager()
// Test and import
bchain := chain.NewChain(blocks)
_, err := chainManager.TestChain(bchain)
if err != nil && !chain.IsTDError(err) {
chainman := self.eth.ChainManager()
err := chainman.InsertChain(blocks)
if err != nil {
poollogger.Debugln(err)
self.Reset()
......@@ -330,16 +327,10 @@ out:
self.peer.StopWithReason(DiscBadPeer)
self.td = ethutil.Big0
self.peer = nil
} else {
if !chain.IsTDError(err) {
chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) {
self.eth.EventMux().Post(chain.NewBlockEvent{block})
self.eth.EventMux().Post(messages)
self.Remove(block.Hash())
})
}
}
for _, block := range blocks {
self.Remove(block.Hash())
}
}
}
......
......@@ -187,6 +187,7 @@ func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Mes
defer sm.mutex.Unlock()
if sm.bc.HasBlock(block.Hash()) {
fmt.Println("already having this block")
return nil, nil, nil
}
......@@ -213,7 +214,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
fmt.Printf("## %x %x ##\n", block.Hash(), block.Number)
}
receipts, err := sm.ApplyDiff(state, parent, block)
_, err = sm.ApplyDiff(state, parent, block)
if err != nil {
return
}
......@@ -224,11 +225,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return
}
receiptSha := types.DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
return
}
/*
receiptSha := types.DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
return
}
*/
// Block validation
if err = sm.ValidateBlock(block, parent); err != nil {
......@@ -241,14 +244,16 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return
}
//block.receipts = receipts // although this isn't necessary it be in the future
rbloom := types.CreateBloom(receipts)
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
return
}
/*
//block.receipts = receipts // although this isn't necessary it be in the future
rbloom := types.CreateBloom(receipts)
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
return
}
*/
state.Update(nil)
state.Update(ethutil.Big0)
if !block.State().Cmp(state) {
err = fmt.Errorf("invalid merkle root. received=%x got=%x", block.Root(), state.Root())
......@@ -268,6 +273,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
sm.transState = state.Copy()
sm.eth.TxPool().RemoveSet(block.Transactions())
fmt.Println("TD", td)
return td, messages, nil
} else {
......
package chain
import (
"bytes"
"container/list"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
)
var chainlogger = logger.NewLogger("CHAIN")
......@@ -56,8 +53,6 @@ type ChainManager struct {
CurrentBlock *types.Block
LastBlockHash []byte
workingChain *BlockChain
}
func NewChainManager() *ChainManager {
......@@ -186,15 +181,6 @@ func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain
func (self *ChainManager) GetBlock(hash []byte) *types.Block {
data, _ := ethutil.Config.Db.Get(hash)
if len(data) == 0 {
if self.workingChain != nil {
// Check the temp chain
for e := self.workingChain.Front(); e != nil; e = e.Next() {
if bytes.Compare(e.Value.(*link).Block.Hash(), hash) == 0 {
return e.Value.(*link).Block
}
}
}
return nil
}
......@@ -264,103 +250,22 @@ func (bc *ChainManager) Stop() {
}
}
func (self *ChainManager) NewIterator(startHash []byte) *ChainIterator {
return &ChainIterator{self, self.GetBlock(startHash)}
}
// This function assumes you've done your checking. No checking is done at this stage anymore
func (self *ChainManager) InsertChain(chain *BlockChain, call func(*types.Block, state.Messages)) {
for e := chain.Front(); e != nil; e = e.Next() {
link := e.Value.(*link)
self.add(link.Block)
self.SetTotalDifficulty(link.Td)
call(link.Block, link.Messages)
}
b, e := chain.Front(), chain.Back()
if b != nil && e != nil {
front, back := b.Value.(*link).Block, e.Value.(*link).Block
chainlogger.Infof("Imported %d blocks. #%v (%x) / %#v (%x)", chain.Len(), front.Number, front.Hash()[0:4], back.Number, back.Hash()[0:4])
}
}
func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {
self.workingChain = chain
defer func() { self.workingChain = nil }()
for e := chain.Front(); e != nil; e = e.Next() {
var (
l = e.Value.(*link)
block = l.Block
parent = self.GetBlock(block.PrevHash)
)
if parent == nil {
err = fmt.Errorf("incoming chain broken on hash %x\n", block.PrevHash[0:4])
return
}
var messages state.Messages
td, messages, err = self.processor.ProcessWithParent(block, parent) //self.eth.BlockManager().ProcessWithParent(block, parent)
func (self *ChainManager) InsertChain(chain Blocks) error {
for _, block := range chain {
td, messages, err := self.Ethereum.BlockManager().Process(block)
if err != nil {
chainlogger.Infoln(err)
chainlogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
chainlogger.Debugln(block)
if IsKnownBlockErr(err) {
continue
}
err = fmt.Errorf("incoming chain failed %v\n", err)
return
return err
}
l.Td = td
l.Messages = messages
}
if td.Cmp(self.TD) <= 0 {
err = &TDError{td, self.TD}
return
self.add(block)
self.SetTotalDifficulty(td)
self.Ethereum.EventMux().Post(NewBlockEvent{block})
self.Ethereum.EventMux().Post(messages)
}
self.workingChain = nil
return
}
type link struct {
Block *types.Block
Messages state.Messages
Td *big.Int
}
type BlockChain struct {
*list.List
}
func NewChain(blocks types.Blocks) *BlockChain {
chain := &BlockChain{list.New()}
for _, block := range blocks {
chain.PushBack(&link{block, nil, nil})
}
return chain
}
func (self *BlockChain) RlpEncode() []byte {
dat := make([]interface{}, 0)
for e := self.Front(); e != nil; e = e.Next() {
dat = append(dat, e.Value.(*link).Block.RlpData())
}
return ethutil.Encode(dat)
}
type ChainIterator struct {
cm *ChainManager
block *types.Block // current block in the iterator
}
func (self *ChainIterator) Prev() *types.Block {
self.block = self.cm.GetBlock(self.block.PrevHash)
return self.block
return nil
}
......@@ -126,3 +126,16 @@ func IsTDError(e error) bool {
_, ok := e.(*TDError)
return ok
}
type KnownBlockError struct {
number uint64
hash []byte
}
func (self *KnownBlockError) Error() string {
return fmt.Sprintf("block %d already known (%x)", self.number, self.hash[0:4])
}
func IsKnownBlockErr(e error) bool {
_, ok := e.(*KnownBlockError)
return ok
}
......@@ -103,11 +103,15 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
block := pool.Ethereum.ChainManager().CurrentBlock
// Something has gone horribly wrong if this happens
if block == nil {
return fmt.Errorf("[TXPL] No last block on the block chain")
return fmt.Errorf("No last block on the block chain")
}
if len(tx.Recipient) != 0 && len(tx.Recipient) != 20 {
return fmt.Errorf("[TXPL] Invalid recipient. len = %d", len(tx.Recipient))
return fmt.Errorf("Invalid recipient. len = %d", len(tx.Recipient))
}
if tx.v > 28 || tx.v < 27 {
return fmt.Errorf("tx.v != (28 || 27)")
}
if tx.GasPrice.Cmp(MinGasPrice) < 0 {
......@@ -115,19 +119,18 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
}
// Get the sender
//sender := pool.Ethereum.BlockManager().procState.GetAccount(tx.Sender())
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
totAmount := new(big.Int).Set(tx.Value)
// Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it.
if sender.Balance().Cmp(totAmount) < 0 {
return fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender())
return fmt.Errorf("Insufficient amount in sender's (%x) account", tx.Sender())
}
if tx.IsContract() {
if tx.GasPrice.Cmp(big.NewInt(minGasPrice)) < 0 {
return fmt.Errorf("[TXPL] Gasprice too low, %s given should be at least %d.", tx.GasPrice, minGasPrice)
return fmt.Errorf("Gasprice too low, %s given should be at least %d.", tx.GasPrice, minGasPrice)
}
}
......@@ -137,6 +140,34 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return nil
}
func (self *TxPool) Add(tx *types.Transaction) error {
hash := tx.Hash()
foundTx := FindTx(self.pool, func(tx *Transaction, e *list.Element) bool {
return bytes.Compare(tx.Hash(), hash) == 0
})
if foundTx != nil {
return fmt.Errorf("Known transaction (%x)", hash[0:4])
}
err := self.ValidateTransaction(tx)
if err != nil {
return err
}
self.addTransaction(tx)
tmp := make([]byte, 4)
copy(tmp, tx.Recipient)
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
// Notify the subscribers
self.Ethereum.EventMux().Post(TxPreEvent{tx})
return nil
}
func (pool *TxPool) queueHandler() {
out:
for {
......@@ -173,10 +204,6 @@ out:
}
}
func (pool *TxPool) QueueTransaction(tx *types.Transaction) {
pool.queueChan <- tx
}
func (pool *TxPool) CurrentTransactions() []*types.Transaction {
pool.mutex.Lock()
defer pool.mutex.Unlock()
......
......@@ -79,12 +79,7 @@ func (tx *Transaction) IsContract() bool {
func (tx *Transaction) CreationAddress(state *state.State) []byte {
// Generate a new address
addr := crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
//for i := uint64(0); state.GetStateObject(addr) != nil; i++ {
// addr = crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce + i}).Encode())[12:]
//}
return addr
return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
}
func (tx *Transaction) Signature(key []byte) []byte {
......
......@@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
)
type plugin struct {
......@@ -45,12 +44,12 @@ func (gui *Gui) LogPrint(level logger.LogLevel, msg string) {
}
*/
}
func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (*xeth.JSReceipt, error) {
func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (string, error) {
var data string
if len(recipient) == 0 {
code, err := ethutil.Compile(d, false)
if err != nil {
return nil, err
return "", err
}
data = ethutil.Bytes2Hex(code)
} else {
......
......@@ -128,7 +128,10 @@ func (self *UiLib) PastPeers() *ethutil.List {
func (self *UiLib) ImportTx(rlpTx string) {
tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(rlpTx))
self.eth.TxPool().QueueTransaction(tx)
err := self.eth.TxPool().Add(tx)
if err != nil {
guilogger.Infoln("import tx failed ", err)
}
}
func (self *UiLib) EvalJavascriptFile(path string) {
......@@ -306,7 +309,7 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
return conv
}
func (self *UiLib) Transact(params map[string]interface{}) (*xeth.JSReceipt, error) {
func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
object := mapToTxParams(params)
return self.JSXEth.Transact(
......
......@@ -62,6 +62,16 @@ func S256(x *big.Int) *big.Int {
}
}
func FirstBitSet(v *big.Int) int {
for i := 0; i < v.BitLen(); i++ {
if v.Bit(i) > 0 {
return i
}
}
return v.BitLen()
}
// Big to bytes
//
// Returns the bytes of a big integer with the size specified by **base**
......
......@@ -29,7 +29,6 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types"
......@@ -205,7 +204,7 @@ func (self *Miner) mine() {
// Accumulate the rewards included for this block
blockManager.AccumelateRewards(block.State(), block, parent)
block.State().Update(nil)
block.State().Update(ethutil.Big0)
minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions))
......@@ -213,15 +212,10 @@ func (self *Miner) mine() {
nonce := self.pow.Search(block, self.powQuitCh)
if nonce != nil {
block.Nonce = nonce
lchain := chain.NewChain(types.Blocks{block})
_, err := chainMan.TestChain(lchain)
err := chainMan.InsertChain(types.Blocks{block})
if err != nil {
minerlogger.Infoln(err)
} else {
chainMan.InsertChain(lchain, func(block *types.Block, _ state.Messages) {
self.eth.EventMux().Post(chain.NewBlockEvent{block})
})
self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val})
minerlogger.Infof("🔨 Mined block %x\n", block.Hash())
......
......@@ -430,7 +430,12 @@ func (p *Peer) HandleInbound() {
// processing when a new block is found
for i := 0; i < msg.Data.Len(); i++ {
tx := types.NewTransactionFromValue(msg.Data.Get(i))
p.ethereum.TxPool().QueueTransaction(tx)
err := p.ethereum.TxPool().Add(tx)
if err != nil {
peerlogger.Infoln(err)
} else {
peerlogger.Infof("tx OK (%x)\n", tx.Hash()[0:4])
}
}
case wire.MsgGetPeersTy:
// Peer asked for list of connected peers
......
......@@ -249,7 +249,6 @@ func (s *State) Reset() {
continue
}
//stateObject.state.Reset()
stateObject.Reset()
}
......@@ -281,6 +280,7 @@ func (self *State) Update(gasUsed *big.Int) {
var deleted bool
// Refund any gas that's left
// XXX THIS WILL CHANGE IN POC8
uhalf := new(big.Int).Div(gasUsed, ethutil.Big2)
for addr, refs := range self.refund {
for _, ref := range refs {
......@@ -289,6 +289,7 @@ func (self *State) Update(gasUsed *big.Int) {
self.GetStateObject([]byte(addr)).AddBalance(refund.Mul(refund, ref.price))
}
}
self.refund = make(map[string][]refund)
for _, stateObject := range self.stateObjects {
if stateObject.remove {
......
......@@ -212,7 +212,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
func (self *StateObject) SetGasPool(gasLimit *big.Int) {
self.gasPool = new(big.Int).Set(gasLimit)
statelogger.DebugDetailf("%x: fuel (+ %v)", self.Address(), self.gasPool)
statelogger.Debugf("%x: gas (+ %v)", self.Address(), self.gasPool)
}
func (self *StateObject) BuyGas(gas, price *big.Int) error {
......
{
"genesis_rlp_hex": "f9012ff9012aa00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0",
"genesis_rlp_hex": "f9012ef90129a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0",
"genesis_state_root": "c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718c",
"initial_alloc": {
"51ba59315b3a95761d0863b05ccc7a7f54703d99": "1606938044258990275541962092341162602522202993782792835301376",
......@@ -11,5 +11,5 @@
"e6716f9544a56c530d868e4bfbacb172315bdead": "1606938044258990275541962092341162602522202993782792835301376",
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4": "1606938044258990275541962092341162602522202993782792835301376"
},
"genesis_hash": "955f36d073ccb026b78ab3424c15cf966a7563aa270413859f78702b9e8e22cb"
"genesis_hash": "779b1b620b03c0fb24963e183d5e88e3dbe4484e3f6e2aa05942e3be7b48e179"
}
......@@ -8,6 +8,8 @@
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs" : {
},
"out" : "0x",
"post" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
......
This diff is collapsed.
{
"makeMoney" : {
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs" : {
},
"out" : "0x",
"post" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000010",
"code" : "0x7b601080600c6000396000f200600035541560095700602035600035556000526000600060006000601773aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecf1",
"nonce" : "0",
"storage" : {
}
},
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" : {
"balance" : "850",
"code" : "0x",
"nonce" : "0",
"storage" : {
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "140",
"code" : "0x",
"nonce" : "1",
"storage" : {
}
},
"aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000000000000000000",
"code" : "0x600160015532600255",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"balance" : "1000000000000000000",
"code" : "0x7b601080600c6000396000f200600035541560095700602035600035556000526000600060006000601773aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecf1",
"nonce" : "0",
"storage" : {
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000",
"code" : "0x",
"nonce" : "0",
"storage" : {
}
},
"aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "1000000000000000000",
"code" : "0x600160015532600255",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" : {
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "10"
}
}
}
\ No newline at end of file
{
"singleItem": {
"in": {
"A": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
"root": "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab"
"in": [
["A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
],
"root": "0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab"
},
"dogs": {
"in": {
"doe": "reindeer",
"dog": "puppy",
"dogglesworth": "cat"
},
"root": "8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"
"in": [
["doe", "reindeer"],
["dog", "puppy"],
["dogglesworth", "cat"]
],
"root": "0x8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"
},
"puppy": {
"in": {
"do": "verb",
"horse": "stallion",
"doge": "coin",
"dog": "puppy"
},
"root": "5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84"
"in": [
["do", "verb"],
["horse", "stallion"],
["doge", "coin"],
["dog", "puppy"]
],
"root": "0x5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84"
},
"emptyValues": {
"in": {
"do": "verb",
"ether": "wookiedoo",
"horse": "stallion",
"shaman": "horse",
"doge": "coin",
"ether": "",
"dog": "puppy",
"shaman": ""
},
"root": "4505cb6d817068bcd68fb225ab4d5ab70860461d3b35738bf6bcf7b44d702d0d"
"in": [
["do", "verb"],
["ether", "wookiedoo"],
["horse", "stallion"],
["shaman", "horse"],
["doge", "coin"],
["ether", ""],
["dog", "puppy"],
["shaman", ""]
],
"root": "0x5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84"
},
"foo": {
"in": {
"foo": "bar",
"food": "bat",
"food": "bass"
},
"root": "17beaa1648bafa633cda809c90c04af50fc8aed3cb40d16efbddee6fdf63c4c3"
"in": [
["foo", "bar"],
["food", "bat"],
["food", "bass"]
],
"root": "0x17beaa1648bafa633cda809c90c04af50fc8aed3cb40d16efbddee6fdf63c4c3"
},
"smallValues": {
"in": {
"be": "e",
"dog": "puppy",
"bed": "d"
},
"root": "3f67c7a47520f79faa29255d2d3c084a7a6df0453116ed7232ff10277a8be68b"
"in": [
["be", "e"],
["dog", "puppy"],
["bed", "d"]
],
"root": "0x3f67c7a47520f79faa29255d2d3c084a7a6df0453116ed7232ff10277a8be68b"
},
"testy": {
"in": {
"test": "test",
"te": "testy"
},
"root": "8452568af70d8d140f58d941338542f645fcca50094b20f3c3d8c3df49337928"
"in": [
["test", "test"],
["te", "testy"]
],
"root": "0x8452568af70d8d140f58d941338542f645fcca50094b20f3c3d8c3df49337928"
},
"hex": {
"in": {
"0x0045": "0x0123456789",
"0x4500": "0x9876543210"
},
"root": "285505fcabe84badc8aa310e2aae17eddc7d120aabec8a476902c8184b3a3503"
},
"in": [
["0x0045", "0x0123456789"],
["0x4500", "0x9876543210"]
],
"root": "0x285505fcabe84badc8aa310e2aae17eddc7d120aabec8a476902c8184b3a3503"
},
"jeff": {
"in": {
"0x0000000000000000000000000000000000000000000000000000000000000045": "0x22b224a1420a802ab51d326e29fa98e34c4f24ea",
"0x0000000000000000000000000000000000000000000000000000000000000046": "0x67706c2076330000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000001234567890": "0x697c7b8c961b56f675d570498424ac8de1a918f6",
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6": "0x1234567890",
"0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2": "0x4655474156000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1": "0x4e616d6552656700000000000000000000000000000000000000000000000000",
"0x4655474156000000000000000000000000000000000000000000000000000000": "0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2",
"0x4e616d6552656700000000000000000000000000000000000000000000000000": "0xec4f34c97e43fbb2816cfd95e388353c7181dab1",
"0x0000000000000000000000000000000000000000000000000000001234567890": "",
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6": "0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000",
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000": "0x697c7b8c961b56f675d570498424ac8de1a918f6"
},
"root": "088c8e162c91c75ca9efa63f21530bbc6964cff7453a5d6af8404d090292a3e7"
}
"in": [
["0x0000000000000000000000000000000000000000000000000000000000000045", "0x22b224a1420a802ab51d326e29fa98e34c4f24ea"],
["0x0000000000000000000000000000000000000000000000000000000000000046", "0x67706c2076330000000000000000000000000000000000000000000000000000"],
["0x0000000000000000000000000000000000000000000000000000001234567890", "0x697c7b8c961b56f675d570498424ac8de1a918f6"],
["0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6", "0x1234567890"],
["0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2", "0x4655474156000000000000000000000000000000000000000000000000000000"],
["0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1", "0x4e616d6552656700000000000000000000000000000000000000000000000000"],
["0x4655474156000000000000000000000000000000000000000000000000000000", "0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2"],
["0x4e616d6552656700000000000000000000000000000000000000000000000000", "0xec4f34c97e43fbb2816cfd95e388353c7181dab1"],
["0x0000000000000000000000000000000000000000000000000000001234567890", ""],
["0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6", "0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"],
["0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000", "0x697c7b8c961b56f675d570498424ac8de1a918f6"]
],
"root": "0x9f6221ebb8efe7cff60a716ecb886e67dd042014be444669f0159d8e68b42100"
}
}
This diff is collapsed.
......@@ -21,6 +21,8 @@
"value" : "1000000000000000000"
},
"gas" : "9698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -64,6 +66,8 @@
"value" : "1000000000000000000"
},
"gas" : "9698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -107,6 +111,8 @@
"value" : "1000000000000000000"
},
"gas" : "9698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -150,6 +156,8 @@
"value" : "1000000000000000000"
},
"gas" : "9898",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -192,6 +200,8 @@
"value" : "1000000000000000000"
},
"gas" : "9698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -235,6 +245,8 @@
"value" : "1000000000000000000"
},
"gas" : "9698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......
......@@ -21,6 +21,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -64,6 +66,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"cd1722f3947def4cf144679da39c4c32bdc35681" : {
......@@ -107,6 +111,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999878",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -156,6 +162,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999678",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -199,6 +207,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999656",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -242,6 +252,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999656",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -291,7 +303,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "99999999692",
"gas" : "99999999691",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -334,7 +348,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "99999999692",
"gas" : "99999999691",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -378,6 +394,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999892",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -420,6 +438,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999697",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -463,6 +483,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999697",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -506,6 +528,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999697",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -549,6 +573,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -592,6 +618,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -635,6 +663,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -678,6 +708,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -721,6 +753,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -763,7 +797,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "99999999692",
"gas" : "99999999691",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -806,7 +842,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "99999999692",
"gas" : "99999999691",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -850,6 +888,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -892,7 +932,9 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "99999999690",
"gas" : "99999999689",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -950,6 +992,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999695",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -1007,6 +1051,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999697",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -1064,6 +1110,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -1107,6 +1155,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999698",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......
This diff is collapsed.
This diff is collapsed.
......@@ -21,6 +21,8 @@
"value" : "1000000000000000000"
},
"gas" : "99999999677",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -64,6 +66,8 @@
"value" : "1000000000000000000"
},
"gas" : "9676",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -107,6 +111,8 @@
"value" : "1000000000000000000"
},
"gas" : "9676",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -129,8 +135,6 @@
}
},
"sha3_3" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
......@@ -149,17 +153,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x620fffff6103e820600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
......@@ -171,8 +164,6 @@
}
},
"sha3_4" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
......@@ -191,17 +182,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6064640fffffffff20600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
......@@ -213,8 +193,6 @@
}
},
"sha3_5" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
......@@ -233,17 +211,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x640fffffffff61271020600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
......@@ -255,8 +222,6 @@
}
},
"sha3_6" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
......@@ -275,17 +240,6 @@
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff20600055",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
......
......@@ -27,6 +27,8 @@
"value" : "1000000000000000000"
},
"gas" : "9949",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -93,6 +95,8 @@
"value" : "1000000000000000000"
},
"gas" : "9824",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -141,6 +145,8 @@
"value" : "1000000000000000000"
},
"gas" : "9971",
"logs" : {
},
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
......@@ -183,6 +189,8 @@
"value" : "1000000000000000000"
},
"gas" : "9999",
"logs" : {
},
"out" : "0x",
"post" : {
"cd1722f3947def4cf144679da39c4c32bdc35681" : {
......
......@@ -9,6 +9,8 @@ module.exports = {
txtest: require('./BasicTests/txtest'),
StateTests: {
stPreCompiledContracts: require('./StateTests/stPreCompiledContracts'),
stRecursiveCreate: require('./StateTests/stRecursiveCreate'),
stSpecial: require('./StateTests/stSpecialTest'),
stSystemOperationsTest: require('./StateTests/stSystemOperationsTest'),
},
VMTests: {
......@@ -17,8 +19,9 @@ module.exports = {
vmBlockInfoTest: require('./VMTests/vmBlockInfoTest'),
vmEnvironmentalInfoTest: require('./VMTests/vmEnvironmentalInfoTest'),
vmIOandFlowOperationsTest: require('./VMTests/vmIOandFlowOperationsTest'),
vmLogTest: require('./VMTests/vmLogTest'),
vmPushDupSwapTest: require('./VMTests/vmPushDupSwapTest'),
vmSha3Test: require('./VMTests/vmSha3Test'),
vmtestst: require('./VMTests/vmtests'),
vmtests: require('./VMTests/vmtests'),
}
};
......@@ -3,6 +3,7 @@ package helper
import (
"math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
......@@ -66,3 +67,17 @@ func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, e
return ret, execution.Gas, err
}
func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int, error) {
address := FromHex(tx["to"])
keyPair, _ := crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
caller := state.GetOrNewStateObject(keyPair.Address())
vmenv := NewEnvFromMap(state, env, tx)
vmenv.origin = caller.Address()
evm := vm.New(vmenv, vm.DebugVmTy)
execution := vm.NewExecution(evm, address, FromHex(tx["data"]), ethutil.Big(tx["gasLimit"]), ethutil.Big(tx["gasPrice"]), ethutil.Big(tx["value"]))
ret, err := execution.Exec(address, caller)
return ret, execution.Gas, err
}
package vm
<<<<<<< HEAD
// import (
// "bytes"
// "testing"
......@@ -133,3 +134,185 @@ package vm
// const fn = "../files/vmtests/vmtests.json"
// RunVmTest(fn, t)
// }
=======
import (
"bytes"
"math/big"
"strconv"
"testing"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
type Account struct {
Balance string
Code string
Nonce string
Storage map[string]string
}
func StateObjectFromAccount(addr string, account Account) *state.StateObject {
obj := state.NewStateObject(ethutil.Hex2Bytes(addr))
obj.SetBalance(ethutil.Big(account.Balance))
if ethutil.IsHex(account.Code) {
account.Code = account.Code[2:]
}
obj.Code = ethutil.Hex2Bytes(account.Code)
obj.Nonce = ethutil.Big(account.Nonce).Uint64()
return obj
}
type Env struct {
CurrentCoinbase string
CurrentDifficulty string
CurrentGasLimit string
CurrentNumber string
CurrentTimestamp interface{}
PreviousHash string
}
type VmTest struct {
Callcreates interface{}
//Env map[string]string
Env Env
Exec map[string]string
Transaction map[string]string
Gas string
Out string
Post map[string]Account
Pre map[string]Account
}
func RunVmTest(p string, t *testing.T) {
tests := make(map[string]VmTest)
helper.CreateFileTests(t, p, &tests)
for name, test := range tests {
state := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
state.SetStateObject(obj)
}
// XXX Yeah, yeah...
env := make(map[string]string)
env["currentCoinbase"] = test.Env.CurrentCoinbase
env["currentDifficulty"] = test.Env.CurrentDifficulty
env["currentGasLimit"] = test.Env.CurrentGasLimit
env["currentNumber"] = test.Env.CurrentNumber
env["previousHash"] = test.Env.PreviousHash
if n, ok := test.Env.CurrentTimestamp.(float64); ok {
env["currentTimestamp"] = strconv.Itoa(int(n))
} else {
env["currentTimestamp"] = test.Env.CurrentTimestamp.(string)
}
var (
ret []byte
gas *big.Int
err error
)
if len(test.Exec) > 0 {
ret, gas, err = helper.RunVm(state, env, test.Exec)
} else {
ret, gas, err = helper.RunState(state, env, test.Transaction)
}
// When an error is returned it doesn't always mean the tests fails.
// Have to come up with some conditional failing mechanism.
if err != nil {
helper.Log.Infoln(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)
}
if len(test.Gas) > 0 {
gexp := ethutil.Big(test.Gas)
if gexp.Cmp(gas) != 0 {
t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
}
}
for addr, account := range test.Post {
obj := state.GetStateObject(helper.FromHex(addr))
for addr, value := range account.Storage {
v := obj.GetState(helper.FromHex(addr)).Bytes()
vexp := helper.FromHex(value)
if bytes.Compare(v, vexp) != 0 {
t.Errorf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v))
}
}
}
}
}
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
func TestVMArithmetic(t *testing.T) {
const fn = "../files/vmtests/vmArithmeticTest.json"
RunVmTest(fn, t)
}
func TestBitwiseLogicOperation(t *testing.T) {
const fn = "../files/vmtests/vmBitwiseLogicOperationTest.json"
RunVmTest(fn, t)
}
func TestBlockInfo(t *testing.T) {
const fn = "../files/vmtests/vmBlockInfoTest.json"
RunVmTest(fn, t)
}
func TestEnvironmentalInfo(t *testing.T) {
const fn = "../files/vmtests/vmEnvironmentalInfoTest.json"
RunVmTest(fn, t)
}
func TestFlowOperation(t *testing.T) {
const fn = "../files/vmtests/vmIOandFlowOperationsTest.json"
RunVmTest(fn, t)
}
func TestPushDupSwap(t *testing.T) {
const fn = "../files/vmtests/vmPushDupSwapTest.json"
RunVmTest(fn, t)
}
func TestVMSha3(t *testing.T) {
const fn = "../files/vmtests/vmSha3Test.json"
RunVmTest(fn, t)
}
func TestVm(t *testing.T) {
const fn = "../files/vmtests/vmtests.json"
RunVmTest(fn, t)
}
func TestStateSystemOperations(t *testing.T) {
const fn = "../files/StateTests/stSystemOperationsTest.json"
RunVmTest(fn, t)
}
func TestStatePreCompiledContracts(t *testing.T) {
const fn = "../files/StateTests/stPreCompiledContracts.json"
RunVmTest(fn, t)
}
func TestStateRecursiveCreate(t *testing.T) {
const fn = "../files/StateTests/stRecursiveCreate.json"
RunVmTest(fn, t)
}
func TestStateSpecialTest(t *testing.T) {
const fn = "../files/StateTests/stSpecialTest.json"
RunVmTest(fn, t)
}
>>>>>>> develop
......@@ -31,12 +31,16 @@ func sha256Func(in []byte) []byte {
}
func ripemd160Func(in []byte) []byte {
return ethutil.RightPadBytes(crypto.Ripemd160(in), 32)
return ethutil.LeftPadBytes(crypto.Ripemd160(in), 32)
}
func ecrecoverFunc(in []byte) []byte {
// In case of an invalid sig. Defaults to return nil
defer func() { recover() }()
return crypto.Ecrecover(in)
hash := in[:32]
v := ethutil.BigD(in[32:64]).Bytes()[0] - 27
sig := append(in[64:], v)
return ethutil.LeftPadBytes(crypto.Sha3(crypto.Ecrecover(append(hash, sig...))[1:])[12:], 32)
}
......@@ -64,7 +64,7 @@ func (c *Closure) GetOp(x int) OpCode {
}
func (c *Closure) GetByte(x int) byte {
if x < len(c.Code) {
if x > -1 && x < len(c.Code) {
return c.Code[x]
}
......
......@@ -69,6 +69,7 @@ func (self *Execution) exec(code, caddr []byte, caller ClosureRef) (ret []byte,
if self.Gas.Cmp(p.Gas) >= 0 {
ret = p.Call(self.input)
self.vm.Printf("NATIVE_FUNC(%x) => %x", naddr, ret)
self.vm.Endl()
}
} else {
// Create a new callable closure
......
......@@ -163,7 +163,7 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
// Stack checks only
case ISZERO, CALLDATALOAD, POP, JUMP, NOT: // 1
require(1)
case ADD, SUB, DIV, SDIV, MOD, SMOD, EXP, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2
case ADD, SUB, DIV, SDIV, MOD, SMOD, LT, GT, SLT, SGT, EQ, AND, OR, XOR, BYTE: // 2
require(2)
case ADDMOD, MULMOD: // 3
require(3)
......@@ -181,6 +181,16 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
reqGs.Set(GasLog)
addStepGasUsage(new(big.Int).Mul(big.NewInt(int64(n)), GasLog))
addStepGasUsage(new(big.Int).Add(mSize, mStart))
case EXP:
require(2)
exp := new(big.Int).Set(stack.data[stack.Len()-2])
nbytes := 0
for exp.Cmp(ethutil.Big0) > 0 {
nbytes += 1
exp.Rsh(exp, 8)
}
gas.Set(big.NewInt(int64(nbytes + 1)))
// Gas only
case STOP:
reqGas.Set(ethutil.Big0)
......@@ -281,7 +291,6 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
addStepGasUsage(memGasUsage)
mem.Resize(newMemSize.Uint64())
}
}
......@@ -295,6 +304,8 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
return nil, new(big.Int), OOG(reqGas, gas)
}
mem.Resize(newMemSize.Uint64())
switch op {
// 0x20 range
case ADD:
......
......@@ -178,19 +178,25 @@ func (self *JSXEth) FromNumber(str string) string {
return ethutil.BigD(ethutil.Hex2Bytes(str)).String()
}
func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) {
var hash []byte
var contractCreation bool
if len(toStr) == 0 {
contractCreation = true
func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
var (
to []byte
value = ethutil.NewValue(valueStr)
gas = ethutil.NewValue(gasStr)
gasPrice = ethutil.NewValue(gasPriceStr)
data []byte
)
if ethutil.IsHex(codeStr) {
data = ethutil.Hex2Bytes(codeStr[2:])
} else {
// Check if an address is stored by this address
addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes()
if len(addr) > 0 {
hash = addr
} else {
hash = ethutil.Hex2Bytes(toStr)
}
data = ethutil.Hex2Bytes(codeStr)
}
if ethutil.IsHex(toStr) {
to = ethutil.Hex2Bytes(toStr[2:])
} else {
to = ethutil.Hex2Bytes(toStr)
}
var keyPair *crypto.KeyPair
......@@ -202,47 +208,78 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
}
if err != nil {
return nil, err
return "", err
}
var (
value = ethutil.Big(valueStr)
gas = ethutil.Big(gasStr)
gasPrice = ethutil.Big(gasPriceStr)
data []byte
tx *types.Transaction
)
if ethutil.IsHex(codeStr) {
data = ethutil.Hex2Bytes(codeStr[2:])
} else {
data = ethutil.Hex2Bytes(codeStr)
tx, err := self.XEth.Transact(keyPair, to, value, gas, gasPrice, data)
if err != nil {
return "", err
}
if contractCreation {
tx = types.NewContractCreationTx(value, gas, gasPrice, data)
} else {
tx = types.NewTransactionMessage(hash, value, gas, gasPrice, data)
if chain.IsContractAddr(to) {
return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil
}
acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address())
tx.Nonce = acc.Nonce
acc.Nonce += 1
self.obj.BlockManager().TransState().UpdateStateObject(acc)
return ethutil.Bytes2Hex(tx.Hash()), nil
tx.Sign(keyPair.PrivateKey)
self.obj.TxPool().QueueTransaction(tx)
/*
var hash []byte
var contractCreation bool
if len(toStr) == 0 {
contractCreation = true
} else {
// Check if an address is stored by this address
addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes()
if len(addr) > 0 {
hash = addr
} else {
hash = ethutil.Hex2Bytes(toStr)
}
}
if contractCreation {
pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
}
return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
var (
value = ethutil.Big(valueStr)
gas = ethutil.Big(gasStr)
gasPrice = ethutil.Big(gasPriceStr)
data []byte
tx *chain.Transaction
)
if ethutil.IsHex(codeStr) {
data = ethutil.Hex2Bytes(codeStr[2:])
} else {
data = ethutil.Hex2Bytes(codeStr)
}
if contractCreation {
tx = chain.NewContractCreationTx(value, gas, gasPrice, data)
} else {
tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data)
}
acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address())
tx.Nonce = acc.Nonce
acc.Nonce += 1
self.obj.BlockManager().TransState().UpdateStateObject(acc)
tx.Sign(keyPair.PrivateKey)
self.obj.TxPool().QueueTransaction(tx)
if contractCreation {
pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State()))
}
return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
*/
}
func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
self.obj.TxPool().QueueTransaction(tx)
err := self.obj.TxPool().Add(tx)
if err != nil {
return nil, err
}
return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment