This repository was archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for historical queries
- Loading branch information
Showing
7 changed files
with
200 additions
and
8 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
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,120 @@ | ||
package rpc_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/celestiaorg/orchestrator-relayer/rpc" | ||
) | ||
|
||
func (s *HistoricQuerierTestSuite) TestQueryHistoricAttestationByNonce() { | ||
appQuerier := rpc.NewAppQuerier( | ||
s.Logger, | ||
s.Network.GRPCAddr, | ||
s.EncConf, | ||
) | ||
require.NoError(s.T(), appQuerier.Start()) | ||
defer appQuerier.Stop() //nolint:errcheck | ||
|
||
// this one should fail because the attestation is deleted from the state | ||
_, err := appQuerier.QueryAttestationByNonce(context.Background(), 1) | ||
s.Error(err) | ||
|
||
att, err := appQuerier.QueryHistoricalAttestationByNonce(context.Background(), 1, 10) | ||
s.NoError(err) | ||
s.NotNil(att) | ||
s.Equal(uint64(1), att.GetNonce()) | ||
} | ||
|
||
func (s *HistoricQuerierTestSuite) TestQueryRecursiveHistoricAttestationByNonce() { | ||
appQuerier := rpc.NewAppQuerier( | ||
s.Logger, | ||
s.Network.GRPCAddr, | ||
s.EncConf, | ||
) | ||
require.NoError(s.T(), appQuerier.Start()) | ||
defer appQuerier.Stop() //nolint:errcheck | ||
|
||
// this one should fail because the attestation is deleted from the state | ||
_, err := appQuerier.QueryAttestationByNonce(context.Background(), 1) | ||
s.Error(err) | ||
|
||
height, err := s.Network.LatestHeight() | ||
s.Require().NoError(err) | ||
att, err := appQuerier.QueryRecursiveHistoricalAttestationByNonce(context.Background(), 1, uint64(height)) | ||
s.Require().NoError(err) | ||
s.NotNil(att) | ||
s.Equal(uint64(1), att.GetNonce()) | ||
} | ||
|
||
func (s *HistoricQuerierTestSuite) TestQueryHistoricalLatestAttestationNonce() { | ||
appQuerier := rpc.NewAppQuerier( | ||
s.Logger, | ||
s.Network.GRPCAddr, | ||
s.EncConf, | ||
) | ||
require.NoError(s.T(), appQuerier.Start()) | ||
defer appQuerier.Stop() //nolint:errcheck | ||
|
||
nonce, err := appQuerier.QueryHistoricalLatestAttestationNonce(context.Background(), 2) | ||
s.Require().NoError(err) | ||
s.Equal(uint64(1), nonce) | ||
} | ||
|
||
func (s *HistoricQuerierTestSuite) TestQueryHistoricalValsetByNonce() { | ||
appQuerier := rpc.NewAppQuerier( | ||
s.Logger, | ||
s.Network.GRPCAddr, | ||
s.EncConf, | ||
) | ||
require.NoError(s.T(), appQuerier.Start()) | ||
defer appQuerier.Stop() //nolint:errcheck | ||
|
||
// this one should fail because the attestation is deleted from the state | ||
_, err := appQuerier.QueryValsetByNonce(context.Background(), 1) | ||
s.Error(err) | ||
|
||
att, err := appQuerier.QueryHistoricalValsetByNonce(context.Background(), 1, 10) | ||
s.Require().NoError(err) | ||
s.NotNil(att) | ||
s.Equal(uint64(1), att.GetNonce()) | ||
} | ||
|
||
func (s *HistoricQuerierTestSuite) TestQueryHistoricalLastValsetBeforeNonce() { | ||
appQuerier := rpc.NewAppQuerier( | ||
s.Logger, | ||
s.Network.GRPCAddr, | ||
s.EncConf, | ||
) | ||
require.NoError(s.T(), appQuerier.Start()) | ||
defer appQuerier.Stop() //nolint:errcheck | ||
|
||
// this one should fail because the attestation is deleted from the state | ||
_, err := appQuerier.QueryLastValsetBeforeNonce(context.Background(), 2) | ||
s.Error(err) | ||
|
||
att, err := appQuerier.QueryHistoricalLastValsetBeforeNonce(context.Background(), 2, 102) | ||
s.Require().NoError(err) | ||
s.NotNil(att) | ||
s.Equal(uint64(1), att.GetNonce()) | ||
} | ||
|
||
func (s *HistoricQuerierTestSuite) TestQueryRecursiveHistoricalLastValsetBeforeNonce() { | ||
appQuerier := rpc.NewAppQuerier( | ||
s.Logger, | ||
s.Network.GRPCAddr, | ||
s.EncConf, | ||
) | ||
require.NoError(s.T(), appQuerier.Start()) | ||
defer appQuerier.Stop() //nolint:errcheck | ||
|
||
// this one should fail because the attestation is deleted from the state | ||
_, err := appQuerier.QueryLastValsetBeforeNonce(context.Background(), 2) | ||
s.Error(err) | ||
|
||
att, err := appQuerier.QueryRecursiveHistoricalLastValsetBeforeNonce(context.Background(), 2, 201) | ||
s.Require().NoError(err) | ||
s.NotNil(att) | ||
s.Equal(uint64(1), att.GetNonce()) | ||
} |
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,51 @@ | ||
package rpc_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/celestiaorg/celestia-app/test/util/testnode" | ||
"github.com/celestiaorg/celestia-app/x/qgb/types" | ||
"github.com/celestiaorg/orchestrator-relayer/rpc" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
tmlog "github.com/tendermint/tendermint/libs/log" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
blobstreamtesting "github.com/celestiaorg/orchestrator-relayer/testing" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type HistoricQuerierTestSuite struct { | ||
suite.Suite | ||
Network *blobstreamtesting.CelestiaNetwork | ||
EncConf encoding.Config | ||
Logger tmlog.Logger | ||
} | ||
|
||
func (s *HistoricQuerierTestSuite) SetupSuite() { | ||
t := s.T() | ||
ctx := context.Background() | ||
s.EncConf = encoding.MakeConfig(app.ModuleEncodingRegisters...) | ||
s.Network = blobstreamtesting.NewCelestiaNetwork( | ||
ctx, | ||
t, | ||
blobstreamtesting.CelestiaNetworkParams{ | ||
GenesisOpts: []testnode.GenesisOption{blobstreamtesting.SetDataCommitmentWindowParams(s.EncConf.Codec, types.Params{DataCommitmentWindow: 101})}, | ||
TimeIotaMs: 6048000, // so that old attestations are deleted as soon as a new one appears | ||
Pruning: "nothing", // make the node an archive one | ||
TimeoutCommit: 20 * time.Millisecond, | ||
}, | ||
) | ||
_, err := s.Network.WaitForHeightWithTimeout(401, 30*time.Second) | ||
s.Logger = tmlog.NewNopLogger() | ||
require.NoError(t, err) | ||
rpc.BlocksIn20DaysPeriod = 100 | ||
} | ||
|
||
func TestHistoricQueriers(t *testing.T) { | ||
suite.Run(t, new(HistoricQuerierTestSuite)) | ||
} |
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