github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/storage/derived/dependencies_test.go (about) 1 package derived_test 2 3 import ( 4 "testing" 5 6 "github.com/onflow/cadence/runtime/common" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/fvm/storage/derived" 10 ) 11 12 func TestProgramDependencies_Count(t *testing.T) { 13 d := derived.NewProgramDependencies() 14 15 require.Equal(t, 0, d.Count()) 16 17 d.Add(common.StringLocation("test")) 18 require.Equal(t, 1, d.Count()) 19 } 20 21 func TestProgramDependencies_Add(t *testing.T) { 22 d := derived.NewProgramDependencies() 23 24 d.Add(common.StringLocation("test")) 25 require.Equal(t, 1, d.Count()) 26 27 address, _ := common.HexToAddress("0xa") 28 addressLocation := common.AddressLocation{Address: address} 29 d.Add(addressLocation) 30 require.True(t, d.ContainsAddress(address)) 31 } 32 33 func TestProgramDependencies_Merge(t *testing.T) { 34 d1 := derived.NewProgramDependencies() 35 d1.Add(common.StringLocation("test1")) 36 37 d2 := derived.NewProgramDependencies() 38 d2.Add(common.StringLocation("test2")) 39 40 d1.Merge(d2) 41 require.Equal(t, 2, d1.Count()) 42 } 43 44 func TestProgramDependencies_ContainsAddress(t *testing.T) { 45 d := derived.NewProgramDependencies() 46 47 address, _ := common.HexToAddress("0xa") 48 addressLocation := common.AddressLocation{Address: address} 49 d.Add(addressLocation) 50 51 require.True(t, d.ContainsAddress(address)) 52 } 53 54 func TestProgramDependencies_ContainsLocation(t *testing.T) { 55 d := derived.NewProgramDependencies() 56 location := common.StringLocation("test") 57 d.Add(location) 58 59 require.True(t, d.ContainsLocation(location)) 60 }