github.com/koko1123/flow-go-1@v0.29.6/fvm/environment/account_creator_test.go (about) 1 package environment_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/koko1123/flow-go-1/fvm/environment" 9 "github.com/koko1123/flow-go-1/fvm/state" 10 "github.com/koko1123/flow-go-1/fvm/utils" 11 "github.com/koko1123/flow-go-1/model/flow" 12 ) 13 14 func Test_NewAccountCreator_NoError(t *testing.T) { 15 view := utils.NewSimpleView() 16 chain := flow.MonotonicEmulator.Chain() 17 txnState := state.NewTransactionState(view, state.DefaultParameters()) 18 creator := environment.NewAddressGenerator(txnState, chain) 19 require.NotNil(t, creator) 20 } 21 22 func Test_NewAccountCreator_GeneratingUpdatesState(t *testing.T) { 23 view := utils.NewSimpleView() 24 chain := flow.MonotonicEmulator.Chain() 25 txnState := state.NewTransactionState(view, state.DefaultParameters()) 26 creator := environment.NewAddressGenerator(txnState, chain) 27 _, err := creator.NextAddress() 28 require.NoError(t, err) 29 30 stateBytes, err := view.Get("", state.AddressStateKey) 31 require.NoError(t, err) 32 33 require.Equal(t, flow.BytesToAddress(stateBytes), flow.HexToAddress("01")) 34 } 35 36 func Test_NewAccountCreator_UsesLedgerState(t *testing.T) { 37 view := utils.NewSimpleView() 38 err := view.Set("", state.AddressStateKey, flow.HexToAddress("01").Bytes()) 39 require.NoError(t, err) 40 41 chain := flow.MonotonicEmulator.Chain() 42 txnState := state.NewTransactionState(view, state.DefaultParameters()) 43 creator := environment.NewAddressGenerator(txnState, chain) 44 45 _, err = creator.NextAddress() 46 require.NoError(t, err) 47 48 stateBytes, err := view.Get("", state.AddressStateKey) 49 require.NoError(t, err) 50 51 require.Equal(t, flow.BytesToAddress(stateBytes), flow.HexToAddress("02")) 52 // counts is one unit higher than returned index (index include zero, but counts starts from 1) 53 require.Equal(t, uint64(2), creator.AddressCount()) 54 }