-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add neutron fetcher test (#99)
- Loading branch information
1 parent
ac3cc75
commit 5866285
Showing
18 changed files
with
432 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":{"threshold":{"threshold_quorum":{"threshold":{"percent":"0.5"},"quorum":{"percent":"0.1"}}},"max_voting_period":{"time":1209600},"min_voting_period":null,"allow_revoting":true,"dao":"neutron1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrstdxvff","close_proposal_on_execution_failure":true}} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":{"vote":null}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":{"vote":{"voter":"neutron103l025fw2x7d8k8px7d07vu667x0h5p5gke4yv","vote":"yes","power":"3069"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":{"vote":{"voter":"neutron103l025fw2x7d8k8px7d07vu667x0h5p5gke4yv","vote":"unknown","power":"3069"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package fetchers | ||
|
||
import ( | ||
"main/pkg/fetchers/cosmos" | ||
"main/pkg/fetchers/neutron" | ||
loggerPkg "main/pkg/logger" | ||
"main/pkg/tracing" | ||
"main/pkg/types" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetFetcher(t *testing.T) { | ||
t.Parallel() | ||
|
||
logger := loggerPkg.GetNopLogger() | ||
tracer := tracing.InitNoopTracer() | ||
|
||
neutronFetcher := GetFetcher(&types.Chain{Type: "neutron"}, logger, tracer) | ||
assert.IsType(t, &neutron.Fetcher{}, neutronFetcher) | ||
|
||
cosmosFetcher := GetFetcher(&types.Chain{}, logger, tracer) | ||
assert.IsType(t, &cosmos.RPC{}, cosmosFetcher) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package neutron | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"main/assets" | ||
loggerPkg "main/pkg/logger" | ||
"main/pkg/tracing" | ||
"main/pkg/types" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jarcoal/httpmock" | ||
) | ||
|
||
//nolint:paralleltest // disabled due to httpmock usage | ||
func TestParamsFail(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
config := &types.Chain{ | ||
Name: "chain", | ||
LCDEndpoints: []string{"https://example.com"}, | ||
NeutronSmartContract: "neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh", | ||
} | ||
logger := loggerPkg.GetNopLogger() | ||
tracer := tracing.InitNoopTracer() | ||
|
||
fetcher := NewFetcher(config, logger, tracer) | ||
|
||
httpmock.RegisterResponder( | ||
"GET", | ||
"https://example.com/cosmwasm/wasm/v1/contract/neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh/smart/eyJjb25maWciOnt9fQ==", | ||
httpmock.NewErrorResponder(errors.New("custom error")), | ||
) | ||
|
||
params, errs := fetcher.GetChainParams(context.Background()) | ||
|
||
require.Len(t, errs, 1) | ||
require.ErrorContains(t, errs[0], "custom error") | ||
require.Nil(t, params) | ||
} | ||
|
||
//nolint:paralleltest // disabled due to httpmock usage | ||
func TestParamsOk(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
config := &types.Chain{ | ||
Name: "chain", | ||
LCDEndpoints: []string{"https://example.com"}, | ||
NeutronSmartContract: "neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh", | ||
} | ||
logger := loggerPkg.GetNopLogger() | ||
tracer := tracing.InitNoopTracer() | ||
|
||
fetcher := NewFetcher(config, logger, tracer) | ||
|
||
httpmock.RegisterResponder( | ||
"GET", | ||
"https://example.com/cosmwasm/wasm/v1/contract/neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh/smart/eyJjb25maWciOnt9fQ==", | ||
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("neutron-params.json")), | ||
) | ||
|
||
params, err := fetcher.GetChainParams(context.Background()) | ||
|
||
require.Empty(t, err) | ||
require.NotNil(t, params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package neutron | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"main/assets" | ||
loggerPkg "main/pkg/logger" | ||
"main/pkg/tracing" | ||
"main/pkg/types" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jarcoal/httpmock" | ||
) | ||
|
||
//nolint:paralleltest // disabled due to httpmock usage | ||
func TestProposalsFail(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
config := &types.Chain{ | ||
Name: "chain", | ||
LCDEndpoints: []string{"https://example.com"}, | ||
NeutronSmartContract: "neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh", | ||
} | ||
logger := loggerPkg.GetNopLogger() | ||
tracer := tracing.InitNoopTracer() | ||
|
||
fetcher := NewFetcher(config, logger, tracer) | ||
|
||
httpmock.RegisterResponder( | ||
"GET", | ||
"https://example.com/cosmwasm/wasm/v1/contract/neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh/smart/eyJyZXZlcnNlX3Byb3Bvc2FscyI6IHsibGltaXQiOiAxMDAwfX0=", | ||
httpmock.NewErrorResponder(errors.New("custom error")), | ||
) | ||
|
||
proposals, height, err := fetcher.GetAllProposals(0, context.Background()) | ||
|
||
require.Error(t, err) | ||
require.Len(t, err.NodeErrors, 1) | ||
|
||
firstError := err.NodeErrors[0].Error | ||
require.ErrorContains(t, &firstError, "custom error") | ||
require.Zero(t, height) | ||
require.Empty(t, proposals) | ||
} | ||
|
||
//nolint:paralleltest // disabled due to httpmock usage | ||
func TestProposalsOk(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
config := &types.Chain{ | ||
Name: "chain", | ||
LCDEndpoints: []string{"https://example.com"}, | ||
NeutronSmartContract: "neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh", | ||
} | ||
logger := loggerPkg.GetNopLogger() | ||
tracer := tracing.InitNoopTracer() | ||
|
||
fetcher := NewFetcher(config, logger, tracer) | ||
|
||
httpmock.RegisterResponder( | ||
"GET", | ||
"https://example.com/cosmwasm/wasm/v1/contract/neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh/smart/eyJyZXZlcnNlX3Byb3Bvc2FscyI6IHsibGltaXQiOiAxMDAwfX0=", | ||
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("neutron-proposals.json")), | ||
) | ||
|
||
proposals, height, err := fetcher.GetAllProposals(0, context.Background()) | ||
|
||
require.Empty(t, err) | ||
require.Zero(t, height) | ||
require.NotEmpty(t, proposals) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.