Skip to content

Commit

Permalink
Temp updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgoStephenAkiki committed Feb 2, 2023
1 parent 01b06eb commit b46cb57
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 105 deletions.
27 changes: 20 additions & 7 deletions conduit/plugins/importers/algod/algod_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ import (
)

const (
importerName = "algod"
archivalMode = "archival"
followerMode = "follower"
importerName = "algod"
archivalModeStr = "archival"
followerModeStr = "follower"
)

const (
archivalMode = iota
followerMode
)

type algodImporter struct {
Expand All @@ -36,6 +41,7 @@ type algodImporter struct {
cfg Config
ctx context.Context
cancel context.CancelFunc
mode int
}

//go:embed sample.yaml
Expand All @@ -54,7 +60,7 @@ func New() importers.Importer {
}

func (algodImp *algodImporter) OnComplete(input data.BlockData) error {
if algodImp.cfg.Mode != followerMode {
if algodImp.mode != followerMode {
return nil
}
_, err := algodImp.aclient.SetSyncRound(input.Round() + 1).Do(algodImp.ctx)
Expand Down Expand Up @@ -82,10 +88,17 @@ func (algodImp *algodImporter) Init(ctx context.Context, cfg plugins.PluginConfi

// To support backwards compatibility with the daemon we default to archival mode
if algodImp.cfg.Mode == "" {
algodImp.cfg.Mode = archivalMode
algodImp.cfg.Mode = archivalModeStr
}

if algodImp.cfg.Mode != archivalMode && algodImp.cfg.Mode != followerMode {
switch algodImp.cfg.Mode {
case archivalModeStr:
algodImp.mode = archivalMode
break
case followerModeStr:
algodImp.mode = followerMode
break
default:
return nil, fmt.Errorf("algod importer was set to a mode (%s) that wasn't supported", algodImp.cfg.Mode)
}

Expand Down Expand Up @@ -166,7 +179,7 @@ func (algodImp *algodImporter) GetBlock(rnd uint64) (data.BlockData, error) {
return blk, err
}

if algodImp.cfg.Mode == followerMode {
if algodImp.mode == followerMode {
// We aren't going to do anything with the new delta until we get everything
// else converted over
// Round 0 has no delta associated with it
Expand Down
140 changes: 42 additions & 98 deletions conduit/plugins/importers/algod/algod_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,16 @@ func TestImporterMetadata(t *testing.T) {
}

func TestCloseSuccess(t *testing.T) {
tests := []struct {
name string
}{
{"archival"},
{"follower"},
}
for _, ttest := range tests {
t.Run(ttest.name, func(t *testing.T) {
ts := test.NewAlgodServer(test.GenesisResponder)
testImporter := New()
cfgStr := fmt.Sprintf(`---
ts := test.NewAlgodServer(test.GenesisResponder)
testImporter := New()
cfgStr := fmt.Sprintf(`---
mode: %s
netaddr: %s
`, ttest.name, ts.URL)
_, err := testImporter.Init(ctx, plugins.MakePluginConfig(cfgStr), logger)
assert.NoError(t, err)
err = testImporter.Close()
assert.NoError(t, err)
})
}
`, archivalModeStr, ts.URL)
_, err := testImporter.Init(ctx, plugins.MakePluginConfig(cfgStr), logger)
assert.NoError(t, err)
err = testImporter.Close()
assert.NoError(t, err)
}

func TestInitSuccess(t *testing.T) {
Expand All @@ -85,96 +75,60 @@ netaddr: %s
}

func TestInitGenesisFailure(t *testing.T) {
tests := []struct {
name string
}{
{"archival"},
{"follower"},
}
for _, ttest := range tests {
t.Run(ttest.name, func(t *testing.T) {
ts := test.NewAlgodServer(test.MakeGenesisResponder(sdk.Genesis{}))
testImporter := New()
cfgStr := fmt.Sprintf(`---
ts := test.NewAlgodServer(test.MakeGenesisResponder(sdk.Genesis{}))
testImporter := New()
cfgStr := fmt.Sprintf(`---
mode: %s
netaddr: %s
`, ttest.name, ts.URL)
_, err := testImporter.Init(ctx, plugins.MakePluginConfig(cfgStr), logger)
assert.Error(t, err)
assert.ErrorContains(t, err, "unable to fetch genesis file")
testImporter.Close()
})
}
`, archivalModeStr, ts.URL)
_, err := testImporter.Init(ctx, plugins.MakePluginConfig(cfgStr), logger)
assert.Error(t, err)
assert.ErrorContains(t, err, "unable to fetch genesis file")
testImporter.Close()
}

func TestInitUnmarshalFailure(t *testing.T) {
tests := []struct {
name string
}{
{"archival"},
{"follower"},
}
for _, ttest := range tests {
t.Run(ttest.name, func(t *testing.T) {
testImporter := New()
_, err := testImporter.Init(ctx, plugins.MakePluginConfig("`"), logger)
assert.Error(t, err)
assert.ErrorContains(t, err, "connect failure in unmarshalConfig")
testImporter.Close()
})
}
testImporter := New()
_, err := testImporter.Init(ctx, plugins.MakePluginConfig("`"), logger)
assert.Error(t, err)
assert.ErrorContains(t, err, "connect failure in unmarshalConfig")
testImporter.Close()
}

func TestConfigDefault(t *testing.T) {
tests := []struct {
name string
}{
{"archival"},
{"follower"},
}
for _, ttest := range tests {
t.Run(ttest.name, func(t *testing.T) {
testImporter := New()
expected, err := yaml.Marshal(&Config{})
if err != nil {
t.Fatalf("unable to Marshal default algodimporter.Config: %v", err)
}
assert.Equal(t, string(expected), testImporter.Config())
})
testImporter := New()
expected, err := yaml.Marshal(&Config{})
if err != nil {
t.Fatalf("unable to Marshal default algodimporter.Config: %v", err)
}
assert.Equal(t, string(expected), testImporter.Config())
}

func TestWaitForBlockBlockFailure(t *testing.T) {
tests := []struct {
name string
}{
{"archival"},
{"follower"},
}
for _, ttest := range tests {
t.Run(ttest.name, func(t *testing.T) {
ts := test.NewAlgodServer(test.GenesisResponder)
testImporter := New()
cfgStr := fmt.Sprintf(`---
ts := test.NewAlgodServer(test.GenesisResponder)
testImporter := New()
cfgStr := fmt.Sprintf(`---
mode: %s
netaddr: %s
`, ttest.name, ts.URL)
_, err := testImporter.Init(ctx, plugins.MakePluginConfig(cfgStr), logger)
assert.NoError(t, err)
assert.NotEqual(t, testImporter, nil)
`, archivalModeStr, ts.URL)
_, err := testImporter.Init(ctx, plugins.MakePluginConfig(cfgStr), logger)
assert.NoError(t, err)
assert.NotEqual(t, testImporter, nil)

blk, err := testImporter.GetBlock(uint64(10))
assert.Error(t, err)
assert.True(t, blk.Empty())

blk, err := testImporter.GetBlock(uint64(10))
assert.Error(t, err)
assert.True(t, blk.Empty())
})
}
}

func TestGetBlockSuccess(t *testing.T) {
tests := []struct {
name string
algodServer *httptest.Server
}{
{"", test.NewAlgodServer(test.GenesisResponder,
test.BlockResponder,
test.BlockAfterResponder)},
{"archival", test.NewAlgodServer(test.GenesisResponder,
test.BlockResponder,
test.BlockAfterResponder)},
Expand Down Expand Up @@ -267,16 +221,6 @@ netaddr: %s
}

func TestAlgodImporter_ProvideMetrics(t *testing.T) {
tests := []struct {
name string
}{
{"archival"},
{"follower"},
}
for _, ttest := range tests {
t.Run(ttest.name, func(t *testing.T) {
testImporter := &algodImporter{}
assert.Len(t, testImporter.ProvideMetrics("blah"), 1)
})
}
testImporter := &algodImporter{}
assert.Len(t, testImporter.ProvideMetrics("blah"), 1)
}

0 comments on commit b46cb57

Please sign in to comment.