2022-01-11 00:59:15 +00:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-11 23:49:04 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
|
|
|
|
fixt "github.com/vulcanize/eth-pg-ipfs-state-snapshot/fixture"
|
2022-02-09 15:19:10 +00:00
|
|
|
mock "github.com/vulcanize/eth-pg-ipfs-state-snapshot/mocks/snapshot"
|
|
|
|
"github.com/vulcanize/eth-pg-ipfs-state-snapshot/test"
|
2022-01-11 00:59:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig(leveldbpath, ancientdbpath string) *Config {
|
|
|
|
return &Config{
|
2022-01-11 00:59:26 +00:00
|
|
|
Eth: &EthConfig{
|
|
|
|
LevelDBPath: leveldbpath,
|
|
|
|
AncientDBPath: ancientdbpath,
|
2022-02-09 15:19:10 +00:00
|
|
|
NodeInfo: test.DefaultNodeInfo,
|
|
|
|
},
|
|
|
|
DB: &DBConfig{
|
|
|
|
URI: test.DefaultPgConfig.DbConnectionString(),
|
|
|
|
ConnConfig: test.DefaultPgConfig,
|
2022-01-11 00:59:26 +00:00
|
|
|
},
|
2022-01-11 00:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateSnapshot(t *testing.T) {
|
2022-02-09 15:19:10 +00:00
|
|
|
config := testConfig(fixt.ChaindataPath, fixt.AncientdataPath)
|
2022-01-11 23:49:04 +00:00
|
|
|
|
|
|
|
edb, err := NewLevelDB(config.Eth)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-02-09 15:19:10 +00:00
|
|
|
workers := 4
|
|
|
|
|
|
|
|
ctl := gomock.NewController(t)
|
|
|
|
tx := mock.NewMockTx(ctl)
|
|
|
|
pub := mock.NewMockPublisher(ctl)
|
2022-01-11 23:49:04 +00:00
|
|
|
|
2022-02-09 15:19:10 +00:00
|
|
|
pub.EXPECT().PublishHeader(gomock.Eq(&fixt.Header1))
|
2022-01-11 23:49:04 +00:00
|
|
|
pub.EXPECT().BeginTx().
|
2022-02-09 15:19:10 +00:00
|
|
|
Return(tx, nil).
|
2022-01-11 23:49:04 +00:00
|
|
|
Times(workers)
|
|
|
|
pub.EXPECT().PrepareTxForBatch(gomock.Any(), gomock.Any()).
|
2022-02-09 15:19:10 +00:00
|
|
|
Return(tx, nil).
|
2022-01-11 23:49:04 +00:00
|
|
|
Times(workers)
|
2022-02-09 15:19:10 +00:00
|
|
|
pub.EXPECT().PublishStateNode(gomock.Any(), gomock.Any(), gomock.Any()).
|
2022-01-11 23:49:04 +00:00
|
|
|
Times(workers)
|
2022-01-16 23:54:55 +00:00
|
|
|
// TODO: fixtures for storage node
|
|
|
|
// pub.EXPECT().PublishStorageNode(gomock.Eq(fixt.StorageNode), gomock.Eq(int64(0)), gomock.Any())
|
2022-02-09 15:19:10 +00:00
|
|
|
// pub.EXPECT().CommitTx(gomock.Any()).
|
|
|
|
// Times(workers)
|
|
|
|
|
|
|
|
tx.EXPECT().Commit().
|
2022-01-11 23:49:04 +00:00
|
|
|
Times(workers)
|
2022-01-11 00:59:15 +00:00
|
|
|
|
2022-01-11 23:49:04 +00:00
|
|
|
service, err := NewSnapshotService(edb, pub)
|
2022-01-11 00:59:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-01-11 23:49:04 +00:00
|
|
|
params := SnapshotParams{Height: 1, Workers: uint(workers)}
|
2022-01-11 00:59:15 +00:00
|
|
|
err = service.CreateSnapshot(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// err = service.CreateLatestSnapshot(0)
|
|
|
|
// if err != nil {
|
2022-02-09 15:19:10 +00:00
|
|
|
// t.Fatal(err)
|
2022-01-11 00:59:15 +00:00
|
|
|
// }
|
|
|
|
}
|