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

     1  package storages
     2  
     3  import (
     4  	"math/big"
     5  	"os"
     6  	"testing"
     7  
     8  	"fmt"
     9  
    10  	"github.com/sixexorg/magnetic-ring/common"
    11  	"github.com/sixexorg/magnetic-ring/store/storelaw"
    12  )
    13  
    14  func TestVoteStore(t *testing.T) {
    15  	dbDir := "./testVote"
    16  	os.RemoveAll(dbDir)
    17  	store, _ := NewVoteStore(dbDir, 0x01, 0x02)
    18  	voteId := common.Hash{1, 2, 3}
    19  	sv := &storelaw.VoteState{
    20  		VoteId:     voteId,
    21  		Height:     10,
    22  		Agree:      big.NewInt(10),
    23  		Against:    big.NewInt(20),
    24  		Abstention: big.NewInt(15),
    25  	}
    26  	store.NewBatch()
    27  	store.SaveVotes([]*storelaw.VoteState{sv})
    28  	err := store.CommitTo()
    29  	if err != nil {
    30  		t.Error(err)
    31  		return
    32  	}
    33  	vs2, err := store.GetVoteState(voteId, 30)
    34  	if err != nil {
    35  		t.Error(err)
    36  		return
    37  	}
    38  	fmt.Println(vs2)
    39  }