|
|
@ -3,13 +3,10 @@ package mempool |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"crypto/rand" |
|
|
|
"crypto/sha256" |
|
|
|
"encoding/binary" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
mrand "math/rand" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
|
|
|
|
@ -418,55 +415,6 @@ func TestSerialReap(t *testing.T) { |
|
|
|
reapCheck(600) |
|
|
|
} |
|
|
|
|
|
|
|
func TestMempoolCloseWAL(t *testing.T) { |
|
|
|
// 1. Create the temporary directory for mempool and WAL testing.
|
|
|
|
rootDir, err := ioutil.TempDir("", "mempool-test") |
|
|
|
require.Nil(t, err, "expecting successful tmpdir creation") |
|
|
|
|
|
|
|
// 2. Ensure that it doesn't contain any elements -- Sanity check
|
|
|
|
m1, err := filepath.Glob(filepath.Join(rootDir, "*")) |
|
|
|
require.Nil(t, err, "successful globbing expected") |
|
|
|
require.Equal(t, 0, len(m1), "no matches yet") |
|
|
|
|
|
|
|
// 3. Create the mempool
|
|
|
|
wcfg := cfg.DefaultConfig() |
|
|
|
wcfg.Mempool.RootDir = rootDir |
|
|
|
app := kvstore.NewApplication() |
|
|
|
cc := proxy.NewLocalClientCreator(app) |
|
|
|
mempool, cleanup := newMempoolWithAppAndConfig(cc, wcfg) |
|
|
|
defer cleanup() |
|
|
|
mempool.height = 10 |
|
|
|
err = mempool.InitWAL() |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
// 4. Ensure that the directory contains the WAL file
|
|
|
|
m2, err := filepath.Glob(filepath.Join(rootDir, "*")) |
|
|
|
require.Nil(t, err, "successful globbing expected") |
|
|
|
require.Equal(t, 1, len(m2), "expecting the wal match in") |
|
|
|
|
|
|
|
// 5. Write some contents to the WAL
|
|
|
|
err = mempool.CheckTx(types.Tx([]byte("foo")), nil, TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
walFilepath := mempool.wal.Path |
|
|
|
sum1 := checksumFile(walFilepath, t) |
|
|
|
|
|
|
|
// 6. Sanity check to ensure that the written TX matches the expectation.
|
|
|
|
require.Equal(t, sum1, checksumIt([]byte("foo\n")), "foo with a newline should be written") |
|
|
|
|
|
|
|
// 7. Invoke CloseWAL() and ensure it discards the
|
|
|
|
// WAL thus any other write won't go through.
|
|
|
|
mempool.CloseWAL() |
|
|
|
err = mempool.CheckTx(types.Tx([]byte("bar")), nil, TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
sum2 := checksumFile(walFilepath, t) |
|
|
|
require.Equal(t, sum1, sum2, "expected no change to the WAL after invoking CloseWAL() since it was discarded") |
|
|
|
|
|
|
|
// 8. Sanity check to ensure that the WAL file still exists
|
|
|
|
m3, err := filepath.Glob(filepath.Join(rootDir, "*")) |
|
|
|
require.Nil(t, err, "successful globbing expected") |
|
|
|
require.Equal(t, 1, len(m3), "expecting the wal match in") |
|
|
|
} |
|
|
|
|
|
|
|
func TestMempool_CheckTxChecksTxSize(t *testing.T) { |
|
|
|
app := kvstore.NewApplication() |
|
|
|
cc := proxy.NewLocalClientCreator(app) |
|
|
@ -651,17 +599,6 @@ func newRemoteApp( |
|
|
|
} |
|
|
|
return clientCreator, server |
|
|
|
} |
|
|
|
func checksumIt(data []byte) string { |
|
|
|
h := sha256.New() |
|
|
|
h.Write(data) |
|
|
|
return fmt.Sprintf("%x", h.Sum(nil)) |
|
|
|
} |
|
|
|
|
|
|
|
func checksumFile(p string, t *testing.T) string { |
|
|
|
data, err := ioutil.ReadFile(p) |
|
|
|
require.Nil(t, err, "expecting successful read of %q", p) |
|
|
|
return checksumIt(data) |
|
|
|
} |
|
|
|
|
|
|
|
func abciResponses(n int, code uint32) []*abci.ResponseDeliverTx { |
|
|
|
responses := make([]*abci.ResponseDeliverTx, 0, n) |
|
|
|