github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/mainchain/storages/account_store_test.go (about) 1 package storages 2 3 import ( 4 "testing" 5 6 "math/big" 7 8 "fmt" 9 10 "bytes" 11 12 "github.com/magiconair/properties/assert" 13 "github.com/sixexorg/magnetic-ring/mock" 14 "github.com/sixexorg/magnetic-ring/store/mainchain/states" 15 ) 16 17 func TestAccountState(t *testing.T) { 18 dbdir := "test/account1" 19 store, _ := NewAccoutStore(dbdir, false) 20 as := &states.AccountState{ 21 Address: mock.Address_1, 22 Height: 1, 23 Data: &states.Account{ 24 Nonce: 1, 25 Balance: big.NewInt(2000), 26 EnergyBalance: big.NewInt(3000), 27 }, 28 } 29 buff := bytes.NewBuffer(nil) 30 buff.Write(as.GetKey()) 31 as.Serialize(buff) 32 asTmp := &states.AccountState{} 33 asTmp.Deserialize(buff) 34 assert.Equal(t, as, asTmp) 35 err := store.Save(as) 36 if err != nil { 37 t.Fail() 38 t.Error(err) 39 return 40 } 41 asNew, err := store.GetPrev(2, mock.Address_1) 42 if err != nil { 43 t.Fail() 44 t.Error(err) 45 return 46 } 47 fmt.Println(asNew.Height, asNew.Data.Balance) 48 }