Skip to content

Commit

Permalink
deep equal arrays of miner addresses in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Oct 1, 2024
1 parent 2354d5c commit 5a50cac
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions e2e/e2e_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/hemilabs/heminetwork/api/protocol"
"github.com/hemilabs/heminetwork/database/bfgd"
"github.com/hemilabs/heminetwork/database/bfgd/postgres"
"github.com/hemilabs/heminetwork/ethereum"
"github.com/hemilabs/heminetwork/hemi"
"github.com/hemilabs/heminetwork/hemi/electrumx"
"github.com/hemilabs/heminetwork/hemi/pop"
Expand Down Expand Up @@ -2325,12 +2326,17 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
// we expect result counts like so : 100, 51, 0
var txIndex uint64 = 1

addresses := []string{}

for range 151 {
privateKey, err := dcrsecp256k1.GeneratePrivateKeyFromRand(rand.Reader)
if err != nil {
t.Fatal(err)
}

address := ethereum.AddressFromPrivateKey(privateKey)
addresses = append(addresses, address.String())

publicKey := privateKey.PubKey()
publicKeyUncompressed := publicKey.SerializeUncompressed()

Expand Down Expand Up @@ -2368,7 +2374,7 @@ func TestPopPayoutsMultiplePages(t *testing.T) {

serializedL2Keystone := hemi.L2KeystoneAbbreviate(includedL2Keystone).Serialize()

uniquePopPayouts := map[string]bool{}
receivedAddresses := []string{}

popPayoutsRequest := bssapi.PopPayoutsRequest{
L2BlockForPayout: serializedL2Keystone[:],
Expand Down Expand Up @@ -2401,7 +2407,7 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
}

for _, p := range popPayoutsResponse.PopPayouts {
uniquePopPayouts[p.MinerAddress.String()] = true
receivedAddresses = append(receivedAddresses, p.MinerAddress.String())
}

popPayoutsRequest.Page = 1
Expand Down Expand Up @@ -2431,7 +2437,7 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
}

for _, p := range popPayoutsResponse.PopPayouts {
uniquePopPayouts[p.MinerAddress.String()] = true
receivedAddresses = append(receivedAddresses, p.MinerAddress.String())
}

popPayoutsRequest.Page = 2
Expand All @@ -2458,9 +2464,11 @@ func TestPopPayoutsMultiplePages(t *testing.T) {
len(popPayoutsResponse.PopPayouts))
}

// ensure there were 151 unique pop payouts using miner address
if len(uniquePopPayouts) != 151 {
t.Fatalf("unexpected number of pop payouts %d", len(uniquePopPayouts))
slices.Sort(addresses)
slices.Sort(receivedAddresses)

if diff := deep.Equal(addresses, receivedAddresses); len(diff) != 0 {
t.Fatalf("unexpected diff %v", diff)
}
}

Expand Down

0 comments on commit 5a50cac

Please sign in to comment.