Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: round trip test for blob submission/retrieval #28

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (
"testing"
"time"

"cosmossdk.io/math"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/suite"

"github.com/rollkit/celestia-openrpc/types/blob"
"github.com/rollkit/celestia-openrpc/types/share"
)

type TestSuite struct {
Expand Down Expand Up @@ -87,15 +91,16 @@ func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
}

// TestClient is a basic smoke test, ensuring that client can execute simple methods.
func (t *TestSuite) TestClient() {
client, err := NewClient(context.Background(), t.getRPCAddress(), t.token)
t.NoError(err)
defer client.Close()

t.NotNil(client)

ctx, closer := context.WithTimeout(context.Background(), 1*time.Second)
defer closer()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

resp := client.Share.ProbabilityOfAvailability(ctx)
t.NotZero(resp)
Expand All @@ -105,6 +110,41 @@ func (t *TestSuite) TestClient() {
t.NotEmpty(info.APIVersion)
}

// TestRoundTrip tests
func (t *TestSuite) TestRoundTrip() {
client, err := NewClient(context.Background(), t.getRPCAddress(), t.token)
t.Require().NoError(err)
defer client.Close()

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

namespace, err := share.NewBlobNamespaceV0([]byte{1, 2, 3, 4, 5, 6, 7, 8})
t.Require().NoError(err)
t.Require().NotEmpty(namespace)

data := []byte("hello world")
blobBlob, err := blob.NewBlobV0(namespace, data)
t.Require().NoError(err)

// write blob to DA
txResponse, err := client.State.SubmitPayForBlob(ctx, math.NewInt(100000000), 200000000, []*blob.Blob{blobBlob})
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved
t.Require().NoError(err)
t.Require().NotNil(txResponse)
t.Zero(txResponse.Code)
t.NotZero(txResponse.Height)

ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
// retrieve data back from DA
blobs, err := client.Blob.GetAll(ctx, uint64(txResponse.Height), []share.Namespace{namespace})
t.Require().NoError(err)
t.Require().NotEmpty(blobs)
t.Len(blobs, 1)
tzdybal marked this conversation as resolved.
Show resolved Hide resolved
t.Require().NotNil(blobs[0])
t.Equal(data, blobs[0].Data)
}

func (t *TestSuite) getRPCAddress() string {
return fmt.Sprintf("http://localhost:%s", t.resource.GetPort("26658/tcp"))
}