Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: fix TestAttestorsChange #4510

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions test/e2e-go/features/stateproofs/stateproofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,10 @@ func registerParticipationAndWait(t *testing.T, client libgoal.Client, part acco
// After making the first Stateproof, we transfer three-quarters of the stake of the
// rich node to the poor node. For both cases, we assert different stakes, that is, to
// conclude whether the poor node is used to create the StateProof or the rich node.
func TestAttestorsChangeTest(t *testing.T) {
func TestAttestorsChange(t *testing.T) {
partitiontest.PartitionTest(t)
defer fixtures.ShutdownSynchronizedTest(t)

if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
t.Skip("This test is difficult for ARM")
}

a := require.New(fixtures.SynchronizedTest(t))

consensusParams := getDefaultStateProofConsensusParams()
Expand Down Expand Up @@ -717,7 +713,7 @@ func TestAttestorsChangeTest(t *testing.T) {
from: accountFetcher{nodeName: "richNode", accountNumber: 0},
to: accountFetcher{nodeName: "poorNode", accountNumber: 0},
}

sum := uint64(0)
for rnd := uint64(1); rnd <= consensusParams.StateProofInterval*(expectedNumberOfStateProofs+1); rnd++ {
// Changing the amount to pay. This should transfer most of the money from the rich node to the poor node.
if consensusParams.StateProofInterval*2 == rnd {
Expand All @@ -738,22 +734,25 @@ func TestAttestorsChangeTest(t *testing.T) {
blk, err := libgoal.BookkeepingBlock(rnd)
a.NoErrorf(err, "failed to retrieve block from algod on round %d", rnd)

if (rnd % consensusParams.StateProofInterval) == 0 {
// Must have a merkle commitment for participants
a.True(len(blk.StateProofTracking[protocol.StateProofBasic].StateProofVotersCommitment) > 0)
a.True(blk.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight != basics.MicroAlgos{})

stake := blk.BlockHeader.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight.ToUint64()

// We sample the accounts' balances StateProofVotersLookback rounds before state proof round.
if (rnd+consensusParams.StateProofVotersLookback)%consensusParams.StateProofInterval == 0 {
sum = 0
// the main part of the test (computing the total stake of the nodes):
sum := uint64(0)
for i := 1; i <= 3; i++ {
sum += accountFetcher{fmt.Sprintf("Node%d", i), 0}.getBalance(a, &fixture)
}

richNodeStake := accountFetcher{"richNode", 0}.getBalance(a, &fixture)
poorNodeStake := accountFetcher{"poorNode", 0}.getBalance(a, &fixture)
sum = sum + richNodeStake + poorNodeStake
}

if (rnd % consensusParams.StateProofInterval) == 0 {
// Must have a merkle commitment for participants
a.True(len(blk.StateProofTracking[protocol.StateProofBasic].StateProofVotersCommitment) > 0)
a.True(blk.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight != basics.MicroAlgos{})

stake := blk.BlockHeader.StateProofTracking[protocol.StateProofBasic].StateProofOnlineTotalWeight.ToUint64()

a.Equal(sum, stake)

Expand Down