Skip to content

Commit

Permalink
Some next fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukanus committed Mar 20, 2023
1 parent 182029f commit 67a4be5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions datastore/datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestPutGetPayload(t *testing.T) {
Proposer: payload.Trace.Message.ProposerPubkey,
Slot: structs.Slot(payload.Trace.Message.Slot),
}
err := ds.PutPayload(ctx, key, payload, time.Minute)
err = ds.PutPayload(ctx, key, payload, time.Minute)
require.NoError(t, err)

// get
Expand All @@ -57,9 +57,9 @@ func randomHeaderAndTrace() structs.HeaderAndTrace {

return structs.HeaderAndTrace{
Header: header,
Trace: &structs.BidTraceWithTimestamp{
Trace: structs.BidTraceWithTimestamp{
BidTraceExtended: structs.BidTraceExtended{
BidTrace: *block.Trace.Message,
BidTrace: block.Message,
BlockNumber: header.BlockNumber,
NumTx: 999,
},
Expand Down
36 changes: 18 additions & 18 deletions datastore/evidence/badger/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,68 @@ func TestPutGetHeaderDelivered(t *testing.T) {
store, err := dbbadger.NewDatastore("/tmp/EvidenceBadger", &dbbadger.DefaultOptions)
require.NoError(t, err)
d := badger.NewDatastore(store, store.DB, time.Hour)
blockNum := uint64(rand.Int())

h, _ := types.PayloadToPayloadHeader(&types.ExecutionPayload{
BlockNumber: uint64(rand.Int()),
})
v := types.U256Str{}
v.UnmarshalText([]byte("12395274185417459875"))
header := structs.HeaderAndTrace{
Header: h,

dt := structs.DeliveredTrace{
Trace: structs.BidTraceWithTimestamp{
BidTraceExtended: structs.BidTraceExtended{
BidTrace: types.BidTrace{
Value: v,
BlockHash: types.Hash(random32Bytes()),
ProposerPubkey: types.PublicKey(random48Bytes()),
},
BlockNumber: h.BlockNumber,
BlockNumber: blockNum,
NumTx: 999,
},
Timestamp: uint64(time.Now().UnixMicro()),
},
BlockNumber: blockNum,
}

slotInt := rand.Int()
slot := structs.Slot(slotInt)
header.Trace.Slot = uint64(slotInt)
dt.Trace.Slot = uint64(slotInt)

// get
_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{Slot: slot})
require.ErrorIs(t, err, ds.ErrNotFound)

// get by block hash
_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockHash: header.Trace.BlockHash})
_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockHash: dt.Trace.BlockHash})
require.ErrorIs(t, err, ds.ErrNotFound)

// get by block number
_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockNum: header.Header.GetBlockNumber()})
_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockNum: dt.BlockNumber})
require.ErrorIs(t, err, ds.ErrNotFound)

_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{Pubkey: header.Trace.ProposerPubkey})
_, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{Pubkey: dt.Trace.ProposerPubkey})
require.ErrorIs(t, err, ds.ErrNotFound)

// set as delivered and retrieve again
err = d.PutDelivered(ctx, slot, structs.DeliveredTrace{Trace: header.Trace, BlockNumber: header.Header.GetBlockNumber()}, time.Minute)
err = d.PutDelivered(ctx, slot, dt, time.Minute)
require.NoError(t, err)

// get
gotHeader, err := d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{Slot: slot})
require.NoError(t, err)
require.EqualValues(t, header.Trace.Value, gotHeader[0].BidTrace.Value)
require.EqualValues(t, dt.Trace.Value, gotHeader[0].BidTrace.Value)

// get by block hash
gotHeader, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockHash: header.Trace.BlockHash})
gotHeader, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockHash: dt.Trace.BlockHash})
require.NoError(t, err)
require.EqualValues(t, header.Trace.Value, gotHeader[0].BidTrace.Value)
require.EqualValues(t, dt.Trace.Value, gotHeader[0].BidTrace.Value)

// get by block number
gotHeader, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockNum: header.Header.GetBlockNumber()})
gotHeader, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{BlockNum: dt.BlockNumber})
require.NoError(t, err)
require.EqualValues(t, header.Trace.Value, gotHeader[0].BidTrace.Value)
require.EqualValues(t, dt.Trace.Value, gotHeader[0].BidTrace.Value)

gotHeader, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{Pubkey: header.Trace.ProposerPubkey})
gotHeader, err = d.GetDeliveredPayloads(ctx, uint64(slotInt+1), structs.PayloadTraceQuery{Pubkey: dt.Trace.ProposerPubkey})
require.NoError(t, err)
require.EqualValues(t, header.Trace.Value, gotHeader[0].BidTrace.Value)
require.EqualValues(t, dt.Trace.Value, gotHeader[0].BidTrace.Value)
}

func random32Bytes() (b [32]byte) {
Expand Down

0 comments on commit 67a4be5

Please sign in to comment.