Skip to content

Commit

Permalink
Merge pull request #1 from jasonpaulos/absenteeism-tests
Browse files Browse the repository at this point in the history
Add unit tests for absenteeism
  • Loading branch information
jannotti authored Apr 29, 2024
2 parents ca9ff29 + 3ed7cb3 commit 738fdc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,12 @@ func TestFetchBlock(t *testing.T) {
blockOptions: idb.GetBlockOptions{Transactions: true},
expected: loadBlockFromFile("test_resources/stpf_block_high_index_response.json"),
},
{
name: "Proposer and Incentives Block",
blockBytes: loadResourceFileOrPanic("test_resources/proposer_incentives_block.block"),
blockOptions: idb.GetBlockOptions{Transactions: true},
expected: loadBlockFromFile("test_resources/proposer_incentives_block_response.json"),
},
}

for _, tc := range testcases {
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions api/test_resources/proposer_incentives_block_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"bonus":10000000,"fees-collected":1,"genesis-hash":"7p0jHnxwza10srqCUzt8JIi+xKyE8/RtGIaaujgsKX4=","genesis-id":"test-v1","participation-updates":{"absent-participation-accounts":["AEAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM3LMI3A"]},"previous-block-hash":"5tC8YaXvIzgHMonUQmmI5svzXrdJefVSFqys/NGpHQk=","proposer":"D4FDFGXJXTBLFYSBVLJOUC5VVPQSH7KZBVCKQ6XIWBEHYM6YRI2U6PGB4A","rewards":{"fee-sink":"A7NMWS3NT3IUDMLVO26ULGXGIIOUQ3ND2TXSER6EBGRZNOBOUIQXHIBGDE","rewards-calculation-round":500000,"rewards-level":0,"rewards-pool":"7777777777777777777777777777777777777777777777777774MSJUVU","rewards-rate":0,"rewards-residue":0},"round":43,"seed":"i767QeAMNYxi0EG0mCT7LyERdseoIeD9D571mo4e4p8=","state-proof-tracking":[{"next-round":512,"online-total-weight":0,"type":0}],"timestamp":1714412239,"transactions":[],"transactions-root":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","transactions-root-sha256":"HQn2+iMjWIFRTaDl+PeJdn5rKOch+otqMK5/Gao+puc=","txn-counter":1003,"upgrade-state":{"current-protocol":"future","next-protocol-approvals":0,"next-protocol-switch-on":0,"next-protocol-vote-before":0},"upgrade-vote":{"upgrade-approve":false,"upgrade-delay":0}}
9 changes: 7 additions & 2 deletions idb/postgres/internal/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,14 @@ func TestBlockHeaderEncoding(t *testing.T) {
},
ParticipationUpdates: sdk.ParticipationUpdates{
ExpiredParticipationAccounts: []sdk.Address{newaddr()},
AbsentParticipationAccounts: []sdk.Address{newaddr()},
},
Proposer: newaddr(),
}

buf := EncodeBlockHeader(header)

template := `{"fees":"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","partupdrmv":["%s"],"prev":"BQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","rnd":3,"rwd":"AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="}`
template := `{"fees":"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","partupdabs":["AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJVBPJXY"],"partupdrmv":["%s"],"prev":"BQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","prp":"AUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAITAR5VI","rnd":3,"rwd":"AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="}`
expectedString := fmt.Sprintf(template, "AMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANVWEXNA")
assert.Equal(t, expectedString, string(buf))

Expand Down Expand Up @@ -539,6 +541,9 @@ func TestLcAccountDataEncoding(t *testing.T) {
TotalAssets: 13,
TotalBoxes: 20,
TotalBoxBytes: 21,
LastHeartbeat: 22,
LastProposed: 23,
IncentiveEligible: true,
},
VotingData: sdk.VotingData{
VoteID: voteID,
Expand All @@ -551,7 +556,7 @@ func TestLcAccountDataEncoding(t *testing.T) {
}
buf := EncodeTrimmedLcAccountData(ad)

expectedString := `{"onl":1,"sel":"DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","spend":"BgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","stprf":"EwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","tapl":11,"tapp":10,"tas":13,"tasp":12,"tbx":20,"tbxb":21,"teap":9,"tsch":{"nbs":8,"nui":7},"vote":"DgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","voteFst":16,"voteKD":18,"voteLst":17}`
expectedString := `{"ie":true,"lhb":22,"lpr":23,"onl":1,"sel":"DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","spend":"BgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","stprf":"EwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","tapl":11,"tapp":10,"tas":13,"tasp":12,"tbx":20,"tbxb":21,"teap":9,"tsch":{"nbs":8,"nui":7},"vote":"DgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","voteFst":16,"voteKD":18,"voteLst":17}`
assert.Equal(t, expectedString, string(buf))

decodedAd, err := DecodeTrimmedLcAccountData(buf)
Expand Down

0 comments on commit 738fdc0

Please sign in to comment.