Skip to content

Commit

Permalink
tests: round trip test for blob submission/retrieval (#28)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

Basic round trip test that submits a blob and then reads it back from
DA.

Resolves #27.

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords
  • Loading branch information
tzdybal authored Jul 5, 2023
1 parent f89b1d9 commit 8ac4b06
Showing 1 changed file with 42 additions and 2 deletions.
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})
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.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"))
}

0 comments on commit 8ac4b06

Please sign in to comment.