Skip to content

Commit a81204f

Browse files
authored
Add heartbeat address to txn_participation (making search eligible) includes tests exercising writing of heartbeat address (along with sender). (#1642)
1 parent 0c26ab4 commit a81204f

File tree

4 files changed

+91
-5
lines changed

4 files changed

+91
-5
lines changed
Binary file not shown.

idb/postgres/internal/writer/write_txn_participation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func addTransactionParticipants(stxnad *types.SignedTxnWithAD, includeInner bool
4040
for _, address := range txn.ApplicationCallTxnFields.Accounts {
4141
add(address)
4242
}
43+
case types.HeartbeatTx:
44+
add(txn.HbAddress)
4345
}
4446

4547
if includeInner {

idb/postgres/internal/writer/writer_test.go

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ func TestWriterTxnParticipationTableNoPayout(t *testing.T) {
481481
tests = append(tests, testcase)
482482
}
483483
{
484-
stxnad := test.MakeCreateAppTxn(sdk.Address(test.AccountA))
484+
stxnad := test.MakeCreateAppTxn(test.AccountA)
485485
stxnad.Txn.ApplicationCallTxnFields.Accounts =
486-
[]sdk.Address{sdk.Address(test.AccountB), sdk.Address(test.AccountC)}
486+
[]sdk.Address{test.AccountB, test.AccountC}
487487
stib, err := util.EncodeSignedTxn(makeBlockFunc().BlockHeader, stxnad.SignedTxn, stxnad.ApplyData)
488488
require.NoError(t, err)
489489

@@ -492,17 +492,40 @@ func TestWriterTxnParticipationTableNoPayout(t *testing.T) {
492492
payset: []sdk.SignedTxnInBlock{stib},
493493
expected: []txnParticipationRow{
494494
{
495-
addr: sdk.Address(test.AccountA),
495+
addr: test.AccountA,
496496
round: 2,
497497
intra: 0,
498498
},
499499
{
500-
addr: sdk.Address(test.AccountB),
500+
addr: test.AccountB,
501501
round: 2,
502502
intra: 0,
503503
},
504504
{
505-
addr: sdk.Address(test.AccountC),
505+
addr: test.AccountC,
506+
round: 2,
507+
intra: 0,
508+
},
509+
},
510+
}
511+
tests = append(tests, testcase)
512+
}
513+
{
514+
stxnad0 := test.MakeHeartbeatTxn(test.AccountA, test.AccountD)
515+
stib0, err := util.EncodeSignedTxn(makeBlockFunc().BlockHeader, stxnad0.SignedTxn, stxnad0.ApplyData)
516+
require.NoError(t, err)
517+
518+
testcase := testtype{
519+
name: "heartbeat",
520+
payset: []sdk.SignedTxnInBlock{stib0},
521+
expected: []txnParticipationRow{
522+
{
523+
addr: test.AccountA,
524+
round: 2,
525+
intra: 0,
526+
},
527+
{
528+
addr: test.AccountD,
506529
round: 2,
507530
intra: 0,
508531
},
@@ -648,6 +671,40 @@ func TestWriterTxnParticipationTableWithPayout(t *testing.T) {
648671
}
649672
tests = append(tests, testcase)
650673
}
674+
{
675+
stxnad0 := test.MakeHeartbeatTxn(test.AccountA, test.AccountD)
676+
stib0, err := util.EncodeSignedTxn(makeBlockFunc().BlockHeader, stxnad0.SignedTxn, stxnad0.ApplyData)
677+
require.NoError(t, err)
678+
679+
testcase := testtype{
680+
name: "heartbeat",
681+
payset: []sdk.SignedTxnInBlock{stib0},
682+
expected: []txnParticipationRow{
683+
{
684+
addr: test.AccountA,
685+
round: 2,
686+
intra: 0,
687+
},
688+
{
689+
addr: test.AccountD,
690+
round: 2,
691+
intra: 0,
692+
},
693+
// Payout involved accounts
694+
{
695+
addr: test.AccountE,
696+
round: 2,
697+
intra: 1,
698+
},
699+
{
700+
addr: test.FeeAddr,
701+
round: 2,
702+
intra: 1,
703+
},
704+
},
705+
}
706+
tests = append(tests, testcase)
707+
}
651708

652709
for _, testcase := range tests {
653710
t.Run(testcase.name, func(t *testing.T) {

util/test/account_testutil.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"crypto/rand"
55
"crypto/sha512"
66
"fmt"
7+
"os"
78

9+
"github.com/algorand/indexer/v3/idb"
810
"github.com/algorand/indexer/v3/util"
911

1012
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
@@ -352,6 +354,31 @@ func MakeAppCallWithInnerTxn(appSender, paymentSender, paymentReceiver, assetSen
352354
return createApp
353355
}
354356

357+
// MakeHeartbeatTxn creates a heartbeat transaction, overriding fields with the provided values.
358+
func MakeHeartbeatTxn(sender, hbAddress sdk.Address) sdk.SignedTxnWithAD {
359+
var hbTxn sdk.SignedTxn
360+
_ = msgpack.Decode(loadResourceFileOrPanic("test_resources/heartbeat.txn"), &hbTxn)
361+
362+
hbTxn.Txn.Sender = sender
363+
hbTxn.Txn.GenesisHash = GenesisHash
364+
var fields = hbTxn.Txn.HeartbeatTxnFields
365+
fields.HbAddress = hbAddress
366+
return sdk.SignedTxnWithAD{
367+
SignedTxn: hbTxn,
368+
}
369+
}
370+
371+
func loadResourceFileOrPanic(path string) []byte {
372+
data, err := os.ReadFile(path)
373+
374+
if err != nil {
375+
panic(fmt.Sprintf("Failed to load resource file: '%s'", path))
376+
}
377+
var ret idb.TxnRow
378+
_ = msgpack.Decode(data, &ret)
379+
return data
380+
}
381+
355382
// MakeBlockForTxns takes some transactions and constructs a block compatible with the indexer import function.
356383
func MakeBlockForTxns(prevHeader sdk.BlockHeader, inputs ...*sdk.SignedTxnWithAD) (sdk.Block, error) {
357384
res := sdk.Block{BlockHeader: prevHeader}

0 commit comments

Comments
 (0)