github.com/koko1123/flow-go-1@v0.29.6/fvm/environment/accounts_status_test.go (about) 1 package environment_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/onflow/atree" 8 "github.com/stretchr/testify/require" 9 10 "github.com/koko1123/flow-go-1/fvm/environment" 11 ) 12 13 func TestAccountStatus(t *testing.T) { 14 15 s := environment.NewAccountStatus() 16 require.False(t, s.IsAccountFrozen()) 17 18 t.Run("test frozen flag set/reset", func(t *testing.T) { 19 s.SetFrozenFlag(true) 20 require.True(t, s.IsAccountFrozen()) 21 22 s.SetFrozenFlag(false) 23 require.False(t, s.IsAccountFrozen()) 24 }) 25 26 t.Run("test setting values", func(t *testing.T) { 27 // set some values for side effect checks 28 s.SetFrozenFlag(true) 29 30 index := atree.StorageIndex{1, 2, 3, 4, 5, 6, 7, 8} 31 s.SetStorageIndex(index) 32 s.SetPublicKeyCount(34) 33 s.SetStorageUsed(56) 34 35 require.Equal(t, uint64(56), s.StorageUsed()) 36 returnedIndex := s.StorageIndex() 37 require.True(t, bytes.Equal(index[:], returnedIndex[:])) 38 require.Equal(t, uint64(34), s.PublicKeyCount()) 39 40 // check no side effect on flags 41 require.True(t, s.IsAccountFrozen()) 42 }) 43 44 t.Run("test serialization", func(t *testing.T) { 45 b := append([]byte(nil), s.ToBytes()...) 46 clone, err := environment.AccountStatusFromBytes(b) 47 require.NoError(t, err) 48 require.Equal(t, s.IsAccountFrozen(), clone.IsAccountFrozen()) 49 require.Equal(t, s.StorageIndex(), clone.StorageIndex()) 50 require.Equal(t, s.PublicKeyCount(), clone.PublicKeyCount()) 51 require.Equal(t, s.StorageUsed(), clone.StorageUsed()) 52 53 // invalid size bytes 54 _, err = environment.AccountStatusFromBytes([]byte{1, 2}) 55 require.Error(t, err) 56 }) 57 }