Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqizng committed Apr 10, 2023
1 parent 4c1830f commit f6e09ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
12 changes: 9 additions & 3 deletions tools/block-generator/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ type generator struct {
// Reporting information from transaction type to data
reportData Report

// ledger
// ledger
ledger *ledger.Ledger
}

Expand Down Expand Up @@ -418,7 +418,10 @@ func (g *generator) WriteBlock(output io.Writer, round uint64) error {
if err != nil {
return err
}
g.ledger.AddBlock(cert.Block, agreement.Certificate{})
err = g.ledger.AddBlock(cert.Block, agreement.Certificate{})
if err != nil {
return err
}
g.ledger.WaitForCommit(basics.Round(g.round))
g.finishRound(numTxnForBlock)
return nil
Expand All @@ -432,6 +435,9 @@ func (g *generator) WriteDeltas(output io.Writer, round uint64) error {
}
// msgp encode deltas
data, err := encode(protocol.CodecHandle, delta)
if err != nil {
return err
}
_, err = output.Write(data)
if err != nil {
return err
Expand Down Expand Up @@ -703,7 +709,7 @@ func (g *generator) initializeLedger() {
genBal := convertToGenesisBalances(g.balances)
// add rewards pool with min balance
genBal[g.rewardsPool] = basics.AccountData{
MicroAlgos: basics.MicroAlgos{g.params.MinBalance},
MicroAlgos: basics.MicroAlgos{Raw: g.params.MinBalance},
}
bal := bookkeeping.MakeGenesisBalances(genBal, g.feeSink, g.rewardsPool)
block, err := bookkeeping.MakeGenesisBlock(g.protocol, bal, g.genesisID, g.genesisHash)
Expand Down
9 changes: 0 additions & 9 deletions tools/block-generator/generator/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,3 @@ func TestWriteRound(t *testing.T) {
_, err := g.ledger.GetStateDeltaForRound(1)
require.NoError(t, err)
}

func TestIndexToAccountAndAccountToIndex(t *testing.T) {
partitiontest.PartitionTest(t)
for i := uint64(0); i < uint64(100000); i++ {
acct := indexToAccount(i)
result := accountToIndex(acct)
require.Equal(t, i, result)
}
}
10 changes: 10 additions & 0 deletions tools/block-generator/generator/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,20 @@ func TestWeightedSelectionOutOfRange(t *testing.T) {
}

func TestConvertToGenesisBalance(t *testing.T) {
partitiontest.PartitionTest(t)
balance := []uint64{100, 200, 300}
genesisBalances := convertToGenesisBalances(balance)
require.Equal(t, 3, len(genesisBalances))
for i, bal := range balance {
require.Equal(t, bal, genesisBalances[indexToAccount(uint64(i))].MicroAlgos.Raw)
}
}

func TestIndexToAccountAndAccountToIndex(t *testing.T) {
partitiontest.PartitionTest(t)
for i := uint64(0); i < uint64(100000); i++ {
acct := indexToAccount(i)
result := accountToIndex(acct)
require.Equal(t, i, result)
}
}

0 comments on commit f6e09ad

Please sign in to comment.