OSDN Git Service

Peer add announces new block message num limit
[bytom/vapor.git] / protocol / block_test.go
index cde4188..4ee6479 100644 (file)
@@ -23,7 +23,7 @@ func (s *mStore) GetStoreStatus() *BlockStoreState                             {
 func (s *mStore) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
 func (s *mStore) GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error     { return nil }
 func (s *mStore) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)                 { return nil, nil }
-func (s *mStore) GetVoteResult(uint64) (*state.VoteResult, error)              { return nil, nil }
+func (s *mStore) GetConsensusResult(uint64) (*state.ConsensusResult, error)              { return nil, nil }
 func (s *mStore) GetMainChainHash(uint64) (*bc.Hash, error)                    { return nil, nil }
 func (s *mStore) GetBlockHashesByHeight(uint64) ([]*bc.Hash, error)            { return nil, nil }
 func (s *mStore) SaveBlock(*types.Block, *bc.TransactionStatus) error          { return nil }
@@ -31,7 +31,7 @@ func (s *mStore) SaveBlockHeader(blockHeader *types.BlockHeader) error {
        s.blockHeaders[blockHeader.Hash()] = blockHeader
        return nil
 }
-func (s *mStore) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.VoteResult) error {
+func (s *mStore) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.ConsensusResult) error {
        return nil
 }
 
@@ -71,12 +71,26 @@ func TestCalcReorganizeChain(t *testing.T) {
                c.store.SaveBlockHeader(newChainBlockHeader)
        }
 
+       // normal
        getAttachBlockHeaders, getDetachBlockHeaders, _ := c.calcReorganizeChain(newChainBlockHeader, mainChainBlockHeader)
        if !testutil.DeepEqual(wantAttachBlockHeaders, getAttachBlockHeaders) {
-               t.Errorf("attach headers want %v but get %v", wantAttachBlockHeaders, getAttachBlockHeaders)
+               t.Errorf("normal test: attach headers want %v but get %v", wantAttachBlockHeaders, getAttachBlockHeaders)
        }
 
        if !testutil.DeepEqual(wantDetachBlockHeaders, getDetachBlockHeaders) {
-               t.Errorf("detach headers want %v but get %v", wantDetachBlockHeaders, getDetachBlockHeaders)
+               t.Errorf("normal test: detach headers want %v but get %v", wantDetachBlockHeaders, getDetachBlockHeaders)
+       }
+
+       // detachBlockHeaders is empty
+       forkChainBlockHeader := wantAttachBlockHeaders[7]
+       wantAttachBlockHeaders = wantAttachBlockHeaders[8:]
+       wantDetachBlockHeaders = []*types.BlockHeader{}
+       getAttachBlockHeaders, getDetachBlockHeaders, _ = c.calcReorganizeChain(newChainBlockHeader, forkChainBlockHeader)
+       if !testutil.DeepEqual(wantAttachBlockHeaders, getAttachBlockHeaders) {
+               t.Errorf("detachBlockHeaders is empty test: attach headers want %v but get %v", wantAttachBlockHeaders, getAttachBlockHeaders)
+       }
+
+       if !testutil.DeepEqual(wantDetachBlockHeaders, getDetachBlockHeaders) {
+               t.Errorf("detachBlockHeaders is empty test: detach headers want %v but get %v", wantDetachBlockHeaders, getDetachBlockHeaders)
        }
 }