From 75d5d1caac5ac4a81a44a7310402c6f3e46987e4 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Fri, 8 Nov 2024 12:25:52 -0500 Subject: [PATCH] move v1 host announcement checking to CheckTransaction --- internal/testutil/check.go | 16 ++++++++++++++++ persist/sqlite/consensus_test.go | 26 +++----------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/internal/testutil/check.go b/internal/testutil/check.go index 6e380dfa..42ea7007 100644 --- a/internal/testutil/check.go +++ b/internal/testutil/check.go @@ -107,6 +107,22 @@ func CheckTransaction(t *testing.T, expectTxn types.Transaction, gotTxn explorer // cf.X = make([]uint64, d.ReadPrefix()) and the prefix is 0 // testutil.Equal(t, "covered fields", expected.CoveredFields, got.CoveredFields) } + + var hostAnnouncements []chain.HostAnnouncement + for _, arb := range expectTxn.ArbitraryData { + var ha chain.HostAnnouncement + if ha.FromArbitraryData(arb) { + hostAnnouncements = append(hostAnnouncements, ha) + } + } + Equal(t, "host announcements", len(hostAnnouncements), len(gotTxn.HostAnnouncements)) + for i := range hostAnnouncements { + expected := hostAnnouncements[i] + got := gotTxn.HostAnnouncements[i] + + Equal(t, "public key", expected.PublicKey, got.PublicKey) + Equal(t, "net address", expected.NetAddress, got.NetAddress) + } } // CheckV2Transaction checks the inputs and outputs of the retrieved transaction diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index b8eeb145..3e037778 100644 --- a/persist/sqlite/consensus_test.go +++ b/persist/sqlite/consensus_test.go @@ -1527,23 +1527,6 @@ func TestHostAnnouncement(t *testing.T) { _, _, cm, db := newStore(t, false, nil) - checkHostAnnouncements := func(expectedArbitraryData [][]byte, got []chain.HostAnnouncement) { - t.Helper() - - var expected []chain.HostAnnouncement - for _, arb := range expectedArbitraryData { - var ha chain.HostAnnouncement - if ha.FromArbitraryData(arb) { - expected = append(expected, ha) - } - } - testutil.Equal(t, "len(hostAnnouncements)", len(expected), len(got)) - for i := range expected { - testutil.Equal(t, "host public key", expected[i].PublicKey, got[i].PublicKey) - testutil.Equal(t, "host net address", expected[i].NetAddress, got[i].NetAddress) - } - } - txn1 := types.Transaction{ ArbitraryData: [][]byte{ testutil.CreateAnnouncement(pk1, "127.0.0.1:1234"), @@ -1619,8 +1602,7 @@ func TestHostAnnouncement(t *testing.T) { if err != nil { t.Fatal(err) } - testutil.Equal(t, "len(txns)", 1, len(dbTxns)) - checkHostAnnouncements(txn1.ArbitraryData, dbTxns[0].HostAnnouncements) + testutil.CheckTransaction(t, txn1, dbTxns[0]) } { @@ -1628,8 +1610,7 @@ func TestHostAnnouncement(t *testing.T) { if err != nil { t.Fatal(err) } - testutil.Equal(t, "len(txns)", 1, len(dbTxns)) - checkHostAnnouncements(txn2.ArbitraryData, dbTxns[0].HostAnnouncements) + testutil.CheckTransaction(t, txn2, dbTxns[0]) } { @@ -1637,8 +1618,7 @@ func TestHostAnnouncement(t *testing.T) { if err != nil { t.Fatal(err) } - testutil.Equal(t, "len(txns)", 1, len(dbTxns)) - checkHostAnnouncements(txn3.ArbitraryData, dbTxns[0].HostAnnouncements) + testutil.CheckTransaction(t, txn3, dbTxns[0]) } ts := time.Unix(0, 0)