Skip to content

Commit

Permalink
move v1 host announcement checking to CheckTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Nov 8, 2024
1 parent bf1c283 commit 75d5d1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
16 changes: 16 additions & 0 deletions internal/testutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 3 additions & 23 deletions persist/sqlite/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -1619,26 +1602,23 @@ 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])
}

{
dbTxns, err := db.Transactions([]types.TransactionID{txn2.ID()})
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])
}

{
dbTxns, err := db.Transactions([]types.TransactionID{txn3.ID()})
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)
Expand Down

0 comments on commit 75d5d1c

Please sign in to comment.