Skip to content

Commit

Permalink
tests: round trip test for blob submission/retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Jul 5, 2023
1 parent af13b3c commit a0a70b7
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 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"

blob "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,40 @@ 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})
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)
t.Equal(data, blobs[0].Data)
}

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

0 comments on commit a0a70b7

Please sign in to comment.