-
Notifications
You must be signed in to change notification settings - Fork 194
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
payment failure cases inabox #1035
Open
hopeyen
wants to merge
5
commits into
master
Choose a base branch
from
hope/payment-failure-inabox
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,94 @@ | ||
package integration_test | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"time" | ||
|
||
"github.com/Layr-Labs/eigenda/api/clients/v2" | ||
auth "github.com/Layr-Labs/eigenda/core/auth/v2" | ||
dispv2 "github.com/Layr-Labs/eigenda/disperser/common/v2" | ||
"github.com/Layr-Labs/eigenda/encoding/utils/codec" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Inabox v2 Integration", func() { | ||
It("reservation runs out", func() { | ||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
|
||
privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdee" | ||
signer := auth.NewLocalBlobRequestSigner(privateKeyHex) | ||
|
||
disp, err := clients.NewDisperserClient(&clients.DisperserClientConfig{ | ||
Hostname: "localhost", | ||
Port: "32005", | ||
}, signer, nil, nil) | ||
Expect(err).To(BeNil()) | ||
Expect(disp).To(Not(BeNil())) | ||
|
||
data1 := make([]byte, 992) | ||
_, err = rand.Read(data1) | ||
Expect(err).To(BeNil()) | ||
data2 := make([]byte, 123) | ||
_, err = rand.Read(data2) | ||
Expect(err).To(BeNil()) | ||
|
||
paddedData1 := codec.ConvertByPaddingEmptyByte(data1) | ||
paddedData2 := codec.ConvertByPaddingEmptyByte(data2) | ||
|
||
blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0) | ||
Expect(err).To(BeNil()) | ||
Expect(key1).To(Not(BeNil())) | ||
Expect(blobStatus1).To(Not(BeNil())) | ||
Expect(*blobStatus1).To(Equal(dispv2.Queued)) | ||
|
||
blobStatus2, key2, err := disp.DisperseBlob(ctx, paddedData2, 0, []uint8{0}, 0) | ||
Expect(err).To(BeNil()) | ||
Expect(key2).To(Not(BeNil())) | ||
Expect(blobStatus2).To(Not(BeNil())) | ||
Expect(*blobStatus2).To(Equal(dispv2.Queued)) | ||
|
||
blobStatus3, key3, err := disp.DisperseBlob(ctx, paddedData2, 0, []uint8{0}, 0) | ||
Expect(err.Error()).To(ContainSubstring("neither reservation nor on-demand payment is available")) | ||
Expect(key3).To(Not(BeNil())) | ||
Expect(blobStatus3).To(BeNil()) | ||
}) | ||
|
||
It("ondemand runs out", func() { | ||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
|
||
privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | ||
signer := auth.NewLocalBlobRequestSigner(privateKeyHex) | ||
|
||
disp, err := clients.NewDisperserClient(&clients.DisperserClientConfig{ | ||
Hostname: "localhost", | ||
Port: "32005", | ||
}, signer, nil, nil) | ||
Expect(err).To(BeNil()) | ||
Expect(disp).To(Not(BeNil())) | ||
|
||
data1 := make([]byte, 992) | ||
_, err = rand.Read(data1) | ||
Expect(err).To(BeNil()) | ||
data2 := make([]byte, 123) | ||
_, err = rand.Read(data2) | ||
Expect(err).To(BeNil()) | ||
|
||
paddedData1 := codec.ConvertByPaddingEmptyByte(data1) | ||
paddedData2 := codec.ConvertByPaddingEmptyByte(data2) | ||
|
||
blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0) | ||
Expect(err).To(BeNil()) | ||
Expect(key1).To(Not(BeNil())) | ||
Expect(blobStatus1).To(Not(BeNil())) | ||
Expect(*blobStatus1).To(Equal(dispv2.Queued)) | ||
|
||
blobStatus2, key2, err := disp.DisperseBlob(ctx, paddedData2, 0, []uint8{0}, 0) | ||
Expect(err.Error()).To(ContainSubstring("neither reservation nor on-demand payment is available")) | ||
Expect(blobStatus2).To(BeNil()) | ||
Expect(key2).To(Not(BeNil())) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these tests could be moved to unit tests? like in
accountant_test.go
?Also, should we also test payment failure cases from disperser server if there isn't already? (to cover the case that user isn't running accountatnt)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I made these tests for the interaction of disperser client and the server, and shows when a blob should be dispersed and when it should fail with respect to payments. I don't think they could be moved to unit test.
Disperser client would build accountant if it wasn't provided with one, so alternatively we could add rogue accountant implementations that makes invalid payment headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the server logic relevant in these tests? It looks like they mostly test the accountant logic (server could have the payment metering disabled and allowed all requests and these tests would still pass)
Yes, but not all requests may originate from the disperser client shipped in this repo. Anyone is free to disperse blobs without running accountant, in which case, API server should enforce correct metering scheme. I was referring to payment failure cases from the API server payment metering, not from the accountant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I understood your concerns. I updated the tests to override the accountant with erroneous payment state so that accountant doesn't account correctly, and focus on testing failures from API server logic. (if payment is disabled, the tests should not pass as the expected failure would instead be nil)
by this logic, should we have a set of tests that doesn't use DisperserClient? The existing tests all utilize
NewDisperserClient
to make API requests