@@ -17,6 +17,7 @@ import (
17
17
"github.com/Layr-Labs/eigenda/core/mock"
18
18
"github.com/Layr-Labs/eigenda/inabox/deploy"
19
19
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
20
+ gethcommon "github.com/ethereum/go-ethereum/common"
20
21
"github.com/ethereum/go-ethereum/crypto"
21
22
"github.com/ory/dockertest/v3"
22
23
"github.com/stretchr/testify/assert"
@@ -30,12 +31,12 @@ var (
30
31
dockertestResource * dockertest.Resource
31
32
dynamoClient commondynamodb.Client
32
33
clientConfig commonaws.ClientConfig
33
- accountID1 string
34
- account1Reservations core.ActiveReservation
35
- account1OnDemandPayments core.OnDemandPayment
36
- accountID2 string
37
- account2Reservations core.ActiveReservation
38
- account2OnDemandPayments core.OnDemandPayment
34
+ accountID1 gethcommon. Address
35
+ account1Reservations * core.ActiveReservation
36
+ account1OnDemandPayments * core.OnDemandPayment
37
+ accountID2 gethcommon. Address
38
+ account2Reservations * core.ActiveReservation
39
+ account2OnDemandPayments * core.OnDemandPayment
39
40
mt * meterer.Meterer
40
41
41
42
deployLocalStack bool
@@ -123,12 +124,12 @@ func setup(_ *testing.M) {
123
124
}
124
125
125
126
now := uint64 (time .Now ().Unix ())
126
- accountID1 = crypto .PubkeyToAddress (privateKey1 .PublicKey ). Hex ()
127
- accountID2 = crypto .PubkeyToAddress (privateKey2 .PublicKey ). Hex ()
128
- account1Reservations = core.ActiveReservation {SymbolsPerSecond : 100 , StartTimestamp : now + 1200 , EndTimestamp : now + 1800 , QuorumSplits : []byte {50 , 50 }, QuorumNumbers : []uint8 {0 , 1 }}
129
- account2Reservations = core.ActiveReservation {SymbolsPerSecond : 200 , StartTimestamp : now - 120 , EndTimestamp : now + 180 , QuorumSplits : []byte {30 , 70 }, QuorumNumbers : []uint8 {0 , 1 }}
130
- account1OnDemandPayments = core.OnDemandPayment {CumulativePayment : big .NewInt (3864 )}
131
- account2OnDemandPayments = core.OnDemandPayment {CumulativePayment : big .NewInt (2000 )}
127
+ accountID1 = crypto .PubkeyToAddress (privateKey1 .PublicKey )
128
+ accountID2 = crypto .PubkeyToAddress (privateKey2 .PublicKey )
129
+ account1Reservations = & core.ActiveReservation {SymbolsPerSecond : 100 , StartTimestamp : now + 1200 , EndTimestamp : now + 1800 , QuorumSplits : []byte {50 , 50 }, QuorumNumbers : []uint8 {0 , 1 }}
130
+ account2Reservations = & core.ActiveReservation {SymbolsPerSecond : 200 , StartTimestamp : now - 120 , EndTimestamp : now + 180 , QuorumSplits : []byte {30 , 70 }, QuorumNumbers : []uint8 {0 , 1 }}
131
+ account1OnDemandPayments = & core.OnDemandPayment {CumulativePayment : big .NewInt (3864 )}
132
+ account2OnDemandPayments = & core.OnDemandPayment {CumulativePayment : big .NewInt (2000 )}
132
133
133
134
store , err := meterer .NewOffchainStore (
134
135
clientConfig ,
@@ -176,13 +177,13 @@ func TestMetererReservations(t *testing.T) {
176
177
binIndex := meterer .GetBinIndex (uint64 (time .Now ().Unix ()), mt .ChainPaymentState .GetReservationWindow ())
177
178
quoromNumbers := []uint8 {0 , 1 }
178
179
179
- paymentChainState .On ("GetActiveReservationByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account string ) bool {
180
+ paymentChainState .On ("GetActiveReservationByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account gethcommon. Address ) bool {
180
181
return account == accountID1
181
182
})).Return (account1Reservations , nil )
182
- paymentChainState .On ("GetActiveReservationByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account string ) bool {
183
+ paymentChainState .On ("GetActiveReservationByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account gethcommon. Address ) bool {
183
184
return account == accountID2
184
185
})).Return (account2Reservations , nil )
185
- paymentChainState .On ("GetActiveReservationByAccount" , testifymock .Anything , testifymock .Anything ).Return (core.ActiveReservation {}, fmt .Errorf ("reservation not found" ))
186
+ paymentChainState .On ("GetActiveReservationByAccount" , testifymock .Anything , testifymock .Anything ).Return (& core.ActiveReservation {}, fmt .Errorf ("reservation not found" ))
186
187
187
188
// test invalid quorom ID
188
189
header := createPaymentHeader (1 , 0 , accountID1 )
@@ -203,7 +204,7 @@ func TestMetererReservations(t *testing.T) {
203
204
if err != nil {
204
205
t .Fatalf ("Failed to generate key: %v" , err )
205
206
}
206
- header = createPaymentHeader (1 , 0 , crypto .PubkeyToAddress (unregisteredUser .PublicKey ). Hex () )
207
+ header = createPaymentHeader (1 , 0 , crypto .PubkeyToAddress (unregisteredUser .PublicKey ))
207
208
assert .NoError (t , err )
208
209
err = mt .MeterRequest (ctx , * header , 1000 , []uint8 {0 , 1 , 2 })
209
210
assert .ErrorContains (t , err , "failed to get active reservation by account: reservation not found" )
@@ -221,7 +222,7 @@ func TestMetererReservations(t *testing.T) {
221
222
err = mt .MeterRequest (ctx , * header , symbolLength , quoromNumbers )
222
223
assert .NoError (t , err )
223
224
item , err := dynamoClient .GetItem (ctx , reservationTableName , commondynamodb.Key {
224
- "AccountID" : & types.AttributeValueMemberS {Value : accountID2 },
225
+ "AccountID" : & types.AttributeValueMemberS {Value : accountID2 . Hex () },
225
226
"BinIndex" : & types.AttributeValueMemberN {Value : strconv .Itoa (int (binIndex ))},
226
227
})
227
228
assert .NoError (t , err )
@@ -237,11 +238,11 @@ func TestMetererReservations(t *testing.T) {
237
238
assert .NoError (t , err )
238
239
overflowedBinIndex := binIndex + 2
239
240
item , err := dynamoClient .GetItem (ctx , reservationTableName , commondynamodb.Key {
240
- "AccountID" : & types.AttributeValueMemberS {Value : accountID2 },
241
+ "AccountID" : & types.AttributeValueMemberS {Value : accountID2 . Hex () },
241
242
"BinIndex" : & types.AttributeValueMemberN {Value : strconv .Itoa (int (overflowedBinIndex ))},
242
243
})
243
244
assert .NoError (t , err )
244
- assert .Equal (t , accountID2 , item ["AccountID" ].(* types.AttributeValueMemberS ).Value )
245
+ assert .Equal (t , accountID2 . Hex () , item ["AccountID" ].(* types.AttributeValueMemberS ).Value )
245
246
assert .Equal (t , strconv .Itoa (int (overflowedBinIndex )), item ["BinIndex" ].(* types.AttributeValueMemberN ).Value )
246
247
// 25 rounded up to the nearest multiple of minNumSymbols - (200-21*9) = 16
247
248
assert .Equal (t , strconv .Itoa (int (16 )), item ["BinUsage" ].(* types.AttributeValueMemberN ).Value )
@@ -260,21 +261,21 @@ func TestMetererOnDemand(t *testing.T) {
260
261
paymentChainState .On ("GetMinNumSymbols" , testifymock .Anything ).Return (uint32 (3 ), nil )
261
262
binIndex := uint32 (0 ) // this field doesn't matter for on-demand payments wrt global rate limit
262
263
263
- paymentChainState .On ("GetOnDemandPaymentByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account string ) bool {
264
+ paymentChainState .On ("GetOnDemandPaymentByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account gethcommon. Address ) bool {
264
265
return account == accountID1
265
266
})).Return (account1OnDemandPayments , nil )
266
- paymentChainState .On ("GetOnDemandPaymentByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account string ) bool {
267
+ paymentChainState .On ("GetOnDemandPaymentByAccount" , testifymock .Anything , testifymock .MatchedBy (func (account gethcommon. Address ) bool {
267
268
return account == accountID2
268
269
})).Return (account2OnDemandPayments , nil )
269
- paymentChainState .On ("GetOnDemandPaymentByAccount" , testifymock .Anything , testifymock .Anything ).Return (core.OnDemandPayment {}, fmt .Errorf ("payment not found" ))
270
+ paymentChainState .On ("GetOnDemandPaymentByAccount" , testifymock .Anything , testifymock .Anything ).Return (& core.OnDemandPayment {}, fmt .Errorf ("payment not found" ))
270
271
paymentChainState .On ("GetOnDemandQuorumNumbers" , testifymock .Anything ).Return (quorumNumbers , nil )
271
272
272
273
// test unregistered account
273
274
unregisteredUser , err := crypto .GenerateKey ()
274
275
if err != nil {
275
276
t .Fatalf ("Failed to generate key: %v" , err )
276
277
}
277
- header := createPaymentHeader (binIndex , 2 , crypto .PubkeyToAddress (unregisteredUser .PublicKey ). Hex () )
278
+ header := createPaymentHeader (binIndex , 2 , crypto .PubkeyToAddress (unregisteredUser .PublicKey ))
278
279
assert .NoError (t , err )
279
280
err = mt .MeterRequest (ctx , * header , 1000 , quorumNumbers )
280
281
assert .ErrorContains (t , err , "failed to get on-demand payment by account: payment not found" )
@@ -291,7 +292,7 @@ func TestMetererOnDemand(t *testing.T) {
291
292
// No rollback after meter request
292
293
result , err := dynamoClient .Query (ctx , ondemandTableName , "AccountID = :account" , commondynamodb.ExpressionValues {
293
294
":account" : & types.AttributeValueMemberS {
294
- Value : accountID1 ,
295
+ Value : accountID1 . Hex () ,
295
296
}})
296
297
assert .NoError (t , err )
297
298
assert .Equal (t , 1 , len (result ))
@@ -336,7 +337,7 @@ func TestMetererOnDemand(t *testing.T) {
336
337
numPrevRecords := 12
337
338
result , err = dynamoClient .Query (ctx , ondemandTableName , "AccountID = :account" , commondynamodb.ExpressionValues {
338
339
":account" : & types.AttributeValueMemberS {
339
- Value : accountID2 ,
340
+ Value : accountID2 . Hex () ,
340
341
}})
341
342
assert .NoError (t , err )
342
343
assert .Equal (t , numPrevRecords , len (result ))
@@ -347,7 +348,7 @@ func TestMetererOnDemand(t *testing.T) {
347
348
// Correct rollback
348
349
result , err = dynamoClient .Query (ctx , ondemandTableName , "AccountID = :account" , commondynamodb.ExpressionValues {
349
350
":account" : & types.AttributeValueMemberS {
350
- Value : accountID2 ,
351
+ Value : accountID2 . Hex () ,
351
352
}})
352
353
assert .NoError (t , err )
353
354
assert .Equal (t , numPrevRecords , len (result ))
@@ -464,9 +465,9 @@ func TestMeterer_symbolsCharged(t *testing.T) {
464
465
}
465
466
}
466
467
467
- func createPaymentHeader (binIndex uint32 , cumulativePayment uint64 , accountID string ) * core.PaymentMetadata {
468
+ func createPaymentHeader (binIndex uint32 , cumulativePayment uint64 , accountID gethcommon. Address ) * core.PaymentMetadata {
468
469
return & core.PaymentMetadata {
469
- AccountID : accountID ,
470
+ AccountID : accountID . Hex () ,
470
471
BinIndex : binIndex ,
471
472
CumulativePayment : big .NewInt (int64 (cumulativePayment )),
472
473
}
0 commit comments