github.com/annchain/OG@v0.0.9/vm/ovm/layer_db_test.go (about) 1 package ovm 2 3 import ( 4 "fmt" 5 "github.com/annchain/OG/common" 6 "math/big" 7 "testing" 8 ) 9 10 func TestLayers(t *testing.T) { 11 base := NewMemoryStateDB() 12 ldb := NewLayerDB(base) 13 14 addr1 := common.HexToAddress("0x01") 15 addr2 := common.HexToAddress("0x02") 16 addr3 := common.HexToAddress("0x03") 17 18 ldb.CreateAccount(addr1) 19 ldb.CreateAccount(addr2) 20 21 ldb.AddBalance(addr1, big.NewInt(100)) 22 23 ldb.NewLayer() 24 ldb.CreateAccount(addr3) 25 ldb.AddBalance(addr1, big.NewInt(50)) 26 ldb.AddBalance(addr2, big.NewInt(30)) 27 28 ldb.NewLayer() 29 ldb.SetNonce(addr3, 1) 30 ldb.SubBalance(addr2, big.NewInt(10000)) 31 32 fmt.Println(ldb.String()) 33 fmt.Println(ldb.GetBalance(addr1)) 34 fmt.Println(ldb.GetBalance(addr2)) 35 fmt.Println(ldb.GetBalance(addr3)) 36 37 ldb.MergeChanges() 38 fmt.Println(ldb.String()) 39 fmt.Println(ldb.GetBalance(addr1)) 40 fmt.Println(ldb.GetBalance(addr2)) 41 fmt.Println(ldb.GetBalance(addr3)) 42 }