You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

72 lines
1.6 KiB

package synchronizer
import (
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/hermeznetwork/hermez-node/db/historydb"
"github.com/hermeznetwork/hermez-node/db/statedb"
"github.com/hermeznetwork/hermez-node/eth"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test(t *testing.T) {
// Int State DB
dir, err := ioutil.TempDir("", "tmpdb")
require.Nil(t, err)
sdb, err := statedb.NewStateDB(dir, true, 32)
assert.Nil(t, err)
// Init History DB
pass := os.Getenv("POSTGRES_PASS")
historyDB, err := historydb.NewHistoryDB(5432, "localhost", "hermez", pass, "history")
require.Nil(t, err)
err = historyDB.Reorg(0)
assert.Nil(t, err)
// Init eth client
ehtClientDialURL := os.Getenv("ETHCLIENT_DIAL_URL")
ethClient, err := ethclient.Dial(ehtClientDialURL)
require.Nil(t, err)
client := eth.NewClient(ethClient, nil, nil, nil)
// Create Synchronizer
s := NewSynchronizer(client, historyDB, sdb)
// Test Sync
err = s.Sync()
require.Nil(t, err)
// TODO: Reorg will be properly tested once we have the mock ethClient implemented
/*
// Force a Reorg
lastSavedBlock, err := historyDB.GetLastBlock()
require.Nil(t, err)
lastSavedBlock.EthBlockNum++
err = historyDB.AddBlock(lastSavedBlock)
require.Nil(t, err)
lastSavedBlock.EthBlockNum++
err = historyDB.AddBlock(lastSavedBlock)
require.Nil(t, err)
log.Debugf("Wait for the blockchain to generate some blocks...")
time.Sleep(40 * time.Second)
err = s.Sync()
require.Nil(t, err)
*/
// Close History DB
if err := historyDB.Close(); err != nil {
fmt.Println("Error closing the history DB:", err)
}
}