aboutsummaryrefslogtreecommitdiffstats
path: root/dex/cache_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-04-02 22:04:28 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:59 +0800
commite02415d6224060ca9d7c3cef9005c729ac6b6c05 (patch)
tree9a15cf979ba16ea9990af921ff518dc6882fc0fb /dex/cache_test.go
parent5d3ac45f9300821560509be0e3be38be55ca992a (diff)
downloaddexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.tar
dexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.tar.gz
dexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.tar.bz2
dexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.tar.lz
dexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.tar.xz
dexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.tar.zst
dexon-e02415d6224060ca9d7c3cef9005c729ac6b6c05.zip
dex: try to reduce the chance to pull non-finalized blocks (#327)
* Send non-finalized blocks to notary set only * Update randomness field for blocks in cache upon receiving agreement result * Filter AgreementResult by its position * Avoid overwriting finalized blocks with non-finalized ones * Add blocks to finalized cache when pulling * Update to finalized cache when we have corresponding element in non-finalized one.
Diffstat (limited to 'dex/cache_test.go')
-rw-r--r--dex/cache_test.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/dex/cache_test.go b/dex/cache_test.go
index b06effafb..04bca06ef 100644
--- a/dex/cache_test.go
+++ b/dex/cache_test.go
@@ -160,7 +160,7 @@ func TestCacheBlock(t *testing.T) {
block2.Hash: {},
block3.Hash: {},
}
- blocks := cache.blocks(hashes)
+ blocks := cache.blocks(hashes, true)
if len(blocks) != 3 {
t.Errorf("fail to get blocks: have %d, want 3", len(blocks))
}
@@ -172,7 +172,7 @@ func TestCacheBlock(t *testing.T) {
cache.addBlock(block4)
- blocks = cache.blocks(hashes)
+ blocks = cache.blocks(hashes, true)
hashMap[block4.Hash] = struct{}{}
if len(blocks) != 3 {
t.Errorf("fail to get blocks: have %d, want 3", len(blocks))
@@ -196,7 +196,7 @@ func TestCacheBlock(t *testing.T) {
if err := db.PutBlock(*block5); err != nil {
panic(err)
}
- blocks = cache.blocks(coreCommon.Hashes{block5.Hash})
+ blocks = cache.blocks(coreCommon.Hashes{block5.Hash}, true)
if len(blocks) != 1 {
t.Errorf("fail to get blocks: have %d, want 1", len(blocks))
} else {
@@ -204,6 +204,10 @@ func TestCacheBlock(t *testing.T) {
t.Errorf("get wrong block: have %s, want %s", blocks[0], block5)
}
}
+ blocks = cache.blocks(coreCommon.Hashes{block5.Hash}, false)
+ if len(blocks) != 0 {
+ t.Errorf("unexpected length of blocks: have %d, want 0", len(blocks))
+ }
}
func TestCacheFinalizedBlock(t *testing.T) {
@@ -274,7 +278,7 @@ func TestCacheFinalizedBlock(t *testing.T) {
if block := cache.finalizedBlock(block5.Position); block != nil {
t.Errorf("unexpected block %s in cache", block)
}
- blocks := cache.blocks(coreCommon.Hashes{block5.Hash})
+ blocks := cache.blocks(coreCommon.Hashes{block5.Hash}, true)
if len(blocks) != 1 {
t.Errorf("fail to get blocks: have %d, want 1", len(blocks))
} else {
@@ -296,7 +300,7 @@ func TestCacheFinalizedBlock(t *testing.T) {
block.Randomness,
finalizedBlock5.Randomness)
}
- blocks = cache.blocks(coreCommon.Hashes{block5.Hash})
+ blocks = cache.blocks(coreCommon.Hashes{block5.Hash}, true)
if len(blocks) != 1 {
t.Errorf("fail to get blocks: have %d, want 1", len(blocks))
} else {