github.com/turingchain2020/turingchain@v1.1.21/blockchain/reduce_real_test.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package blockchain_test 6 7 import ( 8 "testing" 9 10 "github.com/turingchain2020/turingchain/blockchain" 11 "github.com/turingchain2020/turingchain/util" 12 "github.com/turingchain2020/turingchain/util/testnode" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestTryReduceLocalDB(t *testing.T) { 17 cfg := testnode.GetDefaultConfig() 18 mock33 := testnode.NewWithConfig(cfg, nil) 19 //ειδΊ€ζ 20 chain := mock33.GetBlockChain() 21 db := chain.GetDB() 22 kvs := getAllKeys(db) 23 assert.Equal(t, len(kvs), kvCount) 24 defer mock33.Close() 25 26 blockchain.ReduceHeight = 0 27 defer func() { 28 blockchain.ReduceHeight = 10000 29 }() 30 31 var flagHeight int64 32 count := 10 33 for i := 0; i < 2; i++ { 34 txs := util.GenCoinsTxs(cfg, mock33.GetGenesisKey(), int64(count)) 35 for j := 0; j < len(txs); j++ { 36 reply, err := mock33.GetAPI().SendTx(txs[j]) 37 assert.Nil(t, err) 38 assert.Equal(t, reply.IsOk, true) 39 waitH := i*count + (j + 1) 40 mock33.WaitHeight(int64(waitH)) 41 } 42 flagHeight = chain.TryReduceLocalDB(flagHeight, int64(count)) 43 assert.Equal(t, flagHeight, int64((i+1)*count+1)) 44 } 45 }