Skip to content

Commit

Permalink
tests: add eda client e2e test for waitForConfirmationDepth feature
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Oct 19, 2024
1 parent 45c940c commit fbb1851
Showing 1 changed file with 59 additions and 19 deletions.
78 changes: 59 additions & 19 deletions api/clients/eigenda_client_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package clients_test
package clients

import (
"context"
"flag"
"math/big"
"os"
"testing"
"time"

"github.com/Layr-Labs/eigenda/api/clients"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
)
Expand All @@ -22,22 +23,61 @@ func TestClientUsingTestnet(t *testing.T) {
if !runTestnetIntegrationTests {
t.Skip("Skipping testnet integration test")
}
logger := log.NewLogger(log.NewTerminalHandler(os.Stderr, true))
client, err := clients.NewEigenDAClient(logger, clients.EigenDAClientConfig{
RPC: "disperser-holesky.eigenda.xyz:443",
StatusQueryTimeout: 25 * time.Minute,
StatusQueryRetryInterval: 5 * time.Second,
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "2d23e142a9e86a9175b9dfa213f20ea01f6c1731e09fa6edf895f70fe279cbb1",
WaitForFinalization: true,

t.Run("PutBlobWaitForFinalityAndGetBlob", func(t *testing.T) {
t.Parallel()
logger := log.NewLogger(log.NewTerminalHandler(os.Stdout, true))
client, err := NewEigenDAClient(logger, EigenDAClientConfig{
RPC: "disperser-holesky.eigenda.xyz:443",
StatusQueryTimeout: 25 * time.Minute,
StatusQueryRetryInterval: 5 * time.Second,
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "2d23e142a9e86a9175b9dfa213f20ea01f6c1731e09fa6edf895f70fe279cbb1",
WaitForFinalization: true,
})
data := "hello world!"
assert.NoError(t, err)
blobInfo, err := client.PutBlob(context.Background(), []byte(data))
assert.NoError(t, err)
batchHeaderHash := blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash
blobIndex := blobInfo.BlobVerificationProof.BlobIndex
blob, err := client.GetBlob(context.Background(), batchHeaderHash, blobIndex)
assert.NoError(t, err)
assert.Equal(t, data, string(blob))
})

t.Run("PutBlobWaitForConfirmationDepthAndGetBlob", func(t *testing.T) {
t.Parallel()
confDepth := uint64(3)
logger := log.NewLogger(log.NewTerminalHandler(os.Stdout, true))
client, err := NewEigenDAClient(logger, EigenDAClientConfig{
RPC: "disperser-holesky.eigenda.xyz:443",
StatusQueryTimeout: 25 * time.Minute,
StatusQueryRetryInterval: 5 * time.Second,
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "2d23e142a9e86a9175b9dfa213f20ea01f6c1731e09fa6edf895f70fe279cbb1",
WaitForFinalization: false,
WaitForConfirmationDepth: confDepth,
SvcManagerAddr: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b",
EthRpcUrl: "https://1rpc.io/holesky",
})
data := "hello world!"
assert.NoError(t, err)
blobInfo, err := client.PutBlob(context.Background(), []byte(data))
assert.NoError(t, err)
batchHeaderHash := blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash
blobIndex := blobInfo.BlobVerificationProof.BlobIndex
blob, err := client.GetBlob(context.Background(), batchHeaderHash, blobIndex)
assert.NoError(t, err)
assert.Equal(t, data, string(blob))

// assert confirmation depth
blockNumCur, err := client.ethClient.BlockNumber(context.Background())
assert.NoError(t, err)
blockNumAtDepth := new(big.Int).SetUint64(blockNumCur - confDepth)
batchId := blobInfo.BlobVerificationProof.GetBatchId()
onchainBatchMetadataHash, err := client.edasmCaller.BatchIdToBatchMetadataHash(&bind.CallOpts{BlockNumber: blockNumAtDepth}, batchId)
assert.NoError(t, err)
assert.NotEqual(t, onchainBatchMetadataHash, make([]byte, 32))
})
data := "hello world!"
assert.NoError(t, err)
blobInfo, err := client.PutBlob(context.Background(), []byte(data))
assert.NoError(t, err)
batchHeaderHash := blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash
blobIndex := blobInfo.BlobVerificationProof.BlobIndex
blob, err := client.GetBlob(context.Background(), batchHeaderHash, blobIndex)
assert.NoError(t, err)
assert.Equal(t, data, string(blob))
}

0 comments on commit fbb1851

Please sign in to comment.