"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
+ "github.com/vapor/protocol/state"
)
func TestBlockCache(t *testing.T) {
}
}
}
+
+func TestVoteResultCache(t *testing.T) {
+ newVoteResult := func(seq uint64) *state.VoteResult {
+ return &state.VoteResult{
+ Seq: seq,
+ }
+ }
+ voteResults := make(map[uint64]*state.VoteResult)
+ for i := 0; i < maxCachedVoteResults+10; i++ {
+ voteResult := newVoteResult(uint64(i))
+ voteResults[voteResult.Seq] = voteResult
+ }
+
+ cache := newVoteResultCache(func(seq uint64) (*state.VoteResult, error) {
+ return voteResults[seq], nil
+ })
+
+ for i := 0; i < maxCachedVoteResults+10; i++ {
+ voteResult := newVoteResult(uint64(i))
+ cache.lookup(voteResult.Seq)
+ }
+
+ for i := 0; i < 10; i++ {
+ voteResult := newVoteResult(uint64(i))
+ if v, _ := cache.get(voteResult.Seq); v != nil {
+ t.Fatalf("find old vote result")
+ }
+ }
+
+ for i := 10; i < maxCachedVoteResults+10; i++ {
+ voteResult := newVoteResult(uint64(i))
+ if v, _ := cache.get(voteResult.Seq); v == nil {
+ t.Fatalf("can't find new vote result")
+ }
+ }
+}