github.com/koko1123/flow-go-1@v0.29.6/engine/execution/state/bootstrap/bootstrap_test.go (about)

     1  package bootstrap
     2  
     3  import (
     4  	"encoding/hex"
     5  	"testing"
     6  
     7  	"github.com/rs/zerolog"
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/koko1123/flow-go-1/fvm"
    12  	completeLedger "github.com/koko1123/flow-go-1/ledger/complete"
    13  	"github.com/koko1123/flow-go-1/ledger/complete/wal/fixtures"
    14  	"github.com/koko1123/flow-go-1/model/flow"
    15  	"github.com/koko1123/flow-go-1/module/metrics"
    16  	"github.com/koko1123/flow-go-1/utils/unittest"
    17  )
    18  
    19  func TestBootstrapLedger(t *testing.T) {
    20  	unittest.RunWithTempDir(t, func(dbDir string) {
    21  
    22  		chain := flow.Mainnet.Chain()
    23  
    24  		metricsCollector := &metrics.NoopCollector{}
    25  		wal := &fixtures.NoopWAL{}
    26  		ls, err := completeLedger.NewLedger(wal, 100, metricsCollector, zerolog.Nop(), completeLedger.DefaultPathFinderVersion)
    27  		require.NoError(t, err)
    28  		compactor := fixtures.NewNoopCompactor(ls)
    29  		<-compactor.Ready()
    30  		defer func() {
    31  			<-ls.Done()
    32  			<-compactor.Done()
    33  		}()
    34  
    35  		stateCommitment, err := NewBootstrapper(zerolog.Nop()).BootstrapLedger(
    36  			ls,
    37  			unittest.ServiceAccountPublicKey,
    38  			chain,
    39  			fvm.WithInitialTokenSupply(unittest.GenesisTokenSupply),
    40  		)
    41  		require.NoError(t, err)
    42  
    43  		expectedStateCommitment := unittest.GenesisStateCommitment
    44  
    45  		if !assert.Equal(t, expectedStateCommitment, stateCommitment) {
    46  			t.Logf(
    47  				"Incorrect state commitment: got %s, expected %s",
    48  				hex.EncodeToString(stateCommitment[:]),
    49  				hex.EncodeToString(expectedStateCommitment[:]),
    50  			)
    51  		}
    52  	})
    53  }
    54  
    55  func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
    56  	expectedStateCommitmentBytes, _ := hex.DecodeString("8265f0fc3b74daa0869c1cc4fbc9ec0af2594d07657cf4ca39440537e2a12b13")
    57  	expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
    58  	require.NoError(t, err)
    59  
    60  	unittest.RunWithTempDir(t, func(dbDir string) {
    61  
    62  		chain := flow.Mainnet.Chain()
    63  
    64  		metricsCollector := &metrics.NoopCollector{}
    65  		wal := &fixtures.NoopWAL{}
    66  		ls, err := completeLedger.NewLedger(wal, 100, metricsCollector, zerolog.Nop(), completeLedger.DefaultPathFinderVersion)
    67  		require.NoError(t, err)
    68  		compactor := fixtures.NewNoopCompactor(ls)
    69  		<-compactor.Ready()
    70  		defer func() {
    71  			<-ls.Done()
    72  			<-compactor.Done()
    73  		}()
    74  
    75  		stateCommitment, err := NewBootstrapper(zerolog.Nop()).BootstrapLedger(
    76  			ls,
    77  			unittest.ServiceAccountPublicKey,
    78  			chain,
    79  		)
    80  		require.NoError(t, err)
    81  
    82  		if !assert.Equal(t, expectedStateCommitment, stateCommitment) {
    83  			t.Logf(
    84  				"Incorrect state commitment: got %s, expected %s",
    85  				hex.EncodeToString(stateCommitment[:]),
    86  				hex.EncodeToString(expectedStateCommitment[:]),
    87  			)
    88  		}
    89  	})
    90  }