Skip to content

Commit

Permalink
Adds a check to ensure decay is being computed correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Mar 20, 2024
1 parent 2d75b20 commit 59441ba
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions pkg/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (h *testHasher) Hash() common.Hash {
func TestUpdater(t *testing.T) {
t.Parallel()

// timestamp of the First block commitment is X
startTimestamp := time.UnixMilli(1615195200000)
midTimestamp := startTimestamp.Add(time.Duration(2.5 * float64(time.Second)))
endTimestamp := startTimestamp.Add(5 * time.Second)

key, err := crypto.GenerateKey()
if err != nil {
t.Fatal(err)
Expand All @@ -82,17 +87,21 @@ func TestUpdater(t *testing.T) {

if i%2 == 0 {
commitments[string(idxBytes[:])] = preconf.PreConfCommitmentStorePreConfCommitment{
Commiter: builderAddr,
TxnHash: strings.TrimPrefix(txn.Hash().Hex(), "0x"),
CommitmentHash: common.HexToHash(fmt.Sprintf("0x%02d", i)),
BlockCommitedAt: big.NewInt(0),
Commiter: builderAddr,
TxnHash: strings.TrimPrefix(txn.Hash().Hex(), "0x"),
CommitmentHash: common.HexToHash(fmt.Sprintf("0x%02d", i)),
BlockCommitedAt: big.NewInt(0),
DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()),
DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()),
}
} else {
commitments[string(idxBytes[:])] = preconf.PreConfCommitmentStorePreConfCommitment{
Commiter: otherBuilderAddr,
TxnHash: strings.TrimPrefix(txn.Hash().Hex(), "0x"),
CommitmentHash: common.HexToHash(fmt.Sprintf("0x%02d", i)),
BlockCommitedAt: big.NewInt(0),
Commiter: otherBuilderAddr,
TxnHash: strings.TrimPrefix(txn.Hash().Hex(), "0x"),
CommitmentHash: common.HexToHash(fmt.Sprintf("0x%02d", i)),
BlockCommitedAt: big.NewInt(0),
DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()),
DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()),
}
}
}
Expand All @@ -107,10 +116,12 @@ func TestUpdater(t *testing.T) {
}

commitments[string(idxBytes[:])] = preconf.PreConfCommitmentStorePreConfCommitment{
Commiter: builderAddr,
TxnHash: bundle,
CommitmentHash: common.HexToHash(fmt.Sprintf("0x%02d", i)),
BlockCommitedAt: big.NewInt(0),
Commiter: builderAddr,
TxnHash: bundle,
CommitmentHash: common.HexToHash(fmt.Sprintf("0x%02d", i)),
BlockCommitedAt: big.NewInt(0),
DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()),
DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()),
}
}

Expand All @@ -127,7 +138,7 @@ func TestUpdater(t *testing.T) {

l2Client := &testL1Client{
blockNum: 0,
block: types.NewBlock(&types.Header{}, txns, nil, nil, NewHasher()),
block: types.NewBlock(&types.Header{Time: uint64(midTimestamp.UnixMilli())}, txns, nil, nil, NewHasher()),
}

testOracle := &testOracle{
Expand Down Expand Up @@ -164,6 +175,9 @@ func TestUpdater(t *testing.T) {
break
}
settlement := <-testWinnerRegister.settlements
if settlement.decayPercentage != 50 {
t.Fatalf("wrong decay percentage, got %d", settlement.decayPercentage)
}
if settlement.blockNum != 5 {
t.Fatal("wrong block number")
}
Expand Down

0 comments on commit 59441ba

Please sign in to comment.