Skip to content

Commit

Permalink
chore: add test that verifies if all the delegations pointers wasn't …
Browse files Browse the repository at this point in the history
…pointing to the last one
  • Loading branch information
RafilxTenfen committed Jan 13, 2025
1 parent 069d6b4 commit e99764a
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions covenant/covenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,31 @@ func TestIsKeyInCommittee(t *testing.T) {
dels = covenant.SanitizeDelegations(covKeyPair.PublicKey, paramsGet, []*types.Delegation{delWithCovenant})
require.Len(t, dels, 1)

lastUnsanitizedDels := []*types.Delegation{delWithCovenant, delWithCovenant, delNoCovenant}
amtSatFirst := btcutil.Amount(100)
amtSatSecond := btcutil.Amount(150)
amtSatThird := btcutil.Amount(200)
lastUnsanitizedDels := []*types.Delegation{
&types.Delegation{
ParamsVersion: pVersionWithCovenant,
TotalSat: amtSatFirst,
},
delNoCovenant,
&types.Delegation{
ParamsVersion: pVersionWithCovenant,
TotalSat: amtSatSecond,
},
delNoCovenant,
&types.Delegation{
ParamsVersion: pVersionWithCovenant,
TotalSat: amtSatThird,
},
}

sanitizedDels := covenant.SanitizeDelegations(covKeyPair.PublicKey, paramsGet, lastUnsanitizedDels)
require.Len(t, sanitizedDels, 2)

// change something in the lastUnsanitezedDels pointer to see if it modifies in the delegations
// it shouldn't modify the sanitized
endHeightSet := uint32(1000)
delWithCovenant.EndHeight = endHeightSet
require.Equal(t, lastUnsanitizedDels[0].EndHeight, endHeightSet)
require.Equal(t, sanitizedDels[0].EndHeight, endHeightSet)
require.Len(t, sanitizedDels, 3)
require.Equal(t, amtSatFirst, sanitizedDels[0].TotalSat)
require.Equal(t, amtSatSecond, sanitizedDels[1].TotalSat)
require.Equal(t, amtSatThird, sanitizedDels[2].TotalSat)
}

type MockParamGetter struct {
Expand Down

0 comments on commit e99764a

Please sign in to comment.