github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/mainchain/storages/account_cache_test.go (about)

     1  package storages
     2  
     3  import (
     4  	"testing"
     5  
     6  	"math/big"
     7  
     8  	"github.com/sixexorg/magnetic-ring/mock"
     9  	"github.com/sixexorg/magnetic-ring/store/mainchain/states"
    10  )
    11  
    12  func TestAccountCache(t *testing.T) {
    13  	accahe, err := NewAccountCache()
    14  	if err != nil {
    15  		t.Fail()
    16  		t.Error(err)
    17  		return
    18  	}
    19  
    20  	as := &states.AccountState{
    21  		Address: mock.Address_1,
    22  		Data: &states.Account{
    23  			Nonce:       5,
    24  			Balance:     big.NewInt(20),
    25  			EnergyBalance: big.NewInt(200),
    26  			BonusHeight: 0,
    27  		}}
    28  
    29  	accahe.AddState(as)
    30  
    31  	state := accahe.GetState(mock.Address_1)
    32  	if state != nil {
    33  		t.Log(state)
    34  	}
    35  	as2 := &states.AccountState{
    36  		Address: mock.Address_1,
    37  		Data: &states.Account{
    38  			Nonce:       7,
    39  			Balance:     big.NewInt(230),
    40  			EnergyBalance: big.NewInt(300),
    41  			BonusHeight: 0,
    42  		}}
    43  	accahe.AddState(as2)
    44  	state2 := accahe.GetState(mock.Address_1)
    45  	if state2 != nil {
    46  		t.Log(state2)
    47  	}
    48  }