github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/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/onflow/flow-go/fvm/environment" 9 "github.com/onflow/flow-go/fvm/storage/snapshot" 10 "github.com/onflow/flow-go/fvm/storage/testutils" 11 "github.com/onflow/flow-go/model/flow" 12 ) 13 14 func Test_NewAccountCreator_NoError(t *testing.T) { 15 chain := flow.MonotonicEmulator.Chain() 16 txnState := testutils.NewSimpleTransaction(nil) 17 creator := environment.NewAddressGenerator(txnState, chain) 18 require.NotNil(t, creator) 19 } 20 21 func Test_NewAccountCreator_GeneratingUpdatesState(t *testing.T) { 22 chain := flow.MonotonicEmulator.Chain() 23 txnState := testutils.NewSimpleTransaction(nil) 24 creator := environment.NewAddressGenerator(txnState, chain) 25 _, err := creator.NextAddress() 26 require.NoError(t, err) 27 28 stateBytes, err := txnState.Get(flow.AddressStateRegisterID) 29 require.NoError(t, err) 30 31 require.Equal(t, flow.BytesToAddress(stateBytes), flow.HexToAddress("01")) 32 } 33 34 func Test_NewAccountCreator_UsesLedgerState(t *testing.T) { 35 chain := flow.MonotonicEmulator.Chain() 36 txnState := testutils.NewSimpleTransaction( 37 snapshot.MapStorageSnapshot{ 38 flow.AddressStateRegisterID: flow.HexToAddress("01").Bytes(), 39 }) 40 creator := environment.NewAddressGenerator(txnState, chain) 41 42 _, err := creator.NextAddress() 43 require.NoError(t, err) 44 45 stateBytes, err := txnState.Get(flow.AddressStateRegisterID) 46 require.NoError(t, err) 47 48 require.Equal(t, flow.BytesToAddress(stateBytes), flow.HexToAddress("02")) 49 // counts is one unit higher than returned index (index include zero, but counts starts from 1) 50 require.Equal(t, uint64(2), creator.AddressCount()) 51 }