2014-05-20 12:19:07 +03:00
|
|
|
package ethchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/ethereum/eth-go/ethdb"
|
|
|
|
"github.com/ethereum/eth-go/ethutil"
|
2014-05-21 01:17:50 +03:00
|
|
|
"math/big"
|
2014-05-20 12:19:07 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSync(t *testing.T) {
|
2014-06-27 17:56:45 +03:00
|
|
|
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "", "ETH")
|
2014-05-20 12:19:07 +03:00
|
|
|
|
|
|
|
db, _ := ethdb.NewMemDatabase()
|
|
|
|
state := NewState(ethutil.NewTrie(db, ""))
|
|
|
|
|
|
|
|
contract := NewContract([]byte("aa"), ethutil.Big1, ZeroHash256)
|
|
|
|
|
|
|
|
contract.script = []byte{42}
|
|
|
|
|
|
|
|
state.UpdateStateObject(contract)
|
|
|
|
state.Sync()
|
|
|
|
|
|
|
|
object := state.GetStateObject([]byte("aa"))
|
2014-05-21 01:17:50 +03:00
|
|
|
if len(object.Script()) == 0 {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestObjectGet(t *testing.T) {
|
2014-06-27 17:56:45 +03:00
|
|
|
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "", "ETH")
|
2014-05-21 01:17:50 +03:00
|
|
|
|
|
|
|
db, _ := ethdb.NewMemDatabase()
|
|
|
|
ethutil.Config.Db = db
|
|
|
|
|
|
|
|
state := NewState(ethutil.NewTrie(db, ""))
|
|
|
|
|
|
|
|
contract := NewContract([]byte("aa"), ethutil.Big1, ZeroHash256)
|
|
|
|
state.UpdateStateObject(contract)
|
|
|
|
|
|
|
|
contract = state.GetStateObject([]byte("aa"))
|
|
|
|
contract.SetStorage(big.NewInt(0), ethutil.NewValue("hello"))
|
|
|
|
o := contract.GetMem(big.NewInt(0))
|
|
|
|
fmt.Println(o)
|
|
|
|
|
|
|
|
state.UpdateStateObject(contract)
|
|
|
|
contract.SetStorage(big.NewInt(0), ethutil.NewValue("hello00"))
|
|
|
|
|
|
|
|
contract = state.GetStateObject([]byte("aa"))
|
|
|
|
o = contract.GetMem(big.NewInt(0))
|
|
|
|
fmt.Println("after", o)
|
2014-05-20 12:19:07 +03:00
|
|
|
}
|