Update import test

This commit is contained in:
Aleksandr Bezobchuk 2018-10-24 08:30:52 -04:00
parent 9b11fe88bd
commit d017bc7de5

View File

@ -6,8 +6,10 @@ import (
"io" "io"
"math/big" "math/big"
"os" "os"
"os/signal"
"runtime/pprof" "runtime/pprof"
"sort" "sort"
"syscall"
"testing" "testing"
"time" "time"
@ -71,6 +73,26 @@ func newTestCodec() *wire.Codec {
return codec return codec
} }
func cleanup() {
fmt.Println("cleaning up test execution...")
os.RemoveAll(flagDataDir)
if flagCPUProfile != "" {
pprof.StopCPUProfile()
}
}
func trapSignals() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
cleanup()
os.Exit(1)
}()
}
func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, am auth.AccountMapper) { func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, am auth.AccountMapper) {
genBlock := ethcore.DefaultGenesisBlock() genBlock := ethcore.DefaultGenesisBlock()
ms := cms.CacheMultiStore() ms := cms.CacheMultiStore()
@ -117,7 +139,7 @@ func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, am auth.Accoun
// persist multi-store root state // persist multi-store root state
commitID := cms.Commit() commitID := cms.Commit()
require.Equal(t, "F162678AD57BBE352BE0CFCFCD90E394C4781D31", fmt.Sprintf("%X", commitID.Hash)) require.Equal(t, "9871F7F6A9901BFA9BDFF2269A3351CDD901B3AD", fmt.Sprintf("%X", commitID.Hash))
// verify account mapper state // verify account mapper state
genAcc := am.GetAccount(ctx, sdk.AccAddress(genInvestor.Bytes())) genAcc := am.GetAccount(ctx, sdk.AccAddress(genInvestor.Bytes()))
@ -139,11 +161,8 @@ func TestImportBlocks(t *testing.T) {
} }
db := dbm.NewDB("state", dbm.LevelDBBackend, flagDataDir) db := dbm.NewDB("state", dbm.LevelDBBackend, flagDataDir)
defer func() { defer cleanup()
fmt.Println("cleaning up") trapSignals()
os.RemoveAll(flagDataDir)
pprof.StopCPUProfile()
}()
// create logger, codec and root multi-store // create logger, codec and root multi-store
cdc := newTestCodec() cdc := newTestCodec()